Commit dd7b4431 authored by Alexandre Julliard's avatar Alexandre Julliard

ntdll: Add a helper function to check for Wow64 mode.

parent f3d90fd5
......@@ -1434,7 +1434,7 @@ NTSTATUS WINAPI NtQueryInformationProcess( HANDLE handle, PROCESSINFOCLASS class
if (size != len) ret = STATUS_INFO_LENGTH_MISMATCH;
else if (!info) ret = STATUS_ACCESS_VIOLATION;
else if (!handle) ret = STATUS_INVALID_HANDLE;
else if (handle == GetCurrentProcess()) *(ULONG_PTR *)info = !!NtCurrentTeb()->WowTebOffset;
else if (handle == GetCurrentProcess()) *(ULONG_PTR *)info = is_wow64();
else
{
ULONG_PTR val = 0;
......@@ -1476,7 +1476,7 @@ NTSTATUS WINAPI NtQueryInformationProcess( HANDLE handle, PROCESSINFOCLASS class
len = sizeof(ULONG);
if (size != len)
ret = STATUS_INFO_LENGTH_MISMATCH;
else if (is_win64 && !NtCurrentTeb()->WowTebOffset)
else if (is_win64 && !is_wow64())
*(ULONG *)info = MEM_EXECUTE_OPTION_DISABLE |
MEM_EXECUTE_OPTION_DISABLE_THUNK_EMULATION |
MEM_EXECUTE_OPTION_PERMANENT;
......@@ -1639,7 +1639,7 @@ NTSTATUS WINAPI NtSetInformationProcess( HANDLE handle, PROCESSINFOCLASS class,
break;
case ProcessExecuteFlags:
if ((is_win64 && !NtCurrentTeb()->WowTebOffset) || size != sizeof(ULONG)) return STATUS_INVALID_PARAMETER;
if ((is_win64 && !is_wow64()) || size != sizeof(ULONG)) return STATUS_INVALID_PARAMETER;
if (execute_flags & MEM_EXECUTE_OPTION_PERMANENT) return STATUS_ACCESS_DENIED;
else
{
......
......@@ -419,7 +419,7 @@ static void invoke_system_apc( const apc_call_t *call, apc_result_t *result, BOO
};
SYSTEM_BASIC_INFORMATION sbi;
virtual_get_system_info( &sbi, !!NtCurrentTeb()->WowTebOffset );
virtual_get_system_info( &sbi, is_wow64() );
result->type = call->type;
addr = wine_server_get_ptr( call->virtual_alloc_ex.addr );
size = call->virtual_alloc_ex.size;
......
......@@ -2998,7 +2998,7 @@ NTSTATUS WINAPI NtQuerySystemInformation( SYSTEM_INFORMATION_CLASS class,
{
SYSTEM_BASIC_INFORMATION sbi;
virtual_get_system_info( &sbi, !!NtCurrentTeb()->WowTebOffset );
virtual_get_system_info( &sbi, is_wow64() );
len = sizeof(sbi);
if (size == len)
{
......
......@@ -1130,7 +1130,7 @@ void *get_cpu_area( USHORT machine )
WOW64_CPURESERVED *cpu;
ULONG align;
if (!NtCurrentTeb()->WowTebOffset) return NULL;
if (!is_wow64()) return NULL;
#ifdef _WIN64
cpu = NtCurrentTeb()->TlsSlots[WOW64_TLS_CPURESERVED];
#else
......
......@@ -52,6 +52,34 @@ static inline BOOL is_machine_64bit( WORD machine )
return (machine == IMAGE_FILE_MACHINE_AMD64 || machine == IMAGE_FILE_MACHINE_ARM64);
}
#ifdef _WIN64
typedef TEB32 WOW_TEB;
typedef PEB32 WOW_PEB;
static inline TEB64 *NtCurrentTeb64(void) { return NULL; }
#else
typedef TEB64 WOW_TEB;
typedef PEB64 WOW_PEB;
static inline TEB64 *NtCurrentTeb64(void) { return (TEB64 *)NtCurrentTeb()->GdiBatchCount; }
#endif
extern WOW_PEB *wow_peb DECLSPEC_HIDDEN;
static inline WOW_TEB *get_wow_teb( TEB *teb )
{
return teb->WowTebOffset ? (WOW_TEB *)((char *)teb + teb->WowTebOffset) : NULL;
}
static inline BOOL is_wow64(void)
{
return !!wow_peb;
}
/* check for old-style Wow64 (using a 32-bit ntdll.so) */
static inline BOOL is_old_wow64(void)
{
return !is_win64 && wow_peb;
}
/* thread private data, stored in NtCurrentTeb()->GdiTebBatch */
struct ntdll_thread_data
{
......@@ -366,10 +394,7 @@ static inline NTSTATUS wait_async( HANDLE handle, BOOL alertable )
static inline BOOL in_wow64_call(void)
{
#ifdef _WIN64
return !!NtCurrentTeb()->WowTebOffset;
#endif
return FALSE;
return is_win64 && is_wow64();
}
static inline void set_async_iosb( client_ptr_t iosb, NTSTATUS status, ULONG_PTR info )
......@@ -426,29 +451,6 @@ static inline client_ptr_t iosb_client_ptr( IO_STATUS_BLOCK *io )
return wine_server_client_ptr( io );
}
#ifdef _WIN64
typedef TEB32 WOW_TEB;
typedef PEB32 WOW_PEB;
static inline TEB64 *NtCurrentTeb64(void) { return NULL; }
#else
typedef TEB64 WOW_TEB;
typedef PEB64 WOW_PEB;
static inline TEB64 *NtCurrentTeb64(void) { return (TEB64 *)NtCurrentTeb()->GdiBatchCount; }
#endif
extern WOW_PEB *wow_peb DECLSPEC_HIDDEN;
static inline WOW_TEB *get_wow_teb( TEB *teb )
{
return teb->WowTebOffset ? (WOW_TEB *)((char *)teb + teb->WowTebOffset) : NULL;
}
/* check for old-style Wow64 (using a 32-bit ntdll.so) */
static inline BOOL is_old_wow64(void)
{
return !is_win64 && wow_peb;
}
enum loadorder
{
LO_INVALID,
......
......@@ -2974,7 +2974,6 @@ NTSTATUS virtual_alloc_teb( TEB **ret_teb )
void *ptr = NULL;
NTSTATUS status = STATUS_SUCCESS;
SIZE_T block_size = signal_stack_mask + 1;
BOOL is_wow = !!NtCurrentTeb()->WowTebOffset;
server_enter_uninterrupted_section( &virtual_mutex, &sigset );
if (next_free_teb)
......@@ -2989,7 +2988,7 @@ NTSTATUS virtual_alloc_teb( TEB **ret_teb )
{
SIZE_T total = 32 * block_size;
if ((status = NtAllocateVirtualMemory( NtCurrentProcess(), &ptr, is_win64 && is_wow ? 0x7fffffff : 0,
if ((status = NtAllocateVirtualMemory( NtCurrentProcess(), &ptr, is_win64 && is_wow64() ? 0x7fffffff : 0,
&total, MEM_RESERVE, PAGE_READWRITE )))
{
server_leave_uninterrupted_section( &virtual_mutex, &sigset );
......@@ -3002,7 +3001,7 @@ NTSTATUS virtual_alloc_teb( TEB **ret_teb )
NtAllocateVirtualMemory( NtCurrentProcess(), (void **)&ptr, 0, &block_size,
MEM_COMMIT, PAGE_READWRITE );
}
*ret_teb = teb = init_teb( ptr, is_wow );
*ret_teb = teb = init_teb( ptr, is_wow64() );
server_leave_uninterrupted_section( &virtual_mutex, &sigset );
if ((status = signal_alloc_thread( teb )))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment