Module: wine Branch: master Commit: 711bde7cd11bfbb691e0e9b5fa2efae82a4f541c URL: https://source.winehq.org/git/wine.git/?a=commit;h=711bde7cd11bfbb691e0e9b5f...
Author: Alexandre Julliard julliard@winehq.org Date: Mon May 17 09:39:34 2021 +0200
ntdll: Add a helper function to set the thread id.
Signed-off-by: Alexandre Julliard julliard@winehq.org
---
dlls/ntdll/unix/server.c | 38 ++++++++++---------------------------- dlls/ntdll/unix/thread.c | 30 +++++++++++++++++++++++++----- dlls/ntdll/unix/unix_private.h | 1 + 3 files changed, 36 insertions(+), 33 deletions(-)
diff --git a/dlls/ntdll/unix/server.c b/dlls/ntdll/unix/server.c index 9f10bb135bd..33a49adb8e8 100644 --- a/dlls/ntdll/unix/server.c +++ b/dlls/ntdll/unix/server.c @@ -1446,22 +1446,6 @@ static int init_thread_pipe(void) }
-/*********************************************************************** - * init_teb64 - * - * Initialize the 64-bit part of the TEB for WoW64 threads. - */ -static void init_teb64( TEB *teb ) -{ -#ifndef _WIN64 - TEB64 *teb64 = (TEB64 *)((char *)teb - teb_offset); - - if (!is_wow64) return; - teb64->ClientId.UniqueProcess = PtrToUlong( teb->ClientId.UniqueProcess ); - teb64->ClientId.UniqueThread = PtrToUlong( teb->ClientId.UniqueThread ); -#endif -} - /*********************************************************************** * process_exit_wrapper * @@ -1488,6 +1472,7 @@ size_t server_init_process(void) int ret, reply_pipe; struct sigaction sig_act; size_t info_size; + DWORD pid, tid;
server_pid = -1; if (env_socket) @@ -1558,8 +1543,8 @@ size_t server_init_process(void) req->debug_level = (TRACE_ON(server) != 0); wine_server_set_reply( req, supported_machines, sizeof(supported_machines) ); ret = wine_server_call( req ); - NtCurrentTeb()->ClientId.UniqueProcess = ULongToHandle(reply->pid); - NtCurrentTeb()->ClientId.UniqueThread = ULongToHandle(reply->tid); + pid = reply->pid; + tid = reply->tid; info_size = reply->info_size; server_start_time = reply->server_start; supported_machines_count = wine_server_reply_size( reply ) / sizeof(*supported_machines); @@ -1578,13 +1563,11 @@ size_t server_init_process(void) { if (arch && !strcmp( arch, "win32" )) fatal_error( "WINEARCH set to win32 but '%s' is a 64-bit installation.\n", config_dir ); - if (!is_win64) - { - is_wow64 = TRUE; - NtCurrentTeb()->GdiBatchCount = PtrToUlong( (char *)NtCurrentTeb() - teb_offset ); - NtCurrentTeb()->WowTebOffset = -teb_offset; - init_teb64( NtCurrentTeb() ); - } +#ifndef _WIN64 + is_wow64 = TRUE; + NtCurrentTeb()->GdiBatchCount = PtrToUlong( (char *)NtCurrentTeb() - teb_offset ); + NtCurrentTeb()->WowTebOffset = -teb_offset; +#endif } else { @@ -1594,6 +1577,8 @@ size_t server_init_process(void) fatal_error( "WINEARCH set to win64 but '%s' is a 32-bit installation.\n", config_dir ); }
+ set_thread_id( NtCurrentTeb(), pid, tid ); + for (i = 0; i < supported_machines_count; i++) if (supported_machines[i] == current_machine) return info_size;
@@ -1675,12 +1660,9 @@ void server_init_thread( void *entry_point, BOOL *suspend ) req->wait_fd = ntdll_get_thread_data()->wait_fd[1]; wine_server_call( req ); *suspend = reply->suspend; - NtCurrentTeb()->ClientId.UniqueProcess = ULongToHandle(reply->pid); - NtCurrentTeb()->ClientId.UniqueThread = ULongToHandle(reply->tid); } SERVER_END_REQ; close( reply_pipe ); - init_teb64( NtCurrentTeb() ); }
diff --git a/dlls/ntdll/unix/thread.c b/dlls/ntdll/unix/thread.c index 01eeb666a44..079ac16952d 100644 --- a/dlls/ntdll/unix/thread.c +++ b/dlls/ntdll/unix/thread.c @@ -119,6 +119,28 @@ static void start_thread( TEB *teb ) }
+/*********************************************************************** + * set_thread_id + */ +void set_thread_id( TEB *teb, DWORD pid, DWORD tid ) +{ + teb->ClientId.UniqueProcess = ULongToHandle( pid ); + teb->ClientId.UniqueThread = ULongToHandle( tid ); + if (teb->WowTebOffset) + { +#ifdef _WIN64 + TEB32 *teb32 = (TEB32 *)((char *)teb + teb->WowTebOffset); + teb32->ClientId.UniqueProcess = pid; + teb32->ClientId.UniqueThread = tid; +#else + TEB64 *teb64 = (TEB64 *)((char *)teb + teb->WowTebOffset); + teb64->ClientId.UniqueProcess = pid; + teb64->ClientId.UniqueThread = tid; +#endif + } +} + + /*********************************************************************** * update_attr_list * @@ -173,7 +195,6 @@ NTSTATUS WINAPI NtCreateThreadEx( HANDLE *handle, ACCESS_MASK access, OBJECT_ATT DWORD tid = 0; int request_pipe[2]; SIZE_T extra_stack = PTHREAD_STACK_MIN; - CLIENT_ID client_id; TEB *teb; INITIAL_TEB stack; NTSTATUS status; @@ -200,6 +221,7 @@ NTSTATUS WINAPI NtCreateThreadEx( HANDLE *handle, ACCESS_MASK access, OBJECT_ATT
if (result.create_thread.status == STATUS_SUCCESS) { + CLIENT_ID client_id; TEB *teb = wine_server_get_ptr( result.create_thread.teb ); *handle = wine_server_ptr_handle( result.create_thread.handle ); client_id.UniqueProcess = ULongToHandle( result.create_thread.pid ); @@ -253,9 +275,7 @@ NTSTATUS WINAPI NtCreateThreadEx( HANDLE *handle, ACCESS_MASK access, OBJECT_ATT goto done; }
- client_id.UniqueProcess = ULongToHandle( GetCurrentProcessId() ); - client_id.UniqueThread = ULongToHandle( tid ); - teb->ClientId = client_id; + set_thread_id( teb, GetCurrentProcessId(), tid );
teb->Tib.StackBase = stack.StackBase; teb->Tib.StackLimit = stack.StackLimit; @@ -289,7 +309,7 @@ done: close( request_pipe[1] ); return status; } - if (attr_list) update_attr_list( attr_list, &client_id, teb ); + if (attr_list) update_attr_list( attr_list, &teb->ClientId, teb ); return STATUS_SUCCESS; }
diff --git a/dlls/ntdll/unix/unix_private.h b/dlls/ntdll/unix/unix_private.h index ce34cea7fcf..5c340107964 100644 --- a/dlls/ntdll/unix/unix_private.h +++ b/dlls/ntdll/unix/unix_private.h @@ -172,6 +172,7 @@ extern void server_init_process_done(void) DECLSPEC_HIDDEN; extern void server_init_thread( void *entry_point, BOOL *suspend ) DECLSPEC_HIDDEN; extern int server_pipe( int fd[2] ) DECLSPEC_HIDDEN;
+extern void set_thread_id( TEB *teb, DWORD pid, DWORD tid ) DECLSPEC_HIDDEN; extern NTSTATUS context_to_server( context_t *to, const CONTEXT *from ) DECLSPEC_HIDDEN; extern NTSTATUS context_from_server( CONTEXT *to, const context_t *from ) DECLSPEC_HIDDEN; extern void DECLSPEC_NORETURN abort_thread( int status ) DECLSPEC_HIDDEN;