this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Pass direct implementations as callbacks to thread creation elfcall

This fixes an issue when using xtrace that would cause a segfault due to xtrace's hooks being called from the thread currently being created.

+10 -11
+4 -7
src/kernel/emulation/linux/bsdthread/bsdthread_create.c
··· 10 10 #include "../mman/mman.h" 11 11 #include "../simple.h" 12 12 #include "../elfcalls_wrapper.h" 13 + #include "../machdep/tls.h" 14 + #include "../mach/mach_traps.h" 13 15 14 16 extern void *memset(void *s, int c, size_t n); 15 17 ··· 45 47 ret = darling_thread_create((void**) stack, pthread_entry_point_wrapper, thread_start, 46 48 arg, stacksize, flags); 47 49 #else 48 - // Implemented in libdyld 49 - extern int thread_self_trap(void); 50 - // give it the exernal definition rather than `sys_thread_set_tsd_base` directly 51 - extern void _thread_set_tsd_base(void *tsd_base); 52 - 53 50 struct darling_thread_create_callbacks callbacks = { 54 - .thread_self_trap = &thread_self_trap, 55 - .thread_set_tsd_base = &_thread_set_tsd_base, 51 + .thread_self_trap = &thread_self_trap_impl, 52 + .thread_set_tsd_base = &sys_thread_set_tsd_base, 56 53 }; 57 54 58 55 return __darling_thread_create(((uintptr_t)stack), pthread_obj_size,
+4 -2
src/kernel/emulation/linux/bsdthread/workq_kernreturn.c
··· 12 12 #include <sys/queue.h> 13 13 #include <os/lock.h> 14 14 #include <elfcalls/threads.h> 15 + #include "../machdep/tls.h" 16 + #include "../mach/mach_traps.h" 15 17 16 18 #define __PTHREAD_EXPOSE_INTERNALS__ 1 17 19 #include <pthread/priority_private.h> ··· 282 284 wq_event_pending = wq_event; 283 285 284 286 struct darling_thread_create_callbacks callbacks = { 285 - .thread_self_trap = &thread_self_trap, 286 - .thread_set_tsd_base = &_thread_set_tsd_base, 287 + .thread_self_trap = &thread_self_trap_impl, 288 + .thread_set_tsd_base = &sys_thread_set_tsd_base, 287 289 }; 288 290 289 291 __darling_thread_create(512*1024, pthread_obj_size, wqueue_entry_point_wrapper, 0,
+1 -1
src/libelfloader/native/elfcalls.h
··· 5 5 6 6 struct darling_thread_create_callbacks { 7 7 int (*thread_self_trap)(void); 8 - void (*thread_set_tsd_base)(void*); 8 + void (*thread_set_tsd_base)(void*, int); 9 9 }; 10 10 11 11 typedef struct darling_thread_create_callbacks* darling_thread_create_callbacks_t;
+1 -1
src/libelfloader/native/threads.c
··· 200 200 201 201 // libpthread now expects the kernel to set the TSD 202 202 // so, since we're pretending to be the kernel handling threads... 203 - args.callbacks->thread_set_tsd_base(&dthread->tsd[0]); 203 + args.callbacks->thread_set_tsd_base(&dthread->tsd[0], 0); 204 204 *flags |= args.is_workqueue ? DWQ_FLAG_THREAD_TSD_BASE_SET : DTHREAD_START_TSD_BASE_SET; 205 205 206 206 args.port = dthread->tsd[DTHREAD_TSD_SLOT_MACH_THREAD_SELF] = args.callbacks->thread_self_trap();