ntdll: NtAllocateVirtualMemory should fail to commit if an address range is already committed for a memory mapped file.

This commit is contained in:
Dmitry Timoshkov 2013-07-19 14:01:16 +09:00 committed by Alexandre Julliard
parent 47159b6a66
commit 3d759a0c69
3 changed files with 16 additions and 15 deletions

View File

@ -396,12 +396,13 @@ static void test_Loader(void)
SetLastError(0xdeadbeef);
ptr = VirtualAlloc(hlib, si.dwPageSize, MEM_COMMIT, info.Protect);
/* FIXME: Remove once Wine is fixed */
if (ptr) todo_wine
ok(!ptr, "%d: VirtualAlloc should fail\n", i);
else ok(!ptr, "%d: VirtualAlloc should fail\n", i);
/* FIXME: Remove once Wine is fixed */
if (info.Protect == PAGE_WRITECOPY || info.Protect == PAGE_EXECUTE_WRITECOPY)
todo_wine
ok(GetLastError() == ERROR_ACCESS_DENIED, "%d: expected ERROR_ACCESS_DENIED, got %d\n", i, GetLastError());
else
ok(GetLastError() == ERROR_ACCESS_DENIED, "%d: expected ERROR_ACCESS_DENIED, got %d\n", i, GetLastError());
SetLastError(0xdeadbeef);
size = VirtualQuery((char *)hlib + info.RegionSize, &info, sizeof(info));
@ -484,14 +485,15 @@ todo_wine
SetLastError(0xdeadbeef);
ptr = VirtualAlloc((char *)hlib + section.VirtualAddress, si.dwPageSize, MEM_COMMIT, info.Protect);
/* FIXME: Remove once Wine is fixed */
if (ptr) todo_wine
ok(!ptr, "%d: VirtualAlloc should fail\n", i);
else ok(!ptr, "%d: VirtualAlloc should fail\n", i);
/* FIXME: Remove once Wine is fixed */
if (info.Protect == PAGE_WRITECOPY || info.Protect == PAGE_EXECUTE_WRITECOPY)
todo_wine
ok(GetLastError() == ERROR_ACCESS_DENIED || GetLastError() == ERROR_INVALID_ADDRESS,
"%d: expected ERROR_ACCESS_DENIED, got %d\n", i, GetLastError());
else
ok(GetLastError() == ERROR_ACCESS_DENIED || GetLastError() == ERROR_INVALID_ADDRESS,
"%d: expected ERROR_ACCESS_DENIED, got %d\n", i, GetLastError());
}
SetLastError(0xdeadbeef);

View File

@ -1923,13 +1923,12 @@ static void test_CreateFileMapping_protection(void)
SetLastError(0xdeadbeef);
ptr = VirtualAlloc(base, si.dwPageSize, MEM_COMMIT, td[i].prot);
ok(!ptr, "%d: VirtualAlloc(%02x) should fail\n", i, td[i].prot);
/* FIXME: remove once Wine is fixed */
if (td[i].prot == PAGE_WRITECOPY || td[i].prot == PAGE_EXECUTE_WRITECOPY)
ok(!ptr, "%d: VirtualAlloc(%02x) should fail\n", i, td[i].prot);
todo_wine
ok(GetLastError() == ERROR_ACCESS_DENIED, "%d: expected ERROR_ACCESS_DENIED, got %d\n", i, GetLastError());
else
todo_wine
ok(!ptr, "%d: VirtualAlloc(%02x) should fail\n", i, td[i].prot);
todo_wine
ok(GetLastError() == ERROR_ACCESS_DENIED, "%d: expected ERROR_ACCESS_DENIED, got %d\n", i, GetLastError());
SetLastError(0xdeadbeef);
@ -2427,13 +2426,12 @@ static void test_mapping(void)
/*trace("map %#x, view %#x, requested prot %#x\n", page_prot[i], view[j].prot, page_prot[k]);*/
SetLastError(0xdeadbeef);
ptr = VirtualAlloc(base, si.dwPageSize, MEM_COMMIT, page_prot[k]);
ok(!ptr, "VirtualAlloc(%02x) should fail\n", page_prot[k]);
/* FIXME: remove once Wine is fixed */
if (page_prot[k] == PAGE_WRITECOPY || page_prot[k] == PAGE_EXECUTE_WRITECOPY)
ok(!ptr, "VirtualAlloc(%02x) should fail\n", page_prot[k]);
todo_wine
ok(GetLastError() == ERROR_ACCESS_DENIED, "expected ERROR_ACCESS_DENIED, got %d\n", GetLastError());
else
todo_wine
ok(!ptr, "VirtualAlloc(%02x) should fail\n", page_prot[k]);
todo_wine
ok(GetLastError() == ERROR_ACCESS_DENIED, "expected ERROR_ACCESS_DENIED, got %d\n", GetLastError());
}

View File

@ -1974,6 +1974,7 @@ NTSTATUS WINAPI NtAllocateVirtualMemory( HANDLE process, PVOID *ret, ULONG zero_
else /* commit the pages */
{
if (!(view = VIRTUAL_FindView( base, size ))) status = STATUS_NOT_MAPPED_VIEW;
else if (view->mapping && (view->protect & VPROT_COMMITTED)) status = STATUS_ALREADY_COMMITTED;
else if (!VIRTUAL_SetProt( view, base, size, vprot )) status = STATUS_ACCESS_DENIED;
else if (view->mapping && !(view->protect & VPROT_COMMITTED))
{