Commit 5ceb2271 authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

ntdll: Use MAP_PRIVATE for copy on write mappings.

parent 82bb4f51
...@@ -2489,7 +2489,7 @@ static void test_shared_memory(BOOL is_child) ...@@ -2489,7 +2489,7 @@ static void test_shared_memory(BOOL is_child)
CloseHandle(mapping); CloseHandle(mapping);
} }
static void test_shared_memory_ro(BOOL is_child) static void test_shared_memory_ro(BOOL is_child, DWORD child_access)
{ {
HANDLE mapping; HANDLE mapping;
LONG *p; LONG *p;
...@@ -2501,7 +2501,7 @@ static void test_shared_memory_ro(BOOL is_child) ...@@ -2501,7 +2501,7 @@ static void test_shared_memory_ro(BOOL is_child)
ok(GetLastError() == ERROR_ALREADY_EXISTS, "expected ERROR_ALREADY_EXISTS, got %d\n", GetLastError()); ok(GetLastError() == ERROR_ALREADY_EXISTS, "expected ERROR_ALREADY_EXISTS, got %d\n", GetLastError());
SetLastError(0xdeadbef); SetLastError(0xdeadbef);
p = MapViewOfFile(mapping, FILE_MAP_READ | (is_child ? FILE_MAP_WRITE : 0), 0, 0, 4096); p = MapViewOfFile(mapping, is_child ? child_access : FILE_MAP_READ, 0, 0, 4096);
ok(p != NULL, "MapViewOfFile error %d\n", GetLastError()); ok(p != NULL, "MapViewOfFile error %d\n", GetLastError());
if (is_child) if (is_child)
...@@ -2517,14 +2517,17 @@ static void test_shared_memory_ro(BOOL is_child) ...@@ -2517,14 +2517,17 @@ static void test_shared_memory_ro(BOOL is_child)
DWORD ret; DWORD ret;
winetest_get_mainargs(&argv); winetest_get_mainargs(&argv);
sprintf(cmdline, "\"%s\" virtual sharedmemro", argv[0]); sprintf(cmdline, "\"%s\" virtual sharedmemro %x", argv[0], child_access);
ret = CreateProcessA(argv[0], cmdline, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi); ret = CreateProcessA(argv[0], cmdline, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
ok(ret, "CreateProcess(%s) error %d\n", cmdline, GetLastError()); ok(ret, "CreateProcess(%s) error %d\n", cmdline, GetLastError());
winetest_wait_child_process(pi.hProcess); winetest_wait_child_process(pi.hProcess);
CloseHandle(pi.hThread); CloseHandle(pi.hThread);
CloseHandle(pi.hProcess); CloseHandle(pi.hProcess);
ok(*p == 0xdeadbeef, "*p = %x, expected 0xdeadbeef\n", *p); if(child_access & FILE_MAP_WRITE)
ok(*p == 0xdeadbeef, "*p = %x, expected 0xdeadbeef\n", *p);
else
ok(!*p, "*p = %x, expected 0\n", *p);
} }
UnmapViewOfFile(p); UnmapViewOfFile(p);
...@@ -2551,7 +2554,7 @@ START_TEST(virtual) ...@@ -2551,7 +2554,7 @@ START_TEST(virtual)
} }
if (!strcmp(argv[2], "sharedmemro")) if (!strcmp(argv[2], "sharedmemro"))
{ {
test_shared_memory_ro(TRUE); test_shared_memory_ro(TRUE, strtol(argv[3], NULL, 16));
return; return;
} }
while (1) while (1)
...@@ -2580,7 +2583,9 @@ START_TEST(virtual) ...@@ -2580,7 +2583,9 @@ START_TEST(virtual)
pNtUnmapViewOfSection = (void *)GetProcAddress(GetModuleHandleA("ntdll.dll"), "NtUnmapViewOfSection"); pNtUnmapViewOfSection = (void *)GetProcAddress(GetModuleHandleA("ntdll.dll"), "NtUnmapViewOfSection");
test_shared_memory(FALSE); test_shared_memory(FALSE);
test_shared_memory_ro(FALSE); test_shared_memory_ro(FALSE, FILE_MAP_READ|FILE_MAP_WRITE);
test_shared_memory_ro(FALSE, FILE_MAP_COPY);
test_shared_memory_ro(FALSE, FILE_MAP_COPY|FILE_MAP_WRITE);
test_mapping(); test_mapping();
test_CreateFileMapping_protection(); test_CreateFileMapping_protection();
test_VirtualAlloc_protection(); test_VirtualAlloc_protection();
......
...@@ -2627,7 +2627,8 @@ NTSTATUS WINAPI NtMapViewOfSection( HANDLE handle, HANDLE process, PVOID *addr_p ...@@ -2627,7 +2627,8 @@ NTSTATUS WINAPI NtMapViewOfSection( HANDLE handle, HANDLE process, PVOID *addr_p
TRACE("handle=%p size=%lx offset=%x%08x\n", TRACE("handle=%p size=%lx offset=%x%08x\n",
handle, size, offset.u.HighPart, offset.u.LowPart ); handle, size, offset.u.HighPart, offset.u.LowPart );
res = map_file_into_view( view, unix_handle, 0, size, offset.QuadPart, vprot, MAP_SHARED, !dup_mapping ); res = map_file_into_view( view, unix_handle, 0, size, offset.QuadPart, vprot,
(vprot & VPROT_WRITECOPY) ? MAP_PRIVATE : MAP_SHARED, !dup_mapping );
if (res == STATUS_SUCCESS) if (res == STATUS_SUCCESS)
{ {
*addr_ptr = view->base; *addr_ptr = view->base;
......
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