From: Brendan Shanks <bshanks@codeweavers.com> Based on patches from Rémi Bernon and Alexandre Julliard. --- dlls/ntdll/unix/server.c | 6 +++++- dlls/ntdll/unix/thread.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/dlls/ntdll/unix/server.c b/dlls/ntdll/unix/server.c index 1629ee63e63..06eb740914f 100644 --- a/dlls/ntdll/unix/server.c +++ b/dlls/ntdll/unix/server.c @@ -1474,6 +1474,8 @@ static int server_connect(void) #include <mach/mach_error.h> #include <servers/bootstrap.h> +extern NTSTATUS apple_spawn_main_thread(void); + /* send our task port to the server */ static void send_server_task_port(void) { @@ -1754,6 +1756,8 @@ void server_init_process_done(void) #ifdef __APPLE__ send_server_task_port(); + if ((status = apple_spawn_main_thread())) + ERR("Failed to spawn main thread, status %x\n", status); #endif /* Install signal handlers; this cannot be done earlier, since we cannot @@ -1809,7 +1813,7 @@ void server_init_thread( struct thread_data *data ) init_teb_data( data ); signal_start_thread( data->start, data->param, data->teb ); } - else + else if (data->start) { void (*entry)(void *) = data->start; entry( data->param ); diff --git a/dlls/ntdll/unix/thread.c b/dlls/ntdll/unix/thread.c index 55e52af402a..c6b99b747f8 100644 --- a/dlls/ntdll/unix/thread.c +++ b/dlls/ntdll/unix/thread.c @@ -63,6 +63,7 @@ #endif #ifdef __APPLE__ +#include <CoreFoundation/CoreFoundation.h> #include <mach/mach.h> #endif #ifdef __FreeBSD__ @@ -1581,6 +1582,34 @@ void wait_suspend( CONTEXT *context ) } +#ifdef __APPLE__ +/********************************************************************** + * apple_spawn_main_thread + */ +NTSTATUS apple_spawn_main_thread( void ) +{ + struct thread_data *data; + HANDLE handle; + NTSTATUS status; + ULONG flags = THREAD_CREATE_FLAGS_BYPASS_PROCESS_FREEZE; + CFRunLoopSourceContext context = { .perform = (void (*)(void *))server_init_thread }; + CFRunLoopSourceRef source; + + if ((status = create_server_thread( &handle, &data, THREAD_ALL_ACCESS, NULL, NULL, NULL, flags, TRUE ))) + return status; + NtClose( handle ); + + context.info = data; + source = CFRunLoopSourceCreate( NULL, 0, &context ); + CFRunLoopAddSource( CFRunLoopGetMain(), source, kCFRunLoopCommonModes ); + CFRunLoopSourceSignal( source ); + CFRunLoopWakeUp( CFRunLoopGetMain() ); + CFRelease( source ); + return STATUS_SUCCESS; +} +#endif + + /********************************************************************** * send_debug_event * -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/9579