diff --git a/dlls/ntdll/loader.c b/dlls/ntdll/loader.c index 51addaaf983..1dbb0739637 100644 --- a/dlls/ntdll/loader.c +++ b/dlls/ntdll/loader.c @@ -4376,14 +4376,8 @@ void __wine_process_init(void) if (!unix_funcs) load_ntdll_so( ntdll_module, &__wine_spec_nt_header ); - teb = thread_init(); + teb = thread_init( &info_size, &suspend ); peb = teb->Peb; - - /* setup the server connection */ - server_init_process(); - info_size = unix_funcs->server_init_thread( peb, &suspend, &server_cpus, - &is_wow64, &server_start_time ); - peb->ProcessHeap = RtlCreateHeap( HEAP_GROWABLE, NULL, 0, 0, NULL, NULL ); peb->LoaderLock = &loader_section; diff --git a/dlls/ntdll/ntdll_misc.h b/dlls/ntdll/ntdll_misc.h index ff791a60764..f2a1baf17fd 100644 --- a/dlls/ntdll/ntdll_misc.h +++ b/dlls/ntdll/ntdll_misc.h @@ -80,7 +80,7 @@ extern SIZE_T signal_stack_mask DECLSPEC_HIDDEN; extern void signal_init_process(void) DECLSPEC_HIDDEN; extern void version_init(void) DECLSPEC_HIDDEN; extern void debug_init(void) DECLSPEC_HIDDEN; -extern TEB *thread_init(void) DECLSPEC_HIDDEN; +extern TEB *thread_init( SIZE_T *info_size, BOOL *suspend ) DECLSPEC_HIDDEN; extern void actctx_init(void) DECLSPEC_HIDDEN; extern void virtual_init(void) DECLSPEC_HIDDEN; extern void fill_cpu_info(void) DECLSPEC_HIDDEN; diff --git a/dlls/ntdll/server.c b/dlls/ntdll/server.c index bde4a2add18..6fb86a68d6f 100644 --- a/dlls/ntdll/server.c +++ b/dlls/ntdll/server.c @@ -256,7 +256,6 @@ void server_init_process(void) sigaddset( &server_block_set, SIGUSR1 ); sigaddset( &server_block_set, SIGUSR2 ); sigaddset( &server_block_set, SIGCHLD ); - unix_funcs->server_init_process(); } diff --git a/dlls/ntdll/thread.c b/dlls/ntdll/thread.c index d5e34cae3b1..2d4fbe6cbe6 100644 --- a/dlls/ntdll/thread.c +++ b/dlls/ntdll/thread.c @@ -208,13 +208,12 @@ void map_user_shared_data(void) * * NOTES: The first allocated TEB on NT is at 0x7ffde000. */ -TEB *thread_init(void) +TEB *thread_init( SIZE_T *info_size, BOOL *suspend ) { TEB *teb; void *addr; SIZE_T size; NTSTATUS status; - struct ntdll_thread_data *thread_data; virtual_init(); @@ -233,8 +232,8 @@ TEB *thread_init(void) /* allocate and initialize the PEB and initial TEB */ - teb = unix_funcs->virtual_alloc_first_teb(); - unix_funcs->init_threading( &nb_threads, &__wine_ldt_copy ); + teb = unix_funcs->init_threading( &nb_threads, &__wine_ldt_copy, info_size, suspend, &server_cpus, + &is_wow64, &server_start_time ); peb = teb->Peb; peb->FastPebLock = &peb_lock; @@ -266,15 +265,9 @@ TEB *thread_init(void) */ peb->SessionId = 1; - thread_data = (struct ntdll_thread_data *)&teb->GdiTebBatch; - thread_data->request_fd = -1; - thread_data->reply_fd = -1; - thread_data->wait_fd[0] = -1; - thread_data->wait_fd[1] = -1; - - unix_funcs->dbg_init(); unix_funcs->get_paths( &build_dir, &data_dir, &config_dir ); fill_cpu_info(); + server_init_process(); return teb; } diff --git a/dlls/ntdll/unix/debug.c b/dlls/ntdll/unix/debug.c index 2aa6548b361..368baac46f4 100644 --- a/dlls/ntdll/unix/debug.c +++ b/dlls/ntdll/unix/debug.c @@ -290,7 +290,7 @@ int __cdecl __wine_dbg_header( enum __wine_debug_class cls, struct __wine_debug_ /*********************************************************************** * dbg_init */ -void CDECL dbg_init(void) +void dbg_init(void) { setbuf( stdout, NULL ); setbuf( stderr, NULL ); diff --git a/dlls/ntdll/unix/loader.c b/dlls/ntdll/unix/loader.c index 1297c451a10..b6838809f14 100644 --- a/dlls/ntdll/unix/loader.c +++ b/dlls/ntdll/unix/loader.c @@ -1016,7 +1016,6 @@ static struct unix_funcs unix_funcs = virtual_map_section, virtual_get_system_info, virtual_create_builtin_view, - virtual_alloc_first_teb, virtual_alloc_thread_stack, virtual_handle_fault, virtual_locked_server_call, @@ -1049,10 +1048,7 @@ static struct unix_funcs unix_funcs = server_handle_to_fd, server_release_fd, server_pipe, - server_init_process, server_init_process_done, - server_init_thread, - dbg_init, __wine_dbg_get_channel_flags, __wine_dbg_strdup, __wine_dbg_output, diff --git a/dlls/ntdll/unix/server.c b/dlls/ntdll/unix/server.c index 17b23e58d28..9cc01ead7f4 100644 --- a/dlls/ntdll/unix/server.c +++ b/dlls/ntdll/unix/server.c @@ -1399,7 +1399,7 @@ static int get_unix_tid(void) * * Start the server and create the initial socket pair. */ -void CDECL server_init_process(void) +void server_init_process(void) { obj_handle_t version; const char *env_socket = getenv( "WINESERVERSOCKET" ); @@ -1474,8 +1474,7 @@ void CDECL server_init_process_done(void) * * Send an init thread request. */ -size_t CDECL server_init_thread( void *entry_point, BOOL *suspend, unsigned int *cpus, - BOOL *wow64, timeout_t *start_time ) +size_t server_init_thread( void *entry_point, BOOL *suspend ) { static const char *cpu_names[] = { "x86", "x86_64", "PowerPC", "ARM", "ARM64" }; const char *arch = getenv( "WINEARCH" ); @@ -1532,9 +1531,6 @@ size_t CDECL server_init_thread( void *entry_point, BOOL *suspend, unsigned int if (!strcmp( arch, "win64" ) && !is_win64 && !is_wow64) fatal_error( "WINEARCH set to win64 but '%s' is a 32-bit installation.\n", config_dir ); } - if (cpus) *cpus = server_cpus; - if (wow64) *wow64 = is_wow64; - if (start_time) *start_time = server_start_time; return info_size; case STATUS_INVALID_IMAGE_WIN_64: fatal_error( "'%s' is a 32-bit installation, it cannot support 64-bit applications.\n", config_dir ); diff --git a/dlls/ntdll/unix/thread.c b/dlls/ntdll/unix/thread.c index 205a1312e92..3c69dfbd64c 100644 --- a/dlls/ntdll/unix/thread.c +++ b/dlls/ntdll/unix/thread.c @@ -82,13 +82,36 @@ static void pthread_exit_wrapper( int status ) /*********************************************************************** * init_threading */ -void CDECL init_threading( int *nb_threads_ptr, struct ldt_copy **ldt_copy ) +TEB * CDECL init_threading( int *nb_threads_ptr, struct ldt_copy **ldt_copy, SIZE_T *size, BOOL *suspend, + unsigned int *cpus, BOOL *wow64, timeout_t *start_time ) { + TEB *teb; + SIZE_T info_size; + struct ntdll_thread_data *thread_data; #ifdef __i386__ extern struct ldt_copy __wine_ldt_copy; *ldt_copy = &__wine_ldt_copy; #endif nb_threads = nb_threads_ptr; + + teb = virtual_alloc_first_teb(); + thread_data = (struct ntdll_thread_data *)&teb->GdiTebBatch; + thread_data->request_fd = -1; + thread_data->reply_fd = -1; + thread_data->wait_fd[0] = -1; + thread_data->wait_fd[1] = -1; + + signal_init_threading(); + signal_alloc_thread( teb ); + signal_init_thread( teb ); + dbg_init(); + server_init_process(); + info_size = server_init_thread( teb->Peb, suspend ); + if (size) *size = info_size; + if (cpus) *cpus = server_cpus; + if (wow64) *wow64 = is_wow64; + if (start_time) *start_time = server_start_time; + return teb; } @@ -118,7 +141,7 @@ static void start_thread( TEB *teb ) thread_data->debug_info = &debug_info; thread_data->pthread_id = pthread_self(); signal_init_thread( teb ); - server_init_thread( info->entry, &suspend, NULL, NULL, NULL ); + server_init_thread( info->entry, &suspend ); if (info->actctx) { RtlActivateActivationContext( 0, info->actctx, &cookie ); diff --git a/dlls/ntdll/unix/unix_private.h b/dlls/ntdll/unix/unix_private.h index 14c4ee4cd97..962774f8c16 100644 --- a/dlls/ntdll/unix/unix_private.h +++ b/dlls/ntdll/unix/unix_private.h @@ -62,7 +62,6 @@ extern NTSTATUS CDECL virtual_map_section( HANDLE handle, PVOID *addr_ptr, unsig ULONG protect, pe_image_info_t *image_info ) DECLSPEC_HIDDEN; extern void CDECL virtual_get_system_info( SYSTEM_BASIC_INFORMATION *info ) DECLSPEC_HIDDEN; extern NTSTATUS CDECL virtual_create_builtin_view( void *module ) DECLSPEC_HIDDEN; -extern TEB * CDECL virtual_alloc_first_teb(void) DECLSPEC_HIDDEN; extern NTSTATUS CDECL virtual_alloc_thread_stack( INITIAL_TEB *stack, SIZE_T reserve_size, SIZE_T commit_size, SIZE_T *pthread_size ) DECLSPEC_HIDDEN; extern NTSTATUS CDECL virtual_handle_fault( LPCVOID addr, DWORD err, BOOL on_signal_stack ) DECLSPEC_HIDDEN; extern unsigned int CDECL virtual_locked_server_call( void *req_ptr ) DECLSPEC_HIDDEN; @@ -79,10 +78,6 @@ extern void CDECL virtual_set_force_exec( BOOL enable ) DECLSPEC_HIDDEN; extern void CDECL virtual_release_address_space(void) DECLSPEC_HIDDEN; extern void CDECL virtual_set_large_address_space(void) DECLSPEC_HIDDEN; -extern void virtual_init(void) DECLSPEC_HIDDEN; - -extern void CDECL dbg_init(void) DECLSPEC_HIDDEN; - extern unsigned int CDECL server_select( const select_op_t *select_op, data_size_t size, UINT flags, timeout_t abs_timeout, CONTEXT *context, RTL_CRITICAL_SECTION *cs, user_apc_t *user_apc ) DECLSPEC_HIDDEN; @@ -99,11 +94,10 @@ extern NTSTATUS CDECL server_handle_to_fd( HANDLE handle, unsigned int access, i unsigned int *options ) DECLSPEC_HIDDEN; extern void CDECL server_release_fd( HANDLE handle, int unix_fd ) DECLSPEC_HIDDEN; extern int CDECL server_pipe( int fd[2] ) DECLSPEC_HIDDEN; -extern void CDECL server_init_process(void) DECLSPEC_HIDDEN; extern void CDECL server_init_process_done(void) DECLSPEC_HIDDEN; -extern size_t CDECL server_init_thread( void *entry_point, BOOL *suspend, unsigned int *cpus, - BOOL *wow64, timeout_t *start_time ) DECLSPEC_HIDDEN; -extern void CDECL init_threading( int *nb_threads, struct ldt_copy **ldt_copy ) DECLSPEC_HIDDEN; +extern TEB * CDECL init_threading( int *nb_threads_ptr, struct ldt_copy **ldt_copy, SIZE_T *size, + BOOL *suspend, unsigned int *cpus, BOOL *wow64, + timeout_t *start_time ) DECLSPEC_HIDDEN; extern NTSTATUS CDECL create_thread( SIZE_T stack_reserve, SIZE_T stack_commit, HANDLE actctx, DWORD tid, int request_fd, PRTL_THREAD_START_ROUTINE start, void *param, void *relay ) DECLSPEC_HIDDEN; @@ -116,7 +110,9 @@ extern NTSTATUS CDECL get_thread_ldt_entry( HANDLE handle, void *data, ULONG len extern const char *data_dir DECLSPEC_HIDDEN; extern const char *build_dir DECLSPEC_HIDDEN; extern const char *config_dir DECLSPEC_HIDDEN; +extern unsigned int server_cpus DECLSPEC_HIDDEN; extern BOOL is_wow64 DECLSPEC_HIDDEN; +extern timeout_t server_start_time DECLSPEC_HIDDEN; extern sigset_t server_block_set DECLSPEC_HIDDEN; extern SIZE_T signal_stack_size DECLSPEC_HIDDEN; extern SIZE_T signal_stack_mask DECLSPEC_HIDDEN; @@ -125,6 +121,8 @@ extern unsigned int server_call_unlocked( void *req_ptr ) DECLSPEC_HIDDEN; extern void server_enter_uninterrupted_section( RTL_CRITICAL_SECTION *cs, sigset_t *sigset ) DECLSPEC_HIDDEN; extern void server_leave_uninterrupted_section( RTL_CRITICAL_SECTION *cs, sigset_t *sigset ) DECLSPEC_HIDDEN; extern void start_server( BOOL debug ) DECLSPEC_HIDDEN; +extern void server_init_process(void) DECLSPEC_HIDDEN; +extern size_t server_init_thread( void *entry_point, BOOL *suspend ) 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; @@ -132,6 +130,8 @@ extern void wait_suspend( CONTEXT *context ) DECLSPEC_HIDDEN; extern NTSTATUS set_thread_context( HANDLE handle, const context_t *context, BOOL *self ) DECLSPEC_HIDDEN; extern NTSTATUS get_thread_context( HANDLE handle, context_t *context, unsigned int flags, BOOL *self ) DECLSPEC_HIDDEN; +extern void virtual_init(void) DECLSPEC_HIDDEN; +extern TEB *virtual_alloc_first_teb(void) DECLSPEC_HIDDEN; extern NTSTATUS virtual_alloc_teb( TEB **ret_teb ) DECLSPEC_HIDDEN; extern void virtual_free_teb( TEB *teb ) DECLSPEC_HIDDEN; @@ -143,4 +143,6 @@ extern void DECLSPEC_NORETURN signal_start_thread( PRTL_THREAD_START_ROUTINE ent BOOL suspend, void *relay, TEB *teb ) DECLSPEC_HIDDEN; extern void DECLSPEC_NORETURN signal_exit_thread( int status, void (*func)(int) ) DECLSPEC_HIDDEN; +extern void dbg_init(void) DECLSPEC_HIDDEN; + #endif /* __NTDLL_UNIX_PRIVATE_H */ diff --git a/dlls/ntdll/unix/virtual.c b/dlls/ntdll/unix/virtual.c index 58ecaa6fc4d..d768f32f121 100644 --- a/dlls/ntdll/unix/virtual.c +++ b/dlls/ntdll/unix/virtual.c @@ -2539,7 +2539,7 @@ NTSTATUS CDECL virtual_create_builtin_view( void *module ) /*********************************************************************** * virtual_alloc_first_teb */ -TEB * CDECL virtual_alloc_first_teb(void) +TEB *virtual_alloc_first_teb(void) { TEB *teb; PEB *peb; @@ -2561,9 +2561,6 @@ TEB * CDECL virtual_alloc_first_teb(void) teb->Tib.StackBase = (void *)~0ul; teb->StaticUnicodeString.Buffer = teb->StaticUnicodeBuffer; teb->StaticUnicodeString.MaximumLength = sizeof(teb->StaticUnicodeBuffer); - signal_init_threading(); - signal_alloc_thread( teb ); - signal_init_thread( teb ); use_locks = TRUE; return teb; } diff --git a/dlls/ntdll/unixlib.h b/dlls/ntdll/unixlib.h index 67c63fd9268..b456139adfc 100644 --- a/dlls/ntdll/unixlib.h +++ b/dlls/ntdll/unixlib.h @@ -28,7 +28,7 @@ struct ldt_copy; struct msghdr; /* increment this when you change the function table */ -#define NTDLL_UNIXLIB_VERSION 19 +#define NTDLL_UNIXLIB_VERSION 20 struct unix_funcs { @@ -91,7 +91,6 @@ struct unix_funcs ULONG protect, pe_image_info_t *image_info ); void (CDECL *virtual_get_system_info)( SYSTEM_BASIC_INFORMATION *info ); NTSTATUS (CDECL *virtual_create_builtin_view)( void *module ); - TEB * (CDECL *virtual_alloc_first_teb)(void); NTSTATUS (CDECL *virtual_alloc_thread_stack)( INITIAL_TEB *stack, SIZE_T reserve_size, SIZE_T commit_size, SIZE_T *pthread_size ); NTSTATUS (CDECL *virtual_handle_fault)( LPCVOID addr, DWORD err, BOOL on_signal_stack ); unsigned int (CDECL *virtual_locked_server_call)( void *req_ptr ); @@ -109,7 +108,8 @@ struct unix_funcs void (CDECL *virtual_set_large_address_space)(void); /* thread/process functions */ - void (CDECL *init_threading)( int *nb_threads, struct ldt_copy **ldt_copy ); + TEB * (CDECL *init_threading)( int *nb_threads_ptr, struct ldt_copy **ldt_copy, SIZE_T *size, + BOOL *suspend, unsigned int *cpus, BOOL *wow64, timeout_t *start_time ); NTSTATUS (CDECL *create_thread)( SIZE_T stack_reserve, SIZE_T stack_commit, HANDLE actctx, DWORD tid, int request_fd, PRTL_THREAD_START_ROUTINE start, void *param, void *relay ); @@ -136,13 +136,9 @@ struct unix_funcs unsigned int *options ); void (CDECL *server_release_fd)( HANDLE handle, int unix_fd ); int (CDECL *server_pipe)( int fd[2] ); - void (CDECL *server_init_process)(void); void (CDECL *server_init_process_done)(void); - size_t (CDECL *server_init_thread)( void *entry_point, BOOL *suspend, unsigned int *cpus, - BOOL *wow64, timeout_t *start_time ); /* debugging functions */ - void (CDECL *dbg_init)(void); unsigned char (CDECL *dbg_get_channel_flags)( struct __wine_debug_channel *channel ); const char * (CDECL *dbg_strdup)( const char *str ); int (CDECL *dbg_output)( const char *str );