Commit eb04fd22 authored by Alexandre Julliard's avatar Alexandre Julliard

Converted the memory views list to use the standard functions from

wine/list.h. Restructured some functions to always return proper NT status codes. A couple of optimizations. Added a few tests for file mappings.
parent 7f4e77bc
......@@ -107,7 +107,162 @@ static void test_VirtualAlloc(void)
ok(VirtualFree(addr1, 0, MEM_RELEASE), "VirtualFree failed\n");
}
static void test_MapViewOfFile(void)
{
static const char testfile[] = "testfile.xxx";
HANDLE file, mapping;
void *ptr;
file = CreateFileA( testfile, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0 );
ok( file != INVALID_HANDLE_VALUE, "Failed to create test file\n" );
SetFilePointer( file, 4096, NULL, FILE_BEGIN );
SetEndOfFile( file );
/* read/write mapping */
mapping = CreateFileMappingA( file, NULL, PAGE_READWRITE, 0, 4096, NULL );
ok( mapping != 0, "CreateFileMapping failed\n" );
ptr = MapViewOfFile( mapping, FILE_MAP_READ, 0, 0, 4096 );
ok( ptr != NULL, "MapViewOfFile FILE_MAPE_READ failed\n" );
UnmapViewOfFile( ptr );
/* this fails on win9x but succeeds on NT */
ptr = MapViewOfFile( mapping, FILE_MAP_COPY, 0, 0, 4096 );
if (ptr) UnmapViewOfFile( ptr );
else ok( GetLastError() == ERROR_INVALID_PARAMETER, "Wrong error %lx\n", GetLastError() );
ptr = MapViewOfFile( mapping, 0, 0, 0, 4096 );
ok( ptr != NULL, "MapViewOfFile 0 failed\n" );
UnmapViewOfFile( ptr );
ptr = MapViewOfFile( mapping, FILE_MAP_WRITE, 0, 0, 4096 );
ok( ptr != NULL, "MapViewOfFile FILE_MAP_WRITE failed\n" );
UnmapViewOfFile( ptr );
CloseHandle( mapping );
/* read-only mapping */
mapping = CreateFileMappingA( file, NULL, PAGE_READONLY, 0, 4096, NULL );
ok( mapping != 0, "CreateFileMapping failed\n" );
ptr = MapViewOfFile( mapping, FILE_MAP_READ, 0, 0, 4096 );
ok( ptr != NULL, "MapViewOfFile FILE_MAP_READ failed\n" );
UnmapViewOfFile( ptr );
/* this fails on win9x but succeeds on NT */
ptr = MapViewOfFile( mapping, FILE_MAP_COPY, 0, 0, 4096 );
if (ptr) UnmapViewOfFile( ptr );
else ok( GetLastError() == ERROR_INVALID_PARAMETER, "Wrong error %lx\n", GetLastError() );
ptr = MapViewOfFile( mapping, 0, 0, 0, 4096 );
ok( ptr != NULL, "MapViewOfFile 0 failed\n" );
UnmapViewOfFile( ptr );
ptr = MapViewOfFile( mapping, FILE_MAP_WRITE, 0, 0, 4096 );
ok( !ptr, "MapViewOfFile FILE_MAP_WRITE succeeded\n" );
ok( GetLastError() == ERROR_INVALID_PARAMETER ||
GetLastError() == ERROR_ACCESS_DENIED, "Wrong error %lx\n", GetLastError() );
CloseHandle( mapping );
/* copy-on-write mapping */
mapping = CreateFileMappingA( file, NULL, PAGE_WRITECOPY, 0, 4096, NULL );
ok( mapping != 0, "CreateFileMapping failed\n" );
ptr = MapViewOfFile( mapping, FILE_MAP_READ, 0, 0, 4096 );
ok( ptr != NULL, "MapViewOfFile FILE_MAP_READ failed\n" );
UnmapViewOfFile( ptr );
ptr = MapViewOfFile( mapping, FILE_MAP_COPY, 0, 0, 4096 );
ok( ptr != NULL, "MapViewOfFile FILE_MAP_COPY failed\n" );
UnmapViewOfFile( ptr );
ptr = MapViewOfFile( mapping, 0, 0, 0, 4096 );
ok( ptr != NULL, "MapViewOfFile 0 failed\n" );
UnmapViewOfFile( ptr );
ptr = MapViewOfFile( mapping, FILE_MAP_WRITE, 0, 0, 4096 );
ok( !ptr, "MapViewOfFile FILE_MAP_WRITE succeeded\n" );
ok( GetLastError() == ERROR_INVALID_PARAMETER ||
GetLastError() == ERROR_ACCESS_DENIED, "Wrong error %lx\n", GetLastError() );
CloseHandle( mapping );
/* no access mapping */
mapping = CreateFileMappingA( file, NULL, PAGE_NOACCESS, 0, 4096, NULL );
/* fails on NT but succeeds on win9x */
if (!mapping) ok( GetLastError() == ERROR_INVALID_PARAMETER, "Wrong error %lx\n", GetLastError() );
else
{
ptr = MapViewOfFile( mapping, FILE_MAP_READ, 0, 0, 4096 );
ok( ptr != NULL, "MapViewOfFile FILE_MAP_READ failed\n" );
UnmapViewOfFile( ptr );
ptr = MapViewOfFile( mapping, FILE_MAP_COPY, 0, 0, 4096 );
ok( !ptr, "MapViewOfFile FILE_MAP_COPY succeeded\n" );
ok( GetLastError() == ERROR_INVALID_PARAMETER, "Wrong error %lx\n", GetLastError() );
ptr = MapViewOfFile( mapping, 0, 0, 0, 4096 );
ok( ptr != NULL, "MapViewOfFile 0 failed\n" );
UnmapViewOfFile( ptr );
ptr = MapViewOfFile( mapping, FILE_MAP_WRITE, 0, 0, 4096 );
ok( !ptr, "MapViewOfFile FILE_MAP_WRITE succeeded\n" );
ok( GetLastError() == ERROR_INVALID_PARAMETER, "Wrong error %lx\n", GetLastError() );
CloseHandle( mapping );
}
CloseHandle( file );
/* now try read-only file */
file = CreateFileA( testfile, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, 0 );
ok( file != INVALID_HANDLE_VALUE, "Failed to create test file\n" );
mapping = CreateFileMappingA( file, NULL, PAGE_READWRITE, 0, 4096, NULL );
ok( !mapping, "CreateFileMapping PAGE_READWRITE succeeded\n" );
ok( GetLastError() == ERROR_INVALID_PARAMETER ||
GetLastError() == ERROR_ACCESS_DENIED, "Wrong error %lx\n", GetLastError() );
mapping = CreateFileMappingA( file, NULL, PAGE_WRITECOPY, 0, 4096, NULL );
ok( mapping != 0, "CreateFileMapping PAGE_WRITECOPY failed\n" );
CloseHandle( mapping );
mapping = CreateFileMappingA( file, NULL, PAGE_READONLY, 0, 4096, NULL );
ok( mapping != 0, "CreateFileMapping PAGE_READONLY failed\n" );
CloseHandle( mapping );
CloseHandle( file );
/* now try no access file */
file = CreateFileA( testfile, 0, 0, NULL, OPEN_EXISTING, 0, 0 );
ok( file != INVALID_HANDLE_VALUE, "Failed to create test file\n" );
mapping = CreateFileMappingA( file, NULL, PAGE_READWRITE, 0, 4096, NULL );
ok( !mapping, "CreateFileMapping PAGE_READWRITE succeeded\n" );
ok( GetLastError() == ERROR_INVALID_PARAMETER ||
GetLastError() == ERROR_ACCESS_DENIED, "Wrong error %lx\n", GetLastError() );
mapping = CreateFileMappingA( file, NULL, PAGE_WRITECOPY, 0, 4096, NULL );
ok( !mapping, "CreateFileMapping PAGE_WRITECOPY succeeded\n" );
ok( GetLastError() == ERROR_INVALID_PARAMETER ||
GetLastError() == ERROR_ACCESS_DENIED, "Wrong error %lx\n", GetLastError() );
mapping = CreateFileMappingA( file, NULL, PAGE_READONLY, 0, 4096, NULL );
ok( !mapping, "CreateFileMapping PAGE_READONLY succeeded\n" );
ok( GetLastError() == ERROR_INVALID_PARAMETER ||
GetLastError() == ERROR_ACCESS_DENIED, "Wrong error %lx\n", GetLastError() );
CloseHandle( file );
CloseHandle( file );
DeleteFileA( testfile );
}
START_TEST(virtual)
{
test_VirtualAlloc();
test_MapViewOfFile();
}
......@@ -321,6 +321,8 @@ HANDLE WINAPI CreateFileMappingW( HANDLE hFile, LPSECURITY_ATTRIBUTES sa,
switch(protect)
{
case 0:
protect = PAGE_READONLY; /* Win9x compatibility */
/* fall through */
case PAGE_READONLY:
case PAGE_WRITECOPY:
access = STANDARD_RIGHTS_REQUIRED | SECTION_QUERY | SECTION_MAP_READ;
......
......@@ -27,22 +27,34 @@ struct list
struct list *prev;
};
/* add an element after the specified one */
inline static void list_add_after( struct list *elem, struct list *to_add )
{
to_add->next = elem->next;
to_add->prev = elem;
elem->next->prev = to_add;
elem->next = to_add;
}
/* add an element before the specified one */
inline static void list_add_before( struct list *elem, struct list *to_add )
{
to_add->next = elem;
to_add->prev = elem->prev;
elem->prev->next = to_add;
elem->prev = to_add;
}
/* add element at the head of the list */
inline static void list_add_head( struct list *list, struct list *elem )
{
elem->next = list->next;
elem->prev = list;
list->next->prev = elem;
list->next = elem;
list_add_after( list, elem );
}
/* add element at the tail of the list */
inline static void list_add_tail( struct list *list, struct list *elem )
{
elem->next = list;
elem->prev = list->prev;
list->prev->next = elem;
list->prev = elem;
list_add_before( list, elem );
}
/* remove an element from its list */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment