this repo has no description
1
fork

Configure Feed

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

Work on debugging support

+147 -134
+146 -133
src/kernel/emulation/linux/signal/sigexc.c
··· 50 50 // the debugger to handle this situation. 51 51 if (lkm_call(NR_get_tracer, NULL) != 0) 52 52 { 53 + __simple_printf("the predecessor is traced\n"); 53 54 darling_sigexc_self(); 54 55 sys_kill(getpid(), SIGTRAP, 1); 55 56 } ··· 75 76 76 77 void sigrt_handler(int signum, struct linux_siginfo* info, void* ctxt) 77 78 { 79 + __simple_printf("sigrt_handler signum=%d\n", signum); 78 80 if (signum == SIGNAL_SIGEXC_TOGGLE) 79 81 { 80 82 if (info->si_value == SIGRT_MAGIC_ENABLE_SIGEXC) 81 83 { 82 - am_i_ptraced = true; 83 84 darling_sigexc_self(); 84 85 85 86 // Stop on attach ··· 87 88 } 88 89 else if (info->si_value == SIGRT_MAGIC_DISABLE_SIGEXC) 89 90 { 90 - am_i_ptraced = false; 91 91 darling_sigexc_uninstall(); 92 92 } 93 93 } ··· 118 118 119 119 void darling_sigexc_self(void) 120 120 { 121 + am_i_ptraced = true; 122 + 123 + __simple_printf("darling_sigexc_self()\n"); 121 124 // Make sigexc_handler the handler for all signals in the process 122 125 for (int i = 1; i <= 31; i++) 123 126 { 124 127 struct linux_sigaction sa; 125 - sa.sa_sigaction = sigrt_handler; 128 + sa.sa_sigaction = sigexc_handler; 126 129 sa.sa_mask = 0xffffffff; // all other standard Unix signals should be blocked while the handler is run 127 130 sa.sa_flags = LINUX_SA_RESTORER | LINUX_SA_SIGINFO | LINUX_SA_RESTART | LINUX_SA_ONSTACK; 128 131 sa.sa_restorer = sig_restorer; ··· 141 144 } 142 145 void darling_sigexc_uninstall(void) 143 146 { 147 + am_i_ptraced = false; 148 + 149 + __simple_printf("darling_sigexc_uninstall()\n"); 144 150 for (int i = 1; i <= 31; i++) 145 151 { 146 152 struct linux_sigaction sa; ··· 184 190 185 191 void sigexc_handler(int linux_signum, struct linux_siginfo* info, struct linux_ucontext* ctxt) 186 192 { 193 + __simple_printf("sigexc_handler(%d)\n", linux_signum); 187 194 if (!darling_am_i_ptraced()) 195 + { 196 + __simple_printf("NOT TRACED!\n"); 188 197 return; 198 + } 189 199 190 200 if (linux_signum == LINUX_SIGCONT) 191 201 return; ··· 200 210 201 211 int bsd_signum = signum_linux_to_bsd(linux_signum); 202 212 if (bsd_signum <= 0) 213 + { 214 + __simple_printf("Unmapped signal!\n"); 203 215 return; 216 + } 204 217 205 218 // SIGSEGV + SIGBUS -> EXC_BAD_ACCESS 206 219 // SIGTRAP -> EXC_BREAKPOINT ··· 246 259 mcontext_to_thread_state(&ctxt->uc_mcontext.gregs, &tstate); 247 260 mcontext_to_float_state(ctxt->uc_mcontext.fpregs, &fstate); 248 261 249 - thread_set_state(thread, x86_THREAD_STATE64, &tstate, x86_THREAD_STATE64_COUNT); 250 - thread_set_state(thread, x86_FLOAT_STATE64, &fstate, x86_THREAD_FLOAT64_COUNT); 262 + thread_set_state(thread, x86_THREAD_STATE64, (thread_state_t) &tstate, x86_THREAD_STATE64_COUNT); 263 + thread_set_state(thread, x86_FLOAT_STATE64, (thread_state_t) &fstate, x86_FLOAT_STATE64_COUNT); 251 264 #elif defined(__i386__) 252 265 x86_thread_state32_t tstate; 253 266 x86_float_state32_t fstate; ··· 255 268 mcontext_to_thread_state(&ctxt->uc_mcontext.gregs, &tstate); 256 269 mcontext_to_float_state(ctxt->uc_mcontext.fpregs, &fstate); 257 270 258 - thread_set_state(thread, x86_THREAD_STATE32, &tstate, x86_THREAD_STATE32_COUNT); 259 - thread_set_state(thread, x86_FLOAT_STATE32, &fstate, x86_THREAD_FLOAT32_COUNT); 271 + thread_set_state(thread, x86_THREAD_STATE32, (thread_state_t) &tstate, x86_THREAD_STATE32_COUNT); 272 + thread_set_state(thread, x86_FLOAT_STATE32, (thread_state_t) &fstate, x86_FLOAT_STATE32_COUNT); 260 273 #endif 261 274 275 + __simple_printf("Passing Mach exception to port %d\n", port); 262 276 if (port != 0) 263 277 { 264 278 _pthread_setspecific_direct(SIGEXC_TSD_KEY, bsd_signum); ··· 273 287 mach_msg_type_number_t count; 274 288 275 289 count = x86_THREAD_STATE64_COUNT; 276 - thread_get_state(thread, x86_THREAD_STATE64, &tstate, &count); 277 - count = x86_THREAD_FLOAT64_COUNT; 278 - thread_get_state(thread, x86_FLOAT_STATE64, &fstate, &count); 290 + thread_get_state(thread, x86_THREAD_STATE64, (thread_state_t) &tstate, &count); 291 + count = x86_FLOAT_STATE64_COUNT; 292 + thread_get_state(thread, x86_FLOAT_STATE64, (thread_state_t) &fstate, &count); 279 293 280 294 thread_state_to_mcontext(&tstate, &ctxt->uc_mcontext.gregs); 281 295 float_state_to_mcontext(&fstate, ctxt->uc_mcontext.fpregs); ··· 283 297 mach_msg_type_number_t count; 284 298 285 299 count = x86_THREAD_STATE32_COUNT; 286 - thread_get_state(thread, x86_THREAD_STATE32, &tstate, &count); 287 - count = x86_THREAD_FLOAT32_COUNT; 288 - thread_get_state(thread, x86_FLOAT_STATE32, &fstate, &count); 300 + thread_get_state(thread, x86_THREAD_STATE32, (thread_state_t) &tstate, &count); 301 + count = x86_FLOAT_STATE32_COUNT; 302 + thread_get_state(thread, x86_FLOAT_STATE32, (thread_state_t) &fstate, &count); 289 303 290 304 thread_state_to_mcontext(&tstate, &ctxt->uc_mcontext.gregs); 291 305 float_state_to_mcontext(&fstate, ctxt->uc_mcontext.fpregs); ··· 329 343 #if defined(__x86_64__) 330 344 void mcontext_to_thread_state(const struct linux_gregset* regs, x86_thread_state64_t* s) 331 345 { 332 - s->rax = regs->rax; 333 - s->rbx = regs->rbx; 334 - s->rcx = regs->rcx; 335 - s->rdx = regs->rdx; 336 - s->rdi = regs->rdi; 337 - s->rsi = regs->rsi; 338 - s->rbp = regs->rbp; 339 - s->rsp = regs->rsp; 340 - s->r8 = regs->r8; 341 - s->r9 = regs->r9; 342 - s->r10 = regs->r10; 343 - s->r11 = regs->r11; 344 - s->r12 = regs->r12; 345 - s->r13 = regs->r13; 346 - s->r14 = regs->r14; 347 - s->r15 = regs->r15; 348 - s->rip = regs->rip; 349 - s->rflags = regs->efl; 350 - s->cs = regs->cs; 351 - s->fs = regs->fs; 352 - s->gs = regs->gs; 346 + s->__rax = regs->rax; 347 + s->__rbx = regs->rbx; 348 + s->__rcx = regs->rcx; 349 + s->__rdx = regs->rdx; 350 + s->__rdi = regs->rdi; 351 + s->__rsi = regs->rsi; 352 + s->__rbp = regs->rbp; 353 + s->__rsp = regs->rsp; 354 + s->__r8 = regs->r8; 355 + s->__r9 = regs->r9; 356 + s->__r10 = regs->r10; 357 + s->__r11 = regs->r11; 358 + s->__r12 = regs->r12; 359 + s->__r13 = regs->r13; 360 + s->__r14 = regs->r14; 361 + s->__r15 = regs->r15; 362 + s->__rip = regs->rip; 363 + s->__rflags = regs->efl; 364 + s->__cs = regs->cs; 365 + s->__fs = regs->fs; 366 + s->__gs = regs->gs; 353 367 } 354 368 355 369 void mcontext_to_float_state(const linux_fpregset_t fx, x86_float_state64_t* s) 356 370 { 357 - *((uint32_t*)&s->fpu_fcw) = fx->cwd; 358 - *((uint32_t*)&s->fpu_fsw) = fx->swd; 359 - s->fpu_ftw = fx->ftw; 360 - s->fpu_fop = fx->fop; 361 - s->fpu_ip = fx->rip; 362 - s->fpu_cs = 0; 363 - s->fpu_dp = fx->rdp; 364 - s->fpu_ds = 0; 365 - s->fpu_mxcsr = fx->mxcsr; 366 - s->fpu_mxcsrmask = fx->mxcsr_mask; 371 + *((uint32_t*)&s->__fpu_fcw) = fx->cwd; 372 + *((uint32_t*)&s->__fpu_fsw) = fx->swd; 373 + s->__fpu_ftw = fx->ftw; 374 + s->__fpu_fop = fx->fop; 375 + s->__fpu_ip = fx->rip; 376 + s->__fpu_cs = 0; 377 + s->__fpu_dp = fx->rdp; 378 + s->__fpu_ds = 0; 379 + s->__fpu_mxcsr = fx->mxcsr; 380 + s->__fpu_mxcsrmask = fx->mxcr_mask; 367 381 368 - memcpy(&s->fpu_stmm0, fx->_st, 128); 369 - memcpy(&s->fpu_xmm0, fx->_xmm, 256); 382 + memcpy(&s->__fpu_stmm0, fx->_st, 128); 383 + memcpy(&s->__fpu_xmm0, fx->_xmm, 256); 370 384 } 371 385 372 386 void thread_state_to_mcontext(const x86_thread_state64_t* s, struct linux_gregset* regs) 373 387 { 374 - regs->rax = s->rax; 375 - regs->rbx = s->rbx; 376 - regs->rcx = s->rcx; 377 - regs->rdx = s->rdx; 378 - regs->rdi = s->rdi; 379 - regs->rsi = s->rsi; 380 - regs->rbp = s->rbp; 381 - regs->rsp = s->rsp; 382 - regs->r8 = s->r8; 383 - regs->r9 = s->r9; 384 - regs->r10 = s->r10; 385 - regs->r11 = s->r11; 386 - regs->r12 = s->r12; 387 - regs->r13 = s->r13; 388 - regs->r14 = s->r14; 389 - regs->r15 = s->r15; 390 - regs->rip = s->rip; 391 - regs->efl = s->rflags; 392 - regs->cs = s->cs; 393 - regs->fs = s->fs; 394 - regs->gs = s->gs; 388 + regs->rax = s->__rax; 389 + regs->rbx = s->__rbx; 390 + regs->rcx = s->__rcx; 391 + regs->rdx = s->__rdx; 392 + regs->rdi = s->__rdi; 393 + regs->rsi = s->__rsi; 394 + regs->rbp = s->__rbp; 395 + regs->rsp = s->__rsp; 396 + regs->r8 = s->__r8; 397 + regs->r9 = s->__r9; 398 + regs->r10 = s->__r10; 399 + regs->r11 = s->__r11; 400 + regs->r12 = s->__r12; 401 + regs->r13 = s->__r13; 402 + regs->r14 = s->__r14; 403 + regs->r15 = s->__r15; 404 + regs->rip = s->__rip; 405 + regs->efl = s->__rflags; 406 + regs->cs = s->__cs; 407 + regs->fs = s->__fs; 408 + regs->gs = s->__gs; 395 409 } 396 410 397 411 void float_state_to_mcontext(const x86_float_state64_t* s, linux_fpregset_t fx) 398 412 { 399 - fx->cwd = *((uint32_t*)&s->fpu_fcw); 400 - fx->swd = *((uint32_t*)&s->fpu_fsw); 401 - fx->ftw = s->fpu_ftw; 402 - fx->fop = s->fpu_fop; 403 - fx->rip = s->fpu_ip; 404 - fx->rdp = s->fpu_dp; 405 - fx->mxcsr = s->fpu_mxcsr; 406 - fx->mxcsr_mask = s->fpu_mxcsrmask; 413 + fx->cwd = *((uint32_t*)&s->__fpu_fcw); 414 + fx->swd = *((uint32_t*)&s->__fpu_fsw); 415 + fx->ftw = s->__fpu_ftw; 416 + fx->fop = s->__fpu_fop; 417 + fx->rip = s->__fpu_ip; 418 + fx->rdp = s->__fpu_dp; 419 + fx->mxcsr = s->__fpu_mxcsr; 420 + fx->mxcr_mask = s->__fpu_mxcsrmask; 407 421 408 - memcpy(fx->_st, &s->fpu_stmm0, 128); 409 - memcpy(fx->_xmm, &s->fpu_xmm0, 256); 422 + memcpy(fx->_st, &s->__fpu_stmm0, 128); 423 + memcpy(fx->_xmm, &s->__fpu_xmm0, 256); 410 424 } 411 425 412 426 #elif defined(__i386__) 413 427 void mcontext_to_thread_state(const struct linux_gregset* regs, x86_thread_state32_t* s) 414 428 { 415 - s->eax = regs->eax; 416 - s->ebx = regs->ebx; 417 - s->ecx = regs->ecx; 418 - s->edx = regs->edx; 419 - s->edi = regs->edi; 420 - s->esi = regs->esi; 421 - s->ebp = regs->ebp; 422 - s->esp = regs->esp; 423 - s->ss = regs->ss; 424 - s->eflags = regs->efl; 425 - s->eip = regs->eip; 426 - s->cs = regs->cs; 427 - s->ds = regs->ds; 428 - s->es = regs->es; 429 - s->fs = regs->fs; 430 - s->gs = regs->gs; 429 + s->__eax = regs->eax; 430 + s->__ebx = regs->ebx; 431 + s->__ecx = regs->ecx; 432 + s->__edx = regs->edx; 433 + s->__edi = regs->edi; 434 + s->__esi = regs->esi; 435 + s->__ebp = regs->ebp; 436 + s->__esp = regs->esp; 437 + s->__ss = regs->ss; 438 + s->__eflags = regs->efl; 439 + s->__eip = regs->eip; 440 + s->__cs = regs->cs; 441 + s->__ds = regs->ds; 442 + s->__es = regs->es; 443 + s->__fs = regs->fs; 444 + s->__gs = regs->gs; 431 445 } 432 446 433 447 void mcontext_to_float_state(const linux_fpregset_t fx, x86_float_state32_t* s) 434 448 { 435 - *((uint32_t*)&s->fpu_fcw) = fx->cw; 436 - *((uint32_t*)&s->fpu_fsw) = fx->sw; 437 - s->fpu_ftw = fx->tag; 438 - s->fpu_fop = 0; 439 - s->fpu_ip = fx->ipoff; 440 - s->fpu_cs = fx->cssel; 441 - s->fpu_dp = fx->dataoff; 442 - s->fpu_ds = fx->datasel; 443 - s->fpu_mxcsr = fx->mxcsr; 444 - s->fpu_mxcsrmask = fx->mxcsr_mask; 449 + *((uint32_t*)&s->__fpu_fcw) = fx->cw; 450 + *((uint32_t*)&s->__fpu_fsw) = fx->sw; 451 + s->__fpu_ftw = fx->tag; 452 + s->__fpu_fop = 0; 453 + s->__fpu_ip = fx->ipoff; 454 + s->__fpu_cs = fx->cssel; 455 + s->__fpu_dp = fx->dataoff; 456 + s->__fpu_ds = fx->datasel; 457 + s->__fpu_mxcsr = fx->mxcsr; 458 + s->__fpu_mxcsrmask = 0; 445 459 446 - memcpy(&s->fpu_stmm0, fx->_st, 128); 447 - memcpy(&s->fpu_xmm0, fx->_xmm, 128); 448 - memset(((char*) &s->fpu_xmm0) + 128, 0, 128); 460 + memcpy(&s->__fpu_stmm0, fx->_st, 128); 461 + memcpy(&s->__fpu_xmm0, fx->_xmm, 128); 462 + memset(((char*) &s->__fpu_xmm0) + 128, 0, 128); 449 463 } 450 464 451 465 void thread_state_to_mcontext(const x86_thread_state32_t* s, struct linux_gregset* regs) 452 466 { 453 - regs->eax = s->eax; 454 - regs->ebx = s->ebx; 455 - regs->ecx = s->ecx; 456 - regs->edx = s->edx; 457 - regs->edi = s->edi; 458 - regs->esi = s->esi; 459 - regs->ebp = s->ebp; 460 - regs->esp = s->esp; 461 - regs->ss = s->ss; 462 - regs->efl = s->eflags; 463 - regs->eip = s->eip; 464 - regs->cs = s->cs; 465 - regs->ds = s->ds; 466 - regs->es = s->es; 467 - regs->fs = s->fs; 468 - regs->gs = s->gs; 467 + regs->eax = s->__eax; 468 + regs->ebx = s->__ebx; 469 + regs->ecx = s->__ecx; 470 + regs->edx = s->__edx; 471 + regs->edi = s->__edi; 472 + regs->esi = s->__esi; 473 + regs->ebp = s->__ebp; 474 + regs->esp = s->__esp; 475 + regs->ss = s->__ss; 476 + regs->efl = s->__eflags; 477 + regs->eip = s->__eip; 478 + regs->cs = s->__cs; 479 + regs->ds = s->__ds; 480 + regs->es = s->__es; 481 + regs->fs = s->__fs; 482 + regs->gs = s->__gs; 469 483 } 470 484 471 485 void float_state_to_mcontext(const x86_float_state32_t* s, linux_fpregset_t fx) 472 486 { 473 - fx->cw = *((uint32_t*)&s->fpu_fcw); 474 - fx->sw = *((uint32_t*)&s->fpu_fsw); 475 - fx->tag = s->fpu_ftw; 476 - fx->ipoff = s->fpu_ip; 477 - fx->cssel = s->fpu_cs; 478 - fx->dataoff = s->fpu_dp; 479 - fx->datasel = s->fpu_ds; 480 - fx->mxcsr = s->fpu_mxcsr; 481 - fx->mxcsr_mask = s->fpu_mxcsrmask; 487 + fx->cw = *((uint32_t*)&s->__fpu_fcw); 488 + fx->sw = *((uint32_t*)&s->__fpu_fsw); 489 + fx->tag = s->__fpu_ftw; 490 + fx->ipoff = s->__fpu_ip; 491 + fx->cssel = s->__fpu_cs; 492 + fx->dataoff = s->__fpu_dp; 493 + fx->datasel = s->__fpu_ds; 494 + fx->mxcsr = s->__fpu_mxcsr; 482 495 483 - memcpy(fx->_st, &s->fpu_stmm0, 128); 484 - memcpy(fx->_xmm, &s->fpu_xmm0, 128); 496 + memcpy(fx->_st, &s->__fpu_stmm0, 128); 497 + memcpy(fx->_xmm, &s->__fpu_xmm0, 128); 485 498 } 486 499 #endif 487 500
+1 -1
src/kernel/libsyscall/wrappers/_libkernel_init.c
··· 50 50 } 51 51 52 52 setup_elfcalls(apple); 53 - sigexc_setup(); 54 53 mach_init(); 54 + sigexc_setup(); 55 55 }