From 3e3af62be980ff2ed5d2bdce21f78feeedd973ed Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Thu, 9 Mar 2023 17:25:07 +0100 Subject: [PATCH] wow64: Create the WOW64INFO structure. --- dlls/wow64/syscall.c | 8 ++++++++ dlls/wow64cpu/cpu.c | 3 +++ include/winternl.h | 14 ++++++++++++++ 3 files changed, 25 insertions(+) diff --git a/dlls/wow64/syscall.c b/dlls/wow64/syscall.c index d2bb054b6d0..17cfe337532 100644 --- a/dlls/wow64/syscall.c +++ b/dlls/wow64/syscall.c @@ -97,6 +97,7 @@ SYSTEM_DLL_INIT_BLOCK *pLdrSystemDllInitBlock = NULL; /* wow64win syscall table */ static const SYSTEM_SERVICE_TABLE *psdwhwin32; static HMODULE win32u_module; +static WOW64INFO *wow64info; /* cpu backend dll functions */ static void * (WINAPI *pBTCpuGetBopCode)(void); @@ -783,6 +784,7 @@ static const WCHAR *get_cpu_dll_name(void) */ static DWORD WINAPI process_init( RTL_RUN_ONCE *once, void *param, void **context ) { + TEB32 *teb32 = (TEB32 *)((char *)NtCurrentTeb() + NtCurrentTeb()->WowTebOffset); HMODULE module; UNICODE_STRING str = RTL_CONSTANT_STRING( L"ntdll.dll" ); SYSTEM_BASIC_INFORMATION info; @@ -793,6 +795,11 @@ static DWORD WINAPI process_init( RTL_RUN_ONCE *once, void *param, void **contex NtQuerySystemInformation( SystemEmulationBasicInformation, &info, sizeof(info), NULL ); highest_user_address = (ULONG_PTR)info.HighestUserAddress; default_zero_bits = (ULONG_PTR)info.HighestUserAddress | 0x7fffffff; + wow64info = (WOW64INFO *)((PEB32 *)ULongToPtr( teb32->Peb ) + 1); + wow64info->NativeSystemPageSize = 0x1000; + wow64info->NativeMachineType = native_machine; + wow64info->EmulatedMachineType = current_machine; + NtCurrentTeb()->TlsSlots[WOW64_TLS_WOW64INFO] = wow64info; #define GET_PTR(name) p ## name = RtlFindExportedRoutineByName( module, #name ) @@ -836,6 +843,7 @@ static void thread_init(void) void *cpu_area_ctx; RtlWow64GetCurrentCpuArea( NULL, &cpu_area_ctx, NULL ); + NtCurrentTeb()->TlsSlots[WOW64_TLS_WOW64INFO] = wow64info; if (pBTCpuThreadInit) pBTCpuThreadInit(); /* update initial context to jump to 32-bit LdrInitializeThunk (cf. 32-bit call_init_thunk) */ diff --git a/dlls/wow64cpu/cpu.c b/dlls/wow64cpu/cpu.c index 5bcaf9d1c45..7911f7e8b72 100644 --- a/dlls/wow64cpu/cpu.c +++ b/dlls/wow64cpu/cpu.c @@ -290,6 +290,7 @@ NTSTATUS WINAPI BTCpuProcessInit(void) HMODULE module; UNICODE_STRING str; void **p__wine_unix_call_dispatcher; + WOW64INFO *wow64info = NtCurrentTeb()->TlsSlots[WOW64_TLS_WOW64INFO]; if ((ULONG_PTR)syscall_32to64 >> 32) { @@ -297,6 +298,8 @@ NTSTATUS WINAPI BTCpuProcessInit(void) return STATUS_INVALID_ADDRESS; } + wow64info->CpuFlags |= WOW64_CPUFLAGS_MSFT64; + RtlInitUnicodeString( &str, L"ntdll.dll" ); LdrGetDllHandle( NULL, 0, &str, &module ); p__wine_unix_call_dispatcher = RtlFindExportedRoutineByName( module, "__wine_unix_call_dispatcher" ); diff --git a/include/winternl.h b/include/winternl.h index 5a21f167d61..6fd0694b4ce 100644 --- a/include/winternl.h +++ b/include/winternl.h @@ -1085,6 +1085,7 @@ typedef struct _TEB64 #define WOW64_TLS_USERCALLBACKDATA 5 #define WOW64_TLS_APCLIST 7 #define WOW64_TLS_FILESYSREDIR 8 +#define WOW64_TLS_WOW64INFO 10 #define WOW64_TLS_MAX_NUMBER 19 @@ -3855,6 +3856,19 @@ typedef struct _WOW64_CPU_AREA_INFO USHORT Machine; } WOW64_CPU_AREA_INFO, *PWOW64_CPU_AREA_INFO; +typedef struct _WOW64INFO +{ + ULONG NativeSystemPageSize; + ULONG CpuFlags; + ULONG Wow64ExecuteFlags; + ULONG unknown[5]; + USHORT NativeMachineType; + USHORT EmulatedMachineType; +} WOW64INFO; + +#define WOW64_CPUFLAGS_MSFT64 0x01 +#define WOW64_CPUFLAGS_SOFTWARE 0x02 + /* wow64.dll functions */ void * WINAPI Wow64AllocateTemp(SIZE_T); void WINAPI Wow64ApcRoutine(ULONG_PTR,ULONG_PTR,ULONG_PTR,CONTEXT*);