From ea950ac7cfe5156a96bee762cb3af0b4b0ab5e7c Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Thu, 8 May 2014 17:30:46 +0200 Subject: [PATCH] kernel32/tests: Added more shared memory tests, exposing MAP_PRIVATE mapping for read only mapping problem. --- dlls/kernel32/tests/virtual.c | 54 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 51 insertions(+), 3 deletions(-) diff --git a/dlls/kernel32/tests/virtual.c b/dlls/kernel32/tests/virtual.c index 0d417a6b74c..174d422adcc 100644 --- a/dlls/kernel32/tests/virtual.c +++ b/dlls/kernel32/tests/virtual.c @@ -2447,7 +2447,7 @@ todo_wine DeleteFileA(file_name); } -static void test_shared_memory(int is_child) +static void test_shared_memory(BOOL is_child) { HANDLE mapping; LONG *p; @@ -2489,6 +2489,48 @@ static void test_shared_memory(int is_child) CloseHandle(mapping); } +static void test_shared_memory_ro(BOOL is_child) +{ + HANDLE mapping; + LONG *p; + + SetLastError(0xdeadbef); + mapping = CreateFileMappingA(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, 4096, "winetest_virtual.c_ro"); + ok(mapping != 0, "CreateFileMapping error %d\n", GetLastError()); + if (is_child) + ok(GetLastError() == ERROR_ALREADY_EXISTS, "expected ERROR_ALREADY_EXISTS, got %d\n", GetLastError()); + + SetLastError(0xdeadbef); + p = MapViewOfFile(mapping, FILE_MAP_READ | (is_child ? FILE_MAP_WRITE : 0), 0, 0, 4096); + ok(p != NULL, "MapViewOfFile error %d\n", GetLastError()); + + if (is_child) + { + *p = 0xdeadbeef; + } + else + { + char **argv; + char cmdline[MAX_PATH]; + PROCESS_INFORMATION pi; + STARTUPINFOA si = { sizeof(si) }; + DWORD ret; + + winetest_get_mainargs(&argv); + sprintf(cmdline, "\"%s\" virtual sharedmemro", argv[0]); + ret = CreateProcessA(argv[0], cmdline, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi); + ok(ret, "CreateProcess(%s) error %d\n", cmdline, GetLastError()); + winetest_wait_child_process(pi.hProcess); + CloseHandle(pi.hThread); + CloseHandle(pi.hProcess); + + ok(*p == 0xdeadbeef, "*p = %x, expected 0xdeadbeef\n", *p); + } + + UnmapViewOfFile(p); + CloseHandle(mapping); +} + START_TEST(virtual) { int argc; @@ -2504,7 +2546,12 @@ START_TEST(virtual) } if (!strcmp(argv[2], "sharedmem")) { - test_shared_memory(1); + test_shared_memory(TRUE); + return; + } + if (!strcmp(argv[2], "sharedmemro")) + { + test_shared_memory_ro(TRUE); return; } while (1) @@ -2532,7 +2579,8 @@ START_TEST(virtual) pNtMapViewOfSection = (void *)GetProcAddress(GetModuleHandleA("ntdll.dll"), "NtMapViewOfSection"); pNtUnmapViewOfSection = (void *)GetProcAddress(GetModuleHandleA("ntdll.dll"), "NtUnmapViewOfSection"); - test_shared_memory(0); + test_shared_memory(FALSE); + test_shared_memory_ro(FALSE); test_mapping(); test_CreateFileMapping_protection(); test_VirtualAlloc_protection(); -- 2.11.4.GIT