Module: wine Branch: master Commit: 1942cc30171c9f98abde65f3a0d8857c9ccd892a URL: https://gitlab.winehq.org/wine/wine/-/commit/1942cc30171c9f98abde65f3a0d8857...
Author: Alexandre Julliard julliard@winehq.org Date: Wed Aug 30 13:54:59 2023 +0200
wow64: Also send notifications for failed memory management calls.
---
dlls/ntdll/tests/wow64.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ dlls/wow64/syscall.c | 1 + dlls/wow64/virtual.c | 38 ++++++++++++++++++-------------------- 3 files changed, 66 insertions(+), 20 deletions(-)
diff --git a/dlls/ntdll/tests/wow64.c b/dlls/ntdll/tests/wow64.c index 6ca5ebd9b74..485b9006b14 100644 --- a/dlls/ntdll/tests/wow64.c +++ b/dlls/ntdll/tests/wow64.c @@ -392,6 +392,21 @@ static void test_cross_process_notifications( HANDLE process, void *ptr ) } ok( !entry, "not at end of list\n" );
+ addr = (void *)0x123; + size = 0x321; + status = NtAllocateVirtualMemory( process, &addr, 0, &size, MEM_COMMIT, PAGE_EXECUTE_READ ); + ok( status == STATUS_CONFLICTING_ADDRESSES || status == STATUS_INVALID_PARAMETER, + "NtAllocateVirtualMemory failed %lx\n", status ); + entry = pop_from_work_list( &list->work_list ); + if (current_machine != IMAGE_FILE_MACHINE_ARM64) + { + entry = expect_cross_work_entry( list, entry, CrossProcessPreVirtualAlloc, addr, 0x321, + MEM_COMMIT, PAGE_EXECUTE_READ, 0, 0xcccccccc ); + entry = expect_cross_work_entry( list, entry, CrossProcessPostVirtualAlloc, addr, 0x321, + MEM_COMMIT, PAGE_EXECUTE_READ, status, 0xcccccccc ); + } + ok( !entry, "not at end of list\n" ); + addr = NULL; size = 0x4321; status = NtAllocateVirtualMemory( process, &addr, 0, &size, MEM_RESERVE, PAGE_EXECUTE_READWRITE ); @@ -433,6 +448,23 @@ static void test_cross_process_notifications( HANDLE process, void *ptr ) } ok( !entry, "not at end of list\n" );
+ addr2 = (char *)addr + 0x222; + size = 34; + status = NtProtectVirtualMemory( process, &addr2, &size, PAGE_EXECUTE_WRITECOPY, &old_prot ); + ok( status == STATUS_INVALID_PARAMETER_4 || status == STATUS_INVALID_PAGE_PROTECTION, + "NtProtectVirtualMemory failed %lx\n", status ); + entry = pop_from_work_list( &list->work_list ); + if (current_machine != IMAGE_FILE_MACHINE_ARM64) + { + entry = expect_cross_work_entry( list, entry, CrossProcessPreVirtualProtect, + (char *)addr + 0x222, 34, + PAGE_EXECUTE_WRITECOPY, 0, 0xcccccccc, 0xcccccccc ); + entry = expect_cross_work_entry( list, entry, CrossProcessPostVirtualProtect, + (char *)addr + 0x222, 34, + PAGE_EXECUTE_WRITECOPY, status, 0xcccccccc, 0xcccccccc ); + } + ok( !entry, "not at end of list\n" ); + status = NtWriteVirtualMemory( process, (char *)addr + 0x1111, data, sizeof(data), &size ); ok( !status, "NtWriteVirtualMemory failed %lx\n", status ); entry = pop_from_work_list( &list->work_list ); @@ -465,6 +497,21 @@ static void test_cross_process_notifications( HANDLE process, void *ptr ) } ok( !entry, "not at end of list\n" );
+ addr = (void *)0x123; + size = 0; + status = NtFreeVirtualMemory( process, &addr, &size, MEM_RELEASE ); + ok( status == STATUS_MEMORY_NOT_ALLOCATED || status == STATUS_INVALID_PARAMETER, + "NtFreeVirtualMemory failed %lx\n", status ); + entry = pop_from_work_list( &list->work_list ); + if (current_machine != IMAGE_FILE_MACHINE_ARM64) + { + entry = expect_cross_work_entry( list, entry, CrossProcessPreVirtualFree, addr, 0, + MEM_RELEASE, 0, 0xcccccccc, 0xcccccccc ); + entry = expect_cross_work_entry( list, entry, CrossProcessPostVirtualFree, addr, 0, + MEM_RELEASE, status, 0xcccccccc, 0xcccccccc ); + } + ok( !entry, "not at end of list\n" ); + file = CreateFileA( "c:\windows\syswow64\version.dll", GENERIC_READ | GENERIC_EXECUTE, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0 ); ok( file != INVALID_HANDLE_VALUE, "Failed to open version.dll\n" ); mapping = CreateFileMappingA( file, NULL, PAGE_READONLY | SEC_IMAGE, 0, 0, NULL ); diff --git a/dlls/wow64/syscall.c b/dlls/wow64/syscall.c index 4b13fd9d3cd..3b8e479bcb2 100644 --- a/dlls/wow64/syscall.c +++ b/dlls/wow64/syscall.c @@ -1296,6 +1296,7 @@ void WINAPI Wow64ProcessPendingCrossProcessItems(void) break; case CrossProcessPostVirtualAlloc: if (!pBTCpuNotifyMemoryAlloc) break; + if (entry->args[2]) break; pBTCpuNotifyMemoryAlloc( (void *)entry->addr, entry->size, entry->args[0], entry->args[1] ); break; case CrossProcessPreVirtualFree: diff --git a/dlls/wow64/virtual.c b/dlls/wow64/virtual.c index 79b4e9c2288..e497f60210e 100644 --- a/dlls/wow64/virtual.c +++ b/dlls/wow64/virtual.c @@ -160,15 +160,14 @@ NTSTATUS WINAPI wow64_NtAllocateVirtualMemory( UINT *args ) addr, size, 3, type, protect, 0 );
status = NtAllocateVirtualMemory( process, &addr, get_zero_bits( zero_bits ), &size, type, protect ); + + if (!is_current) + send_cross_process_notification( process, CrossProcessPostVirtualAlloc, + addr, size, 3, type, protect, status ); + if (!status) { - if (is_current) - { - if (pBTCpuNotifyMemoryAlloc) pBTCpuNotifyMemoryAlloc( addr, size, type, protect ); - } - else send_cross_process_notification( process, CrossProcessPostVirtualAlloc, - addr, size, 3, type, protect, 0 ); - + if (is_current && pBTCpuNotifyMemoryAlloc) pBTCpuNotifyMemoryAlloc( addr, size, type, protect ); put_addr( addr32, addr ); put_size( size32, size ); } @@ -204,15 +203,13 @@ NTSTATUS WINAPI wow64_NtAllocateVirtualMemoryEx( UINT *args ) addr, size, 3, type, protect, 0 );
status = NtAllocateVirtualMemoryEx( process, &addr, &size, type, protect, params64, count ); + + if (!is_current) send_cross_process_notification( process, CrossProcessPostVirtualAlloc, + addr, size, 3, type, protect, status ); + if (!status) { - if (is_current) - { - if (pBTCpuNotifyMemoryAlloc) pBTCpuNotifyMemoryAlloc( addr, size, type, protect ); - } - else send_cross_process_notification( process, CrossProcessPostVirtualAlloc, - addr, size, 3, type, protect, 0 ); - + if (is_current && pBTCpuNotifyMemoryAlloc) pBTCpuNotifyMemoryAlloc( addr, size, type, protect ); put_addr( addr32, addr ); put_size( size32, size ); } @@ -299,11 +296,11 @@ NTSTATUS WINAPI wow64_NtFreeVirtualMemory( UINT *args ) addr, size, 2, type, 0 );
status = NtFreeVirtualMemory( process, &addr, &size, type ); + + if (!is_current) send_cross_process_notification( process, CrossProcessPostVirtualFree, + addr, size, 2, type, status ); if (!status) { - if (!is_current) - send_cross_process_notification( process, CrossProcessPostVirtualFree, - addr, size, 2, type, 0 ); put_addr( addr32, addr ); put_size( size32, size ); } @@ -517,11 +514,12 @@ NTSTATUS WINAPI wow64_NtProtectVirtualMemory( UINT *args ) addr, size, 2, new_prot, 0 );
status = NtProtectVirtualMemory( process, &addr, &size, new_prot, old_prot ); + + if (!is_current) send_cross_process_notification( process, CrossProcessPostVirtualProtect, + addr, size, 2, new_prot, status ); + if (!status) { - if (!is_current) - send_cross_process_notification( process, CrossProcessPostVirtualProtect, - addr, size, 2, new_prot, 0 ); put_addr( addr32, addr ); put_size( size32, size ); }