diff --git a/patches/ntdll-OSX_TEB_x86_64/0001-ntdll-Set-0x30-TEB-field-on-OS-X-64-bit.patch b/patches/ntdll-OSX_TEB_x86_64/0001-ntdll-Set-0x30-TEB-field-on-OS-X-64-bit.patch new file mode 100644 index 00000000..3e14a3a9 --- /dev/null +++ b/patches/ntdll-OSX_TEB_x86_64/0001-ntdll-Set-0x30-TEB-field-on-OS-X-64-bit.patch @@ -0,0 +1,90 @@ +From d9d0084d97f4f17468882bb830ea7005afc920ca Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Michael=20M=C3=BCller?= +Date: Sat, 9 Apr 2016 03:21:45 +0200 +Subject: ntdll: Set 0x30 TEB field on OS X 64 bit. + +--- + dlls/ntdll/signal_x86_64.c | 24 ++---------------------- + include/winnt.h | 2 +- + 2 files changed, 3 insertions(+), 23 deletions(-) + +diff --git a/dlls/ntdll/signal_x86_64.c b/dlls/ntdll/signal_x86_64.c +index ca3e6ca..29f7b78 100644 +--- a/dlls/ntdll/signal_x86_64.c ++++ b/dlls/ntdll/signal_x86_64.c +@@ -241,7 +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)) + #elif defined (__APPLE__) +-static pthread_key_t teb_key; + + #define RAX_sig(context) ((context)->uc_mcontext->__ss.__rax) + #define RBX_sig(context) ((context)->uc_mcontext->__ss.__rbx) +@@ -2834,12 +2833,6 @@ void signal_free_thread( TEB *teb ) + 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 +@@ -2849,10 +2842,6 @@ void signal_init_thread( TEB *teb ) + const WORD fpu_cw = 0x27f; + stack_t ss; + +-#ifdef __APPLE__ +- static pthread_once_t init_once = PTHREAD_ONCE_INIT; +-#endif +- + #if defined __linux__ + arch_prctl( ARCH_SET_GS, teb ); + #elif defined (__FreeBSD__) || defined (__FreeBSD_kernel__) +@@ -2861,8 +2850,7 @@ void signal_init_thread( TEB *teb ) + sysarch( X86_64_SET_GSBASE, &teb ); + #elif defined (__APPLE__) + /* FIXME: Actually setting %gs needs support from the OS */ +- pthread_once( &init_once, init_teb_key ); +- pthread_setspecific( teb_key, teb ); ++ __asm__ volatile (".byte 0x65\n\tmovq %0,(0x30)" : : "r" (teb)); + #else + # error Please define setting %gs for your architecture + #endif +@@ -3844,16 +3832,8 @@ __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. ++ * FIXME: This isn't exported from NTDLL on real NT. + */ +-#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__ */ +diff --git a/include/winnt.h b/include/winnt.h +index 5ece0f7..4bd4fc0 100644 +--- a/include/winnt.h ++++ b/include/winnt.h +@@ -2328,7 +2328,7 @@ static FORCEINLINE struct _TEB * WINAPI NtCurrentTeb(void) + __asm mov teb, eax; + return teb; + } +-#elif defined(__x86_64__) && defined(__GNUC__) && !defined(__APPLE__) ++#elif defined(__x86_64__) && defined(__GNUC__) + static FORCEINLINE struct _TEB * WINAPI NtCurrentTeb(void) + { + struct _TEB *teb; +-- +2.7.1 + diff --git a/patches/ntdll-OSX_TEB_x86_64/definition b/patches/ntdll-OSX_TEB_x86_64/definition new file mode 100644 index 00000000..a3e42d0d --- /dev/null +++ b/patches/ntdll-OSX_TEB_x86_64/definition @@ -0,0 +1 @@ +Fixes: Improve compatibility of 64-bit support for OS X diff --git a/patches/patchinstall.sh b/patches/patchinstall.sh index 056417b2..29c14980 100755 --- a/patches/patchinstall.sh +++ b/patches/patchinstall.sh @@ -216,6 +216,7 @@ patch_enable_all () enable_ntdll_NtQueryEaFile="$1" enable_ntdll_NtQuerySection="$1" enable_ntdll_NtSetLdtEntries="$1" + enable_ntdll_OSX_TEB_x86_64="$1" enable_ntdll_Pipe_SpecialCharacters="$1" enable_ntdll_ProcessQuotaLimits="$1" enable_ntdll_Purist_Mode="$1" @@ -819,6 +820,9 @@ patch_enable () ntdll-NtSetLdtEntries) enable_ntdll_NtSetLdtEntries="$2" ;; + ntdll-OSX_TEB_x86_64) + enable_ntdll_OSX_TEB_x86_64="$2" + ;; ntdll-Pipe_SpecialCharacters) enable_ntdll_Pipe_SpecialCharacters="$2" ;; @@ -4900,6 +4904,18 @@ if test "$enable_ntdll_NtSetLdtEntries" -eq 1; then ) >> "$patchlist" fi +# Patchset ntdll-OSX_TEB_x86_64 +# | +# | Modified files: +# | * dlls/ntdll/signal_x86_64.c, include/winnt.h +# | +if test "$enable_ntdll_OSX_TEB_x86_64" -eq 1; then + patch_apply ntdll-OSX_TEB_x86_64/0001-ntdll-Set-0x30-TEB-field-on-OS-X-64-bit.patch + ( + echo '+ { "Michael Müller", "ntdll: Set 0x30 TEB field on OS X 64 bit.", 1 },'; + ) >> "$patchlist" +fi + # Patchset ntdll-Pipe_SpecialCharacters # | # | This patchset fixes the following Wine bugs: