Commit 75019420 authored by Ken Thomases's avatar Ken Thomases Committed by Alexandre Julliard

ntdll: For Mac 64-bit, poke the TEB address to %gs:0x30 and re-enable the…

ntdll: For Mac 64-bit, poke the TEB address to %gs:0x30 and re-enable the inlining of NtCurrentTeb(). 64-bit Windows apps have hard-coded accesses to %gs:0x30 baked into them. They need to find the TEB self pointer there. Technically, the gsbase register and the memory it points to belong to the pthread implementation on macOS. It's used for the pthread TLS implementation. However, study of the sources and experimentation reveal that TLS slot 6 (offset 0x30) is not currently used. Furthermore, Apple has promised to not use that slot in the future. So, we hijack it for our purposes. Signed-off-by: 's avatarKen Thomases <ken@codeweavers.com> Signed-off-by: 's avatarAlexandre Julliard <julliard@winehq.org>
parent b05704db
...@@ -149,7 +149,7 @@ ...@@ -149,7 +149,7 @@
@ stdcall NtCreateTimer(ptr long ptr long) @ stdcall NtCreateTimer(ptr long ptr long)
@ stub NtCreateToken @ stub NtCreateToken
# @ stub NtCreateWaitablePort # @ stub NtCreateWaitablePort
@ stdcall NtCurrentTeb() @ stdcall -arch=win32,arm64 NtCurrentTeb()
# @ stub NtDebugActiveProcess # @ stub NtDebugActiveProcess
# @ stub NtDebugContinue # @ stub NtDebugContinue
@ stdcall NtDelayExecution(long ptr) @ stdcall NtDelayExecution(long ptr)
......
...@@ -241,8 +241,6 @@ static inline int arch_prctl( int func, void *ptr ) { return syscall( __NR_arch_ ...@@ -241,8 +241,6 @@ static inline int arch_prctl( int func, void *ptr ) { return syscall( __NR_arch_
#define FPU_sig(context) ((XMM_SAVE_AREA32 *)((context)->uc_mcontext.__fpregs)) #define FPU_sig(context) ((XMM_SAVE_AREA32 *)((context)->uc_mcontext.__fpregs))
#elif defined (__APPLE__) #elif defined (__APPLE__)
static pthread_key_t teb_key;
#define RAX_sig(context) ((context)->uc_mcontext->__ss.__rax) #define RAX_sig(context) ((context)->uc_mcontext->__ss.__rax)
#define RBX_sig(context) ((context)->uc_mcontext->__ss.__rbx) #define RBX_sig(context) ((context)->uc_mcontext->__ss.__rbx)
#define RCX_sig(context) ((context)->uc_mcontext->__ss.__rcx) #define RCX_sig(context) ((context)->uc_mcontext->__ss.__rcx)
...@@ -2834,13 +2832,6 @@ void signal_free_thread( TEB *teb ) ...@@ -2834,13 +2832,6 @@ void signal_free_thread( TEB *teb )
NtFreeVirtualMemory( NtCurrentProcess(), (void **)&teb, &size, MEM_RELEASE ); NtFreeVirtualMemory( NtCurrentProcess(), (void **)&teb, &size, MEM_RELEASE );
} }
#ifdef __APPLE__
static void init_teb_key(void)
{
pthread_key_create( &teb_key, NULL );
}
#endif
/********************************************************************** /**********************************************************************
* signal_init_thread * signal_init_thread
*/ */
...@@ -2849,10 +2840,6 @@ void signal_init_thread( TEB *teb ) ...@@ -2849,10 +2840,6 @@ void signal_init_thread( TEB *teb )
const WORD fpu_cw = 0x27f; const WORD fpu_cw = 0x27f;
stack_t ss; stack_t ss;
#ifdef __APPLE__
static pthread_once_t init_once = PTHREAD_ONCE_INIT;
#endif
#if defined __linux__ #if defined __linux__
arch_prctl( ARCH_SET_GS, teb ); arch_prctl( ARCH_SET_GS, teb );
#elif defined (__FreeBSD__) || defined (__FreeBSD_kernel__) #elif defined (__FreeBSD__) || defined (__FreeBSD_kernel__)
...@@ -2860,9 +2847,9 @@ void signal_init_thread( TEB *teb ) ...@@ -2860,9 +2847,9 @@ void signal_init_thread( TEB *teb )
#elif defined(__NetBSD__) #elif defined(__NetBSD__)
sysarch( X86_64_SET_GSBASE, &teb ); sysarch( X86_64_SET_GSBASE, &teb );
#elif defined (__APPLE__) #elif defined (__APPLE__)
/* FIXME: Actually setting %gs needs support from the OS */ __asm__ volatile (".byte 0x65\n\tmovq %0,%c1"
pthread_once( &init_once, init_teb_key ); :
pthread_setspecific( teb_key, teb ); : "r" (teb->Tib.Self), "n" (FIELD_OFFSET(TEB, Tib.Self)));
#else #else
# error Please define setting %gs for your architecture # error Please define setting %gs for your architecture
#endif #endif
...@@ -3847,19 +3834,4 @@ __ASM_STDCALL_FUNC( DbgBreakPoint, 0, "int $3; ret") ...@@ -3847,19 +3834,4 @@ __ASM_STDCALL_FUNC( DbgBreakPoint, 0, "int $3; ret")
*/ */
__ASM_STDCALL_FUNC( DbgUserBreakPoint, 0, "int $3; ret") __ASM_STDCALL_FUNC( DbgUserBreakPoint, 0, "int $3; ret")
/**********************************************************************
* NtCurrentTeb (NTDLL.@)
*
* FIXME: This isn't exported from NTDLL on real NT. This should be
* removed if and when we can set the GSBASE MSR on Mac OS X.
*/
#ifdef __APPLE__
TEB * WINAPI NtCurrentTeb(void)
{
return pthread_getspecific( teb_key );
}
#else
__ASM_STDCALL_FUNC( NtCurrentTeb, 0, ".byte 0x65\n\tmovq 0x30,%rax\n\tret" )
#endif
#endif /* __x86_64__ */ #endif /* __x86_64__ */
...@@ -2331,7 +2331,7 @@ static FORCEINLINE struct _TEB * WINAPI NtCurrentTeb(void) ...@@ -2331,7 +2331,7 @@ static FORCEINLINE struct _TEB * WINAPI NtCurrentTeb(void)
__asm mov teb, eax; __asm mov teb, eax;
return teb; return teb;
} }
#elif defined(__x86_64__) && defined(__GNUC__) && !defined(__APPLE__) #elif defined(__x86_64__) && defined(__GNUC__)
static FORCEINLINE struct _TEB * WINAPI NtCurrentTeb(void) static FORCEINLINE struct _TEB * WINAPI NtCurrentTeb(void)
{ {
struct _TEB *teb; struct _TEB *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