Module: wine Branch: master Commit: bffba4acb55b043f5af8e2f8bc14d4313cf94bd1 URL: https://gitlab.winehq.org/wine/wine/-/commit/bffba4acb55b043f5af8e2f8bc14d43...
Author: Alexandre Julliard julliard@winehq.org Date: Mon Jul 8 12:34:04 2024 +0200
wow64: Fix NtMapViewOfSection CPU backend notifications.
---
dlls/ntdll/tests/wow64.c | 8 ++------ dlls/wow64/syscall.c | 20 ++++++++++---------- dlls/wow64/virtual.c | 38 ++++++++++++++++++++------------------ dlls/wow64/wow64_private.h | 20 ++++++++++---------- 4 files changed, 42 insertions(+), 44 deletions(-)
diff --git a/dlls/ntdll/tests/wow64.c b/dlls/ntdll/tests/wow64.c index 594a46d4d65..fcd10df92a0 100644 --- a/dlls/ntdll/tests/wow64.c +++ b/dlls/ntdll/tests/wow64.c @@ -1748,7 +1748,6 @@ static void test_notifications( HMODULE module, CROSS_PROCESS_WORK_LIST *list ) status = NtMapViewOfSection( mapping, GetCurrentProcess(), &addr, 0, 0, &offset, &size, ViewShare, 0, PAGE_READONLY ); ok( NT_SUCCESS(status), "NtMapViewOfSection failed %lx\n", status ); - todo_wine expect_notifications( results, 0, NULL ); NtUnmapViewOfSection( GetCurrentProcess(), addr );
@@ -1764,20 +1763,17 @@ static void test_notifications( HMODULE module, CROSS_PROCESS_WORK_LIST *list ) expect.args[1] = (ULONG_PTR)addr; expect.args[3] = size; expect.args[5] = PAGE_READONLY; - todo_wine expect_notifications( results, 1, &expect ); NtUnmapViewOfSection( GetCurrentProcess(), addr );
results[1] = 0xdeadbeef; status = NtMapViewOfSection( mapping, GetCurrentProcess(), &addr, 0, 0, &offset, &size, ViewShare, 0, PAGE_READONLY ); - todo_wine ok( status == 0xdeadbeef, "NtMapViewOfSection failed %lx\n", status ); expect.args[0] = results[2]; /* FIXME: first parameter unknown */ expect.args[1] = (ULONG_PTR)addr; expect.args[3] = size; expect.args[5] = PAGE_READONLY; - todo_wine expect_notifications( results, 1, &expect );
NtCurrentTeb()->Tib.ArbitraryUserPointer = NULL; @@ -1800,8 +1796,8 @@ static void test_notifications( HMODULE module, CROSS_PROCESS_WORK_LIST *list ) expect[1].args[1] = 1; expect_notifications( results, 2, expect );
- NtUnmapViewOfSection( GetCurrentProcess(), (char *)0x12345 ); - expect[0].args[0] = expect[1].args[0] = 0x12345; + NtUnmapViewOfSection( GetCurrentProcess(), (char *)0x1234 ); + expect[0].args[0] = expect[1].args[0] = 0x1234; expect[1].args[1] = 1; expect[1].args[2] = (ULONG)STATUS_NOT_MAPPED_VIEW; expect_notifications( results, 2, expect ); diff --git a/dlls/wow64/syscall.c b/dlls/wow64/syscall.c index dba95db8588..b4e8cf2a3e0 100644 --- a/dlls/wow64/syscall.c +++ b/dlls/wow64/syscall.c @@ -104,17 +104,17 @@ static void (WINAPI *pBTCpuThreadInit)(void); static void (WINAPI *pBTCpuSimulate)(void) __attribute__((used)); static void * (WINAPI *p__wine_get_unix_opcode)(void); static void * (WINAPI *pKiRaiseUserExceptionDispatcher)(void); -void (WINAPI *pBTCpuFlushInstructionCache2)( const void *, SIZE_T ) = NULL; -void (WINAPI *pBTCpuFlushInstructionCacheHeavy)( const void *, SIZE_T ) = NULL; -void (WINAPI *pBTCpuNotifyMapViewOfSection)( void * ) = NULL; -void (WINAPI *pBTCpuNotifyMemoryAlloc)( void *, SIZE_T, ULONG, ULONG, BOOL, NTSTATUS ) = NULL; -void (WINAPI *pBTCpuNotifyMemoryDirty)( void *, SIZE_T ) = NULL; -void (WINAPI *pBTCpuNotifyMemoryFree)( void *, SIZE_T, ULONG, BOOL, NTSTATUS ) = NULL; -void (WINAPI *pBTCpuNotifyMemoryProtect)( void *, SIZE_T, ULONG, BOOL, NTSTATUS ) = NULL; -void (WINAPI *pBTCpuNotifyUnmapViewOfSection)( void *, BOOL, NTSTATUS ) = NULL; +void (WINAPI *pBTCpuFlushInstructionCache2)( const void *, SIZE_T ) = NULL; +void (WINAPI *pBTCpuFlushInstructionCacheHeavy)( const void *, SIZE_T ) = NULL; +NTSTATUS (WINAPI *pBTCpuNotifyMapViewOfSection)( void *, void *, void *, SIZE_T, ULONG, ULONG ) = NULL; +void (WINAPI *pBTCpuNotifyMemoryAlloc)( void *, SIZE_T, ULONG, ULONG, BOOL, NTSTATUS ) = NULL; +void (WINAPI *pBTCpuNotifyMemoryDirty)( void *, SIZE_T ) = NULL; +void (WINAPI *pBTCpuNotifyMemoryFree)( void *, SIZE_T, ULONG, BOOL, NTSTATUS ) = NULL; +void (WINAPI *pBTCpuNotifyMemoryProtect)( void *, SIZE_T, ULONG, BOOL, NTSTATUS ) = NULL; +void (WINAPI *pBTCpuNotifyUnmapViewOfSection)( void *, BOOL, NTSTATUS ) = NULL; NTSTATUS (WINAPI *pBTCpuResetToConsistentState)( EXCEPTION_POINTERS * ) = NULL; -void (WINAPI *pBTCpuUpdateProcessorInformation)( SYSTEM_CPU_INFORMATION * ) = NULL; -void (WINAPI *pBTCpuThreadTerm)( HANDLE ) = NULL; +void (WINAPI *pBTCpuUpdateProcessorInformation)( SYSTEM_CPU_INFORMATION * ) = NULL; +void (WINAPI *pBTCpuThreadTerm)( HANDLE ) = NULL;
BOOL WINAPI DllMain( HINSTANCE inst, DWORD reason, void *reserved ) { diff --git a/dlls/wow64/virtual.c b/dlls/wow64/virtual.c index e9972168f3e..ca362438340 100644 --- a/dlls/wow64/virtual.c +++ b/dlls/wow64/virtual.c @@ -407,6 +407,23 @@ NTSTATUS WINAPI wow64_NtLockVirtualMemory( UINT *args ) }
+static void notify_map_view_of_section( HANDLE handle, void *addr, SIZE_T size, ULONG alloc, + ULONG protect, NTSTATUS *ret_status ) +{ + SECTION_IMAGE_INFORMATION info; + NTSTATUS status; + + if (!NtCurrentTeb()->Tib.ArbitraryUserPointer) return; + if (NtQuerySection( handle, SectionImageInformation, &info, sizeof(info), NULL )) return; + if (info.Machine != current_machine) return; + init_image_mapping( addr ); + if (!pBTCpuNotifyMapViewOfSection) return; + status = pBTCpuNotifyMapViewOfSection( NULL, addr, NULL, size, alloc, protect ); + if (NT_SUCCESS(status)) return; + NtUnmapViewOfSection( GetCurrentProcess(), addr ); + *ret_status = status; +} + /********************************************************************** * wow64_NtMapViewOfSection */ @@ -433,17 +450,10 @@ NTSTATUS WINAPI wow64_NtMapViewOfSection( UINT *args ) commit, offset, size_32to64( &size, size32 ), inherit, alloc, protect ); if (NT_SUCCESS(status)) { - SECTION_IMAGE_INFORMATION info; - - if (RtlIsCurrentProcess( process ) && - !NtQuerySection( handle, SectionImageInformation, &info, sizeof(info), NULL ) && - info.Machine == current_machine) - { - if (pBTCpuNotifyMapViewOfSection) pBTCpuNotifyMapViewOfSection( addr ); - init_image_mapping( addr ); - } put_addr( addr32, addr ); put_size( size32, size ); + if (RtlIsCurrentProcess( process )) + notify_map_view_of_section( handle, addr, size, alloc, protect, &status ); } NtCurrentTeb()->Tib.ArbitraryUserPointer = prev; return status; @@ -479,17 +489,9 @@ NTSTATUS WINAPI wow64_NtMapViewOfSectionEx( UINT *args ) size_32to64( &size, size32 ), alloc, protect, params64, count ); if (NT_SUCCESS(status)) { - SECTION_IMAGE_INFORMATION info; - - if (is_current && - !NtQuerySection( handle, SectionImageInformation, &info, sizeof(info), NULL ) && - info.Machine == current_machine) - { - if (pBTCpuNotifyMapViewOfSection) pBTCpuNotifyMapViewOfSection( addr ); - init_image_mapping( addr ); - } put_addr( addr32, addr ); put_size( size32, size ); + if (is_current) notify_map_view_of_section( handle, addr, size, alloc, protect, &status ); } NtCurrentTeb()->Tib.ArbitraryUserPointer = prev; return status; diff --git a/dlls/wow64/wow64_private.h b/dlls/wow64/wow64_private.h index 80604b0ad17..b55e847c04c 100644 --- a/dlls/wow64/wow64_private.h +++ b/dlls/wow64/wow64_private.h @@ -39,16 +39,16 @@ extern ULONG_PTR highest_user_address; extern ULONG_PTR default_zero_bits; extern SYSTEM_DLL_INIT_BLOCK *pLdrSystemDllInitBlock;
-extern void (WINAPI *pBTCpuFlushInstructionCache2)( const void *, SIZE_T ); -extern void (WINAPI *pBTCpuFlushInstructionCacheHeavy)( const void *, SIZE_T ); -extern void (WINAPI *pBTCpuNotifyMapViewOfSection)( void * ); -extern void (WINAPI *pBTCpuNotifyMemoryAlloc)( void *, SIZE_T, ULONG, ULONG, BOOL, NTSTATUS ); -extern void (WINAPI *pBTCpuNotifyMemoryDirty)( void *, SIZE_T ); -extern void (WINAPI *pBTCpuNotifyMemoryFree)( void *, SIZE_T, ULONG, BOOL, NTSTATUS ); -extern void (WINAPI *pBTCpuNotifyMemoryProtect)( void *, SIZE_T, ULONG, BOOL, NTSTATUS ); -extern void (WINAPI *pBTCpuNotifyUnmapViewOfSection)( void *, BOOL, NTSTATUS ); -extern void (WINAPI *pBTCpuUpdateProcessorInformation)( SYSTEM_CPU_INFORMATION * ); -extern void (WINAPI *pBTCpuThreadTerm)( HANDLE ); +extern void (WINAPI *pBTCpuFlushInstructionCache2)( const void *, SIZE_T ); +extern void (WINAPI *pBTCpuFlushInstructionCacheHeavy)( const void *, SIZE_T ); +extern NTSTATUS (WINAPI *pBTCpuNotifyMapViewOfSection)( void *, void *, void *, SIZE_T, ULONG, ULONG ); +extern void (WINAPI *pBTCpuNotifyMemoryAlloc)( void *, SIZE_T, ULONG, ULONG, BOOL, NTSTATUS ); +extern void (WINAPI *pBTCpuNotifyMemoryDirty)( void *, SIZE_T ); +extern void (WINAPI *pBTCpuNotifyMemoryFree)( void *, SIZE_T, ULONG, BOOL, NTSTATUS ); +extern void (WINAPI *pBTCpuNotifyMemoryProtect)( void *, SIZE_T, ULONG, BOOL, NTSTATUS ); +extern void (WINAPI *pBTCpuNotifyUnmapViewOfSection)( void *, BOOL, NTSTATUS ); +extern void (WINAPI *pBTCpuUpdateProcessorInformation)( SYSTEM_CPU_INFORMATION * ); +extern void (WINAPI *pBTCpuThreadTerm)( HANDLE );
struct object_attr64 {