Commit 6ecc8039 authored by Alexandre Julliard's avatar Alexandre Julliard

ntdll: Use a pthread key for the TEB on all platforms.

parent c212987d
...@@ -1770,9 +1770,4 @@ __ASM_GLOBAL_FUNC( __wine_longjmp, ...@@ -1770,9 +1770,4 @@ __ASM_GLOBAL_FUNC( __wine_longjmp,
"mov r0, r1\n\t" /* retval */ "mov r0, r1\n\t" /* retval */
"bx r2" ) "bx r2" )
/**********************************************************************
* NtCurrentTeb (NTDLL.@)
*/
__ASM_GLOBAL_FUNC( NtCurrentTeb, "mrc p15, 0, r0, c13, c0, 2; bx lr" )
#endif /* __arm__ */ #endif /* __arm__ */
...@@ -129,8 +129,6 @@ static DWORD64 get_fault_esr( ucontext_t *sigcontext ) ...@@ -129,8 +129,6 @@ static DWORD64 get_fault_esr( ucontext_t *sigcontext )
#endif /* linux */ #endif /* linux */
static pthread_key_t teb_key;
struct syscall_frame struct syscall_frame
{ {
ULONG64 x[29]; /* 000 */ ULONG64 x[29]; /* 000 */
...@@ -1320,7 +1318,6 @@ NTSTATUS WINAPI NtSetLdtEntries( ULONG sel1, LDT_ENTRY entry1, ULONG sel2, LDT_E ...@@ -1320,7 +1318,6 @@ NTSTATUS WINAPI NtSetLdtEntries( ULONG sel1, LDT_ENTRY entry1, ULONG sel2, LDT_E
*/ */
void signal_init_threading(void) void signal_init_threading(void)
{ {
pthread_key_create( &teb_key, NULL );
} }
...@@ -1348,8 +1345,6 @@ void signal_init_thread( TEB *teb ) ...@@ -1348,8 +1345,6 @@ void signal_init_thread( TEB *teb )
{ {
/* Win64/ARM applications expect the TEB pointer to be in the x18 platform register. */ /* Win64/ARM applications expect the TEB pointer to be in the x18 platform register. */
__asm__ __volatile__( "mov x18, %0" : : "r" (teb) ); __asm__ __volatile__( "mov x18, %0" : : "r" (teb) );
pthread_setspecific( teb_key, teb );
} }
...@@ -1634,13 +1629,4 @@ __ASM_GLOBAL_FUNC( __wine_longjmp, ...@@ -1634,13 +1629,4 @@ __ASM_GLOBAL_FUNC( __wine_longjmp,
"mov x0, x1\n\t" /* retval */ "mov x0, x1\n\t" /* retval */
"ret" ) "ret" )
/**********************************************************************
* NtCurrentTeb (NTDLL.@)
*/
TEB * WINAPI NtCurrentTeb(void)
{
return pthread_getspecific( teb_key );
}
#endif /* __aarch64__ */ #endif /* __aarch64__ */
...@@ -2752,10 +2752,4 @@ __ASM_GLOBAL_FUNC( __wine_longjmp, ...@@ -2752,10 +2752,4 @@ __ASM_GLOBAL_FUNC( __wine_longjmp,
"addl $4,%esp\n\t" /* get rid of return address */ "addl $4,%esp\n\t" /* get rid of return address */
"jmp *20(%ecx)\n\t" /* jmp_buf.Eip */ ) "jmp *20(%ecx)\n\t" /* jmp_buf.Eip */ )
/**********************************************************************
* NtCurrentTeb (NTDLL.@)
*/
__ASM_STDCALL_FUNC( NtCurrentTeb, 0, ".byte 0x64\n\tmovl 0x18,%eax\n\tret" )
#endif /* __i386__ */ #endif /* __i386__ */
...@@ -2896,9 +2896,4 @@ __ASM_GLOBAL_FUNC( __wine_longjmp, ...@@ -2896,9 +2896,4 @@ __ASM_GLOBAL_FUNC( __wine_longjmp,
"movq 0x10(%rcx),%rsp\n\t" /* jmp_buf->Rsp */ "movq 0x10(%rcx),%rsp\n\t" /* jmp_buf->Rsp */
"jmp *%rdx" ) "jmp *%rdx" )
/**********************************************************************
* NtCurrentTeb (NTDLL.@)
*/
__ASM_GLOBAL_FUNC( NtCurrentTeb, "movq %gs:0x30,%rax; ret" )
#endif /* __x86_64__ */ #endif /* __x86_64__ */
...@@ -73,6 +73,8 @@ WINE_DEFAULT_DEBUG_CHANNEL(thread); ...@@ -73,6 +73,8 @@ WINE_DEFAULT_DEBUG_CHANNEL(thread);
WINE_DECLARE_DEBUG_CHANNEL(seh); WINE_DECLARE_DEBUG_CHANNEL(seh);
WINE_DECLARE_DEBUG_CHANNEL(threadname); WINE_DECLARE_DEBUG_CHANNEL(threadname);
pthread_key_t teb_key = 0;
static int nb_threads = 1; static int nb_threads = 1;
static inline int get_unix_exit_code( NTSTATUS status ) static inline int get_unix_exit_code( NTSTATUS status )
...@@ -1066,6 +1068,7 @@ static void start_thread( TEB *teb ) ...@@ -1066,6 +1068,7 @@ static void start_thread( TEB *teb )
BOOL suspend; BOOL suspend;
thread_data->pthread_id = pthread_self(); thread_data->pthread_id = pthread_self();
pthread_setspecific( teb_key, teb );
signal_init_thread( teb ); signal_init_thread( teb );
server_init_thread( thread_data->start, &suspend ); server_init_thread( thread_data->start, &suspend );
signal_start_thread( thread_data->start, thread_data->param, suspend, teb ); signal_start_thread( thread_data->start, thread_data->param, suspend, teb );
...@@ -1523,6 +1526,15 @@ NTSTATUS WINAPI NtRaiseException( EXCEPTION_RECORD *rec, CONTEXT *context, BOOL ...@@ -1523,6 +1526,15 @@ NTSTATUS WINAPI NtRaiseException( EXCEPTION_RECORD *rec, CONTEXT *context, BOOL
} }
/**********************************************************************
* NtCurrentTeb (NTDLL.@)
*/
TEB * WINAPI NtCurrentTeb(void)
{
return pthread_getspecific( teb_key );
}
/*********************************************************************** /***********************************************************************
* NtOpenThread (NTDLL.@) * NtOpenThread (NTDLL.@)
*/ */
......
...@@ -117,6 +117,7 @@ extern const char *config_dir DECLSPEC_HIDDEN; ...@@ -117,6 +117,7 @@ extern const char *config_dir DECLSPEC_HIDDEN;
extern const char *user_name DECLSPEC_HIDDEN; extern const char *user_name DECLSPEC_HIDDEN;
extern const char **dll_paths DECLSPEC_HIDDEN; extern const char **dll_paths DECLSPEC_HIDDEN;
extern const char **system_dll_paths DECLSPEC_HIDDEN; extern const char **system_dll_paths DECLSPEC_HIDDEN;
extern pthread_key_t teb_key DECLSPEC_HIDDEN;
extern PEB *peb DECLSPEC_HIDDEN; extern PEB *peb DECLSPEC_HIDDEN;
extern USHORT *uctable DECLSPEC_HIDDEN; extern USHORT *uctable DECLSPEC_HIDDEN;
extern USHORT *lctable DECLSPEC_HIDDEN; extern USHORT *lctable DECLSPEC_HIDDEN;
......
...@@ -2929,6 +2929,7 @@ static TEB *init_teb( void *ptr, BOOL is_wow ) ...@@ -2929,6 +2929,7 @@ static TEB *init_teb( void *ptr, BOOL is_wow )
TEB *virtual_alloc_first_teb(void) TEB *virtual_alloc_first_teb(void)
{ {
void *ptr; void *ptr;
TEB *teb;
NTSTATUS status; NTSTATUS status;
SIZE_T data_size = page_size; SIZE_T data_size = page_size;
SIZE_T block_size = signal_stack_mask + 1; SIZE_T block_size = signal_stack_mask + 1;
...@@ -2950,7 +2951,10 @@ TEB *virtual_alloc_first_teb(void) ...@@ -2950,7 +2951,10 @@ TEB *virtual_alloc_first_teb(void)
data_size = 2 * block_size; data_size = 2 * block_size;
NtAllocateVirtualMemory( NtCurrentProcess(), (void **)&ptr, 0, &data_size, MEM_COMMIT, PAGE_READWRITE ); NtAllocateVirtualMemory( NtCurrentProcess(), (void **)&ptr, 0, &data_size, MEM_COMMIT, PAGE_READWRITE );
peb = (PEB *)((char *)teb_block + 31 * block_size + (is_win64 ? 0 : page_size)); peb = (PEB *)((char *)teb_block + 31 * block_size + (is_win64 ? 0 : page_size));
return init_teb( ptr, FALSE ); teb = init_teb( ptr, FALSE );
pthread_key_create( &teb_key, NULL );
pthread_setspecific( teb_key, teb );
return 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