Module: wine Branch: master Commit: 1591e01e5d5b29ebb3d3bcb01e6ffc962d65b919 URL: https://gitlab.winehq.org/wine/wine/-/commit/1591e01e5d5b29ebb3d3bcb01e6ffc9...
Author: Alexandre Julliard julliard@winehq.org Date: Mon Jul 10 17:03:31 2023 +0200
wow64: Implement backend notification functions.
Co-authored-by: Billy Laws blaws05@gmail.com
---
dlls/wow64/process.c | 3 +++ dlls/wow64/syscall.c | 15 ++++++++++++++ dlls/wow64/virtual.c | 49 +++++++++++++++++++++++++++++++++------------- dlls/wow64/wow64_private.h | 10 +++++++++- 4 files changed, 62 insertions(+), 15 deletions(-)
diff --git a/dlls/wow64/process.c b/dlls/wow64/process.c index 2182491bbfb..0728f9f0999 100644 --- a/dlls/wow64/process.c +++ b/dlls/wow64/process.c @@ -435,6 +435,9 @@ NTSTATUS WINAPI wow64_NtFlushInstructionCache( UINT *args ) const void *addr = get_ptr( &args ); SIZE_T size = get_ulong( &args );
+ if (pBTCpuNotifyFlushInstructionCache2 && RtlIsCurrentProcess( process )) + pBTCpuNotifyFlushInstructionCache2( addr, size ); + return NtFlushInstructionCache( process, addr, size ); }
diff --git a/dlls/wow64/syscall.c b/dlls/wow64/syscall.c index 85db80a53df..0f8135859bc 100644 --- a/dlls/wow64/syscall.c +++ b/dlls/wow64/syscall.c @@ -100,6 +100,7 @@ static HMODULE win32u_module; static WOW64INFO *wow64info;
/* cpu backend dll functions */ +/* the function prototypes most likely differ from Windows */ static void * (WINAPI *pBTCpuGetBopCode)(void); static NTSTATUS (WINAPI *pBTCpuGetContext)(HANDLE,HANDLE,void *,void *); static BOOLEAN (WINAPI *pBTCpuIsProcessorFeaturePresent)(UINT); @@ -110,6 +111,13 @@ static void (WINAPI *pBTCpuSimulate)(void); static NTSTATUS (WINAPI *pBTCpuResetToConsistentState)( EXCEPTION_POINTERS * ); static void * (WINAPI *p__wine_get_unix_opcode)(void); static void * (WINAPI *pKiRaiseUserExceptionDispatcher)(void); +void (WINAPI *pBTCpuNotifyFlushInstructionCache2)( const void *, SIZE_T ) = NULL; +void (WINAPI *pBTCpuNotifyMapViewOfSection)( void * ) = NULL; +void (WINAPI *pBTCpuNotifyMemoryAlloc)( void *, SIZE_T, ULONG, ULONG ) = NULL; +void (WINAPI *pBTCpuNotifyMemoryDirty)( void *, SIZE_T ) = NULL; +void (WINAPI *pBTCpuNotifyMemoryFree)( void *, SIZE_T ) = NULL; +void (WINAPI *pBTCpuNotifyMemoryProtect)( void *, SIZE_T, ULONG ) = NULL; +void (WINAPI *pBTCpuNotifyUnmapViewOfSection)( void * ) = NULL; void (WINAPI *pBTCpuUpdateProcessorInformation)( SYSTEM_CPU_INFORMATION * ) = NULL;
void *dummy = RtlUnwind; @@ -896,6 +904,13 @@ static DWORD WINAPI process_init( RTL_RUN_ONCE *once, void *param, void **contex GET_PTR( BTCpuResetToConsistentState ); GET_PTR( BTCpuSetContext ); GET_PTR( BTCpuSimulate ); + GET_PTR( BTCpuNotifyFlushInstructionCache2 ); + GET_PTR( BTCpuNotifyMapViewOfSection ); + GET_PTR( BTCpuNotifyMemoryAlloc ); + GET_PTR( BTCpuNotifyMemoryDirty ); + GET_PTR( BTCpuNotifyMemoryFree ); + GET_PTR( BTCpuNotifyMemoryProtect ); + GET_PTR( BTCpuNotifyUnmapViewOfSection ); GET_PTR( BTCpuUpdateProcessorInformation ); GET_PTR( __wine_get_unix_opcode );
diff --git a/dlls/wow64/virtual.c b/dlls/wow64/virtual.c index c171fe39cb2..6a63f3793bb 100644 --- a/dlls/wow64/virtual.c +++ b/dlls/wow64/virtual.c @@ -126,6 +126,8 @@ NTSTATUS WINAPI wow64_NtAllocateVirtualMemory( UINT *args ) size_32to64( &size, size32 ), type, protect ); if (!status) { + if (pBTCpuNotifyMemoryAlloc && RtlIsCurrentProcess(process)) + pBTCpuNotifyMemoryAlloc( addr, size, type, protect ); put_addr( addr32, addr ); put_size( size32, size ); } @@ -150,7 +152,8 @@ NTSTATUS WINAPI wow64_NtAllocateVirtualMemoryEx( UINT *args ) SIZE_T size; NTSTATUS status; MEM_EXTENDED_PARAMETER *params64; - BOOL set_limit = (!*addr32 && process == GetCurrentProcess()); + BOOL is_current = RtlIsCurrentProcess( process ); + BOOL set_limit = (!*addr32 && is_current);
if ((status = mem_extended_parameters_32to64( ¶ms64, params32, &count, set_limit ))) return status;
@@ -158,6 +161,7 @@ NTSTATUS WINAPI wow64_NtAllocateVirtualMemoryEx( UINT *args ) type, protect, params64, count ); if (!status) { + if (pBTCpuNotifyMemoryAlloc && is_current) pBTCpuNotifyMemoryAlloc( addr, size, type, protect ); put_addr( addr32, addr ); put_size( size32, size ); } @@ -212,12 +216,14 @@ NTSTATUS WINAPI wow64_NtFreeVirtualMemory( UINT *args ) ULONG *size32 = get_ptr( &args ); ULONG type = get_ulong( &args );
- void *addr; - SIZE_T size; + void *addr = ULongToPtr( *addr32 ); + SIZE_T size = *size32; NTSTATUS status;
- status = NtFreeVirtualMemory( process, addr_32to64( &addr, addr32 ), - size_32to64( &size, size32 ), type ); + if (pBTCpuNotifyMemoryFree && RtlIsCurrentProcess( process )) + pBTCpuNotifyMemoryFree( addr, size ); + + status = NtFreeVirtualMemory( process, &addr, &size, type ); if (!status) { put_addr( addr32, addr ); @@ -353,9 +359,12 @@ NTSTATUS WINAPI wow64_NtMapViewOfSection( UINT *args ) { SECTION_IMAGE_INFORMATION info;
- if (!NtQuerySection( handle, SectionImageInformation, &info, sizeof(info), NULL )) + if (RtlIsCurrentProcess( process ) && + !NtQuerySection( handle, SectionImageInformation, &info, sizeof(info), NULL ) && + info.Machine == current_machine) { - if (info.Machine == current_machine) init_image_mapping( addr ); + if (pBTCpuNotifyMapViewOfSection) pBTCpuNotifyMapViewOfSection( addr ); + init_image_mapping( addr ); } put_addr( addr32, addr ); put_size( size32, size ); @@ -382,7 +391,8 @@ NTSTATUS WINAPI wow64_NtMapViewOfSectionEx( UINT *args ) SIZE_T size; NTSTATUS status; MEM_EXTENDED_PARAMETER *params64; - BOOL set_limit = (!*addr32 && process == GetCurrentProcess()); + BOOL is_current = RtlIsCurrentProcess( process ); + BOOL set_limit = (!*addr32 && is_current);
if ((status = mem_extended_parameters_32to64( ¶ms64, params32, &count, set_limit ))) return status;
@@ -392,9 +402,12 @@ NTSTATUS WINAPI wow64_NtMapViewOfSectionEx( UINT *args ) { SECTION_IMAGE_INFORMATION info;
- if (!NtQuerySection( handle, SectionImageInformation, &info, sizeof(info), NULL )) + if (is_current && + !NtQuerySection( handle, SectionImageInformation, &info, sizeof(info), NULL ) && + info.Machine == current_machine) { - if (info.Machine == current_machine) init_image_mapping( addr ); + if (pBTCpuNotifyMapViewOfSection) pBTCpuNotifyMapViewOfSection( addr ); + init_image_mapping( addr ); } put_addr( addr32, addr ); put_size( size32, size ); @@ -413,12 +426,14 @@ NTSTATUS WINAPI wow64_NtProtectVirtualMemory( UINT *args ) ULONG new_prot = get_ulong( &args ); ULONG *old_prot = get_ptr( &args );
- void *addr; - SIZE_T size; + void *addr = ULongToPtr( *addr32 ); + SIZE_T size = *size32; NTSTATUS status;
- status = NtProtectVirtualMemory( process, addr_32to64( &addr, addr32 ), - size_32to64( &size, size32 ), new_prot, old_prot ); + if (pBTCpuNotifyMemoryProtect && RtlIsCurrentProcess(process)) + pBTCpuNotifyMemoryProtect( addr, size, new_prot ); + + status = NtProtectVirtualMemory( process, &addr, &size, new_prot, old_prot ); if (!status) { put_addr( addr32, addr ); @@ -686,6 +701,9 @@ NTSTATUS WINAPI wow64_NtUnmapViewOfSection( UINT *args ) HANDLE process = get_handle( &args ); void *addr = get_ptr( &args );
+ if (pBTCpuNotifyUnmapViewOfSection && RtlIsCurrentProcess( process )) + pBTCpuNotifyUnmapViewOfSection( addr ); + return NtUnmapViewOfSection( process, addr ); }
@@ -699,6 +717,9 @@ NTSTATUS WINAPI wow64_NtUnmapViewOfSectionEx( UINT *args ) void *addr = get_ptr( &args ); ULONG flags = get_ulong( &args );
+ if (pBTCpuNotifyUnmapViewOfSection && RtlIsCurrentProcess( process )) + pBTCpuNotifyUnmapViewOfSection( addr ); + return NtUnmapViewOfSectionEx( process, addr, flags ); }
diff --git a/dlls/wow64/wow64_private.h b/dlls/wow64/wow64_private.h index a840c1d01c0..73a100cba32 100644 --- a/dlls/wow64/wow64_private.h +++ b/dlls/wow64/wow64_private.h @@ -38,7 +38,15 @@ extern ULONG_PTR args_alignment DECLSPEC_HIDDEN; extern ULONG_PTR highest_user_address DECLSPEC_HIDDEN; extern ULONG_PTR default_zero_bits DECLSPEC_HIDDEN; extern SYSTEM_DLL_INIT_BLOCK *pLdrSystemDllInitBlock DECLSPEC_HIDDEN; -extern void (WINAPI *pBTCpuUpdateProcessorInformation)( SYSTEM_CPU_INFORMATION * ) DECLSPEC_HIDDEN; + +extern void (WINAPI *pBTCpuNotifyFlushInstructionCache2)( const void *, SIZE_T ); +extern void (WINAPI *pBTCpuNotifyMapViewOfSection)( void * ); +extern void (WINAPI *pBTCpuNotifyMemoryAlloc)( void *, SIZE_T, ULONG, ULONG ); +extern void (WINAPI *pBTCpuNotifyMemoryDirty)( void *, SIZE_T ); +extern void (WINAPI *pBTCpuNotifyMemoryFree)( void *, SIZE_T ); +extern void (WINAPI *pBTCpuNotifyMemoryProtect)( void *, SIZE_T, ULONG ); +extern void (WINAPI *pBTCpuNotifyUnmapViewOfSection)( void * ); +extern void (WINAPI *pBTCpuUpdateProcessorInformation)( SYSTEM_CPU_INFORMATION * );
struct object_attr64 {