this repo has no description
1
fork

Configure Feed

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

Support debugging of dyld's early initialization

+46 -36
+2
src/dyld/src/dyldAPIs.cpp
··· 85 85 86 86 #ifdef DARLING 87 87 extern "C" int mach_driver_get_fd(void); 88 + extern "C" bool darling_am_i_ptraced(void); 88 89 #endif 89 90 90 91 // In 10.3.x and earlier all the NSObjectFileImage API's were implemeneted in libSystem.dylib ··· 214 215 #endif 215 216 #ifdef DARLING 216 217 {"__dyld_get_mach_driver_fd", (void*)mach_driver_get_fd }, 218 + {"__dyld_am_i_ptraced", (void*)darling_am_i_ptraced }, 217 219 #endif 218 220 #endif //DEPRECATED_APIS_SUPPORTED 219 221
+5
src/dyld/src/dyldInitialization.cpp
··· 197 197 198 198 extern "C" void mach_init(const char* apple[]); 199 199 extern "C" void __guard_setup(const char* apple[]); 200 + extern "C" void sigexc_setup(); 200 201 201 202 202 203 // ··· 230 231 #if DYLD_INITIALIZER_SUPPORT 231 232 // run all C++ initializers inside dyld 232 233 runDyldInitializers(dyldsMachHeader, slide, argc, argv, envp, apple); 234 + #endif 235 + 236 + #ifdef DARLING 237 + sigexc_setup(); 233 238 #endif 234 239 235 240 // now that we are done bootstrapping dyld, call dyld's main
+3 -4
src/kernel/emulation/linux/mach/lkm.c
··· 7 7 #include <unistd.h> 8 8 #include <sys/resource.h> 9 9 #include "../../libsyscall/wrappers/_libkernel_init.h" 10 + #include "../simple.h" 11 + #include "../misc/ioctl.h" 10 12 11 - extern int __real_ioctl(int fd, int cmd, void* arg); 12 13 extern int sys_open(const char*, int, int); 13 14 extern int sys_close(int); 14 15 extern int sys_write(int, const void*, int); ··· 18 19 extern int sys_fcntl(int, int, int); 19 20 extern _libkernel_functions_t _libkernel_functions; 20 21 21 - extern void sigexc_setup1(void); 22 - extern void sigexc_setup2(void); 23 22 24 23 static int driver_fd = -1; 25 24 ··· 41 40 #else 42 41 // Ask for fd already set up by dyld 43 42 int (*p)(void); 44 - _libkernel_functions->dyld_func_lookup("__dyld_get_mach_driver_fd", &p); 43 + _libkernel_functions->dyld_func_lookup("__dyld_get_mach_driver_fd", (void**) &p); 45 44 46 45 driver_fd = (*p)(); 47 46 #endif
+35 -28
src/kernel/emulation/linux/signal/sigexc.c
··· 10 10 #include "sigaltstack.h" 11 11 #include "../mach/lkm.h" 12 12 #include "../../../../lkm/api.h" 13 + #include "../../../libsyscall/wrappers/_libkernel_init.h" 13 14 #include "kill.h" 14 - #include <emmintrin.h> 15 + #include "../simple.h" 15 16 16 17 // Support for Darwin debugging. 17 18 // Unlike other Unix-like systems, macOS doesn't use wait() to handle events in the debugged process. ··· 21 22 static void handle_rt_signal(int signum); 22 23 extern void sig_restorer(void); 23 24 extern int getpid(void); 25 + 26 + extern _libkernel_functions_t _libkernel_functions; 24 27 25 28 void darling_sigexc_uninstall(void); 26 29 void sigrt_handler(int signum, struct linux_siginfo* info, void* ctxt); ··· 43 46 44 47 #define kern_printf(...) { char buf[128]; __simple_sprintf(buf, __VA_ARGS__); lkm_call(0x1028, buf); } 45 48 46 - char xyzbuf[128]; 47 49 void sigexc_setup1(void) 48 50 { 49 - lkm_call(0x1028, "sigexc_setup1()"); 51 + kern_printf("sigexc_setup1()"); 50 52 // Setup handler for SIGNAL_SIGEXC_TOGGLE and SIGNAL_SIGEXC_THUPDATE 51 53 handle_rt_signal(SIGNAL_SIGEXC_TOGGLE); 52 54 handle_rt_signal(SIGNAL_SIGEXC_THUPDATE); ··· 54 56 55 57 void sigexc_setup2(void) 56 58 { 57 - lkm_call(0x1028, xyzbuf); 58 - lkm_call(0x1028, "sigexc_setup2()\n"); 59 + kern_printf("sigexc_setup2()\n"); 59 60 60 61 linux_sigset_t set; 61 62 set = (1ull << (SIGNAL_SIGEXC_TOGGLE-1)); ··· 69 70 // the debugger to handle this situation. 70 71 if (!am_i_ptraced && lkm_call(NR_get_tracer, NULL) != 0) 71 72 { 72 - // __simple_printf("the predecessor is traced\n"); 73 + kern_printf("sigexc: the parent is traced\n"); 73 74 darling_sigexc_self(); 74 75 sigexc_handler(LINUX_SIGTRAP, NULL, NULL); 75 76 } ··· 77 78 78 79 void sigexc_setup(void) 79 80 { 81 + #ifdef VARIANT_DYLD 80 82 sigexc_setup1(); 81 83 if (lkm_call(NR_started_suspended, 0)) 82 84 { 85 + kern_printf("sigexc: waiting for signal\n"); 86 + 83 87 // sigsuspend until resumed or debugger attached 84 88 linux_sigset_t set = -1ll; 85 89 set &= ~(1ull << (LINUX_SIGCONT-1)); ··· 87 91 set &= ~(1ull << (SIGNAL_SIGEXC_THUPDATE-1)); 88 92 89 93 LINUX_SYSCALL(__NR_rt_sigsuspend, &set, 8); 94 + 95 + kern_printf("sigexc: done waiting for signal\n"); 90 96 } 91 97 sigexc_setup2(); 98 + #else 99 + sigexc_setup1(); 100 + 101 + // get am_i_ptraced value from dyld 102 + bool (*is_traced)(void); 103 + _libkernel_functions->dyld_func_lookup("__dyld_am_i_ptraced", (void**) &is_traced); 104 + am_i_ptraced = is_traced(); 105 + 106 + if (am_i_ptraced) 107 + { 108 + // We have to take over from dyld's build of this file, because 109 + // we rely on having accurate signal handler information of the running application. 110 + kern_printf("sigexc: taking over sigexc handling\n"); 111 + darling_sigexc_self(); 112 + } 113 + #endif 92 114 } 93 115 94 116 static void handle_rt_signal(int signum) ··· 106 128 sizeof(sa.sa_mask)); 107 129 108 130 //char buf[128]; 109 - __simple_sprintf(xyzbuf, "Setting handler for RT signal %d: %d", signum, rv); 131 + //__simple_sprintf(xyzbuf, "Setting handler for RT signal %d: %d", signum, rv); 110 132 //lkm_call(0x1028, buf); 111 133 } 112 134 ··· 117 139 118 140 void sigrt_handler(int signum, struct linux_siginfo* info, void* ctxt) 119 141 { 120 - char buf[128]; 121 - __simple_sprintf(buf, "sigrt_handler signum=%d, si_value=%x\n", signum, info->si_value); 122 - lkm_call(0x1028, buf); 142 + kern_printf("sigexc: sigrt_handler signum=%d, si_value=%x\n", signum, info->si_value); 143 + 123 144 if (signum == SIGNAL_SIGEXC_TOGGLE) 124 145 { 125 146 if (((uint32_t) info->si_value) == SIGRT_MAGIC_ENABLE_SIGEXC) ··· 261 282 262 283 void sigexc_handler(int linux_signum, struct linux_siginfo* info, struct linux_ucontext* ctxt) 263 284 { 264 - char buf[128]; 265 - __simple_sprintf(buf, "sigexc_handler(%d, %p, %p)\n", linux_signum, info, ctxt); 266 - lkm_call(0x1028, buf); 285 + kern_printf("sigexc_handler(%d, %p, %p)\n", linux_signum, info, ctxt); 267 286 268 287 if (!darling_am_i_ptraced()) 269 288 { 270 - __simple_printf("NOT TRACED!\n"); 289 + kern_printf("sigexc: NOT TRACED!\n"); 271 290 return; 272 291 } 273 292 ··· 285 304 int bsd_signum = signum_linux_to_bsd(linux_signum); 286 305 if (bsd_signum <= 0) 287 306 { 288 - __simple_printf("Unmapped signal!\n"); 307 + kern_printf("sigexc: Unmapped signal!\n"); 289 308 return; 290 309 } 291 310 ··· 328 347 if (lkm_call(NR_last_triggered_watchpoint, &args) == 0) 329 348 { 330 349 codes[1] = args.address; 331 - codes[2] = args.flags; 350 + // codes[2] = args.flags; 332 351 } 333 352 } 334 353 break; ··· 420 439 421 440 thread_state_to_mcontext(&tstate, &ctxt->uc_mcontext.gregs); 422 441 float_state_to_mcontext(&fstate, ctxt->uc_mcontext.fpregs); 423 - 424 - /* 425 - if (bsd_signum == SIGTRAP) 426 - { 427 - uint8_t* rip = (uint8_t*) ctxt->uc_mcontext.gregs.rip; 428 - kern_printf("rip at resume: %p\n", rip); 429 - kern_printf("Value at rip on resume: 0x%x\n", *rip); 430 - _mm_clflush(rip); 431 - } 432 - */ 433 - kern_printf("sigexc: test test\n"); 434 - kern_printf("sigexc: EFL at leave: 0x%x\n", ctxt->uc_mcontext.gregs.efl); 435 442 436 443 #elif defined(__i386__) 437 444 mach_msg_type_number_t count;
+1 -4
src/kernel/emulation/linux/signal/sigexc.h
··· 14 14 #define SIGRT_MAGIC_ENABLE_SIGEXC 0xdebdeb01 15 15 #define SIGRT_MAGIC_DISABLE_SIGEXC 0xdebdeb00 16 16 17 - // Initializes this module (before opening LKM) 18 - void sigexc_setup1(void); 19 - // Finish initialization (after opening LKM) 20 - void sigexc_setup2(void); 17 + void sigexc_setup(void); 21 18 22 19 // Is this process currently traced by a debugger? 23 20 bool darling_am_i_ptraced(void);