this repo has no description
1
fork

Configure Feed

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

New way of passing register states to the debugger (LKM changes pending)

+232 -6
+13 -1
src/kernel/emulation/linux/signal/sigaction.h
··· 124 124 struct { 125 125 unsigned short significand[4], exponent; 126 126 } _st[8]; 127 - unsigned long status; 127 + unsigned short status, magic; 128 + unsigned int _fxsr_env[6]; 129 + unsigned int mxcsr; 130 + unsigned int reserved; 131 + struct _fpxreg { 132 + unsigned short significand[4]; 133 + unsigned short exponent; 134 + unsigned short padding[3]; 135 + } _fxsr_st[8]; 136 + struct { 137 + unsigned element[4]; 138 + } _xmm[8]; 128 139 } *linux_fpregset_t; 129 140 130 141 struct linux_gregset 131 142 { 132 143 int gs, fs, es, ds, edi, esi, ebp, esp, ebx, edx, ecx, eax; 133 144 int trapno, err, eip, cs, efl, uesp; 145 + int ss; 134 146 }; 135 147 #endif 136 148
+218 -4
src/kernel/emulation/linux/signal/sigexc.c
··· 27 27 static char sigexc_altstack[8192]; 28 28 static struct bsd_stack orig_stack; 29 29 30 + #if defined(__x86_64__) 31 + static void mcontext_to_thread_state(const struct linux_gregset* regs, x86_thread_state64_t* s); 32 + static void mcontext_to_float_state(const linux_fpregset_t fx, x86_float_state64_t* s); 33 + static void thread_state_to_mcontext(const x86_thread_state64_t* s, struct linux_gregset* regs); 34 + static void float_state_to_mcontext(const x86_float_state64_t* s, linux_fpregset_t fx); 35 + #elif defined(__i386__) 36 + static void mcontext_to_thread_state(const struct linux_gregset* regs, x86_thread_state32_t* s); 37 + static void mcontext_to_float_state(const linux_fpregset_t fx, x86_float_state32_t* s); 38 + static void thread_state_to_mcontext(const x86_thread_state32_t* s, struct linux_gregset* regs); 39 + static void float_state_to_mcontext(const x86_float_state32_t* s, linux_fpregset_t fx); 40 + #endif 41 + 30 42 void sigexc_setup(void) 31 43 { 32 44 // Setup handler for SIGNAL_SIGEXC_TOGGLE and SIGNAL_SIGEXC_THUPDATE ··· 170 182 return 0; 171 183 } 172 184 173 - void sigexc_handler(int linux_signum, struct linux_siginfo* info, void* ctxt) 185 + void sigexc_handler(int linux_signum, struct linux_siginfo* info, struct linux_ucontext* ctxt) 174 186 { 175 187 if (!darling_am_i_ptraced()) 176 188 return; ··· 184 196 int mach_exception; 185 197 long long codes[EXCEPTION_CODE_MAX] = { 0 }; 186 198 mach_port_t port; 199 + thread_t thread = mach_thread_self(); 187 200 188 201 int bsd_signum = signum_linux_to_bsd(linux_signum); 189 202 if (bsd_signum <= 0) ··· 225 238 226 239 port = get_exc_port(mach_exception); 227 240 228 - // TODO: pass mcontext_t to LKM 241 + // Pass register states to LKM 242 + #if defined(__x86_64__) 243 + x86_thread_state64_t tstate; 244 + x86_float_state64_t fstate; 245 + 246 + mcontext_to_thread_state(&ctxt->uc_mcontext.gregs, &tstate); 247 + mcontext_to_float_state(ctxt->uc_mcontext.fpregs, &fstate); 248 + 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); 251 + #elif defined(__i386__) 252 + x86_thread_state32_t tstate; 253 + x86_float_state32_t fstate; 254 + 255 + mcontext_to_thread_state(&ctxt->uc_mcontext.gregs, &tstate); 256 + mcontext_to_float_state(ctxt->uc_mcontext.fpregs, &fstate); 257 + 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); 260 + #endif 261 + 229 262 if (port != 0) 230 263 { 231 264 _pthread_setspecific_direct(SIGEXC_TSD_KEY, bsd_signum); 232 265 233 - mach_exception_raise(port, mach_thread_self(), mach_task_self(), mach_exception, codes, sizeof(codes) / sizeof(codes[0])); 266 + mach_exception_raise(port, mach_thread_self(), thread, mach_exception, codes, sizeof(codes) / sizeof(codes[0])); 234 267 235 268 bsd_signum = _pthread_getspecific_direct(SIGEXC_TSD_KEY); 236 269 } 237 - // Get (possibly updated) mcontext_t from LKM 270 + 271 + // Get (possibly updated by GDB) register states from LKM 272 + #if defined(__x86_64__) 273 + mach_msg_type_number_t count; 274 + 275 + 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); 279 + 280 + thread_state_to_mcontext(&tstate, &ctxt->uc_mcontext.gregs); 281 + float_state_to_mcontext(&fstate, ctxt->uc_mcontext.fpregs); 282 + #elif defined(__i386__) 283 + mach_msg_type_number_t count; 284 + 285 + 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); 289 + 290 + thread_state_to_mcontext(&tstate, &ctxt->uc_mcontext.gregs); 291 + float_state_to_mcontext(&fstate, ctxt->uc_mcontext.fpregs); 292 + #endif 238 293 239 294 // Pass the signal to the application handler or emulate the effects of the signal if SIG_DFL is set. 240 295 if (bsd_signum) ··· 270 325 } 271 326 } 272 327 } 328 + 329 + #if defined(__x86_64__) 330 + void mcontext_to_thread_state(const struct linux_gregset* regs, x86_thread_state64_t* s) 331 + { 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; 353 + } 354 + 355 + void mcontext_to_float_state(const linux_fpregset_t fx, x86_float_state64_t* s) 356 + { 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; 367 + 368 + memcpy(&s->fpu_stmm0, fx->_st, 128); 369 + memcpy(&s->fpu_xmm0, fx->_xmm, 256); 370 + } 371 + 372 + void thread_state_to_mcontext(const x86_thread_state64_t* s, struct linux_gregset* regs) 373 + { 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; 395 + } 396 + 397 + void float_state_to_mcontext(const x86_float_state64_t* s, linux_fpregset_t fx) 398 + { 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; 407 + 408 + memcpy(fx->_st, &s->fpu_stmm0, 128); 409 + memcpy(fx->_xmm, &s->fpu_xmm0, 256); 410 + } 411 + 412 + #elif defined(__i386__) 413 + void mcontext_to_thread_state(const struct linux_gregset* regs, x86_thread_state32_t* s) 414 + { 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; 431 + } 432 + 433 + void mcontext_to_float_state(const linux_fpregset_t fx, x86_float_state32_t* s) 434 + { 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; 445 + 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); 449 + } 450 + 451 + void thread_state_to_mcontext(const x86_thread_state32_t* s, struct linux_gregset* regs) 452 + { 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; 469 + } 470 + 471 + void float_state_to_mcontext(const x86_float_state32_t* s, linux_fpregset_t fx) 472 + { 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; 482 + 483 + memcpy(fx->_st, &s->fpu_stmm0, 128); 484 + memcpy(fx->_xmm, &s->fpu_xmm0, 128); 485 + } 486 + #endif 273 487 274 488 #define LINUX_SI_QUEUE (-1) 275 489 int linux_sigqueue(int pid, int rtsig, int value)
+1 -1
src/kernel/emulation/linux/signal/sigexc.h
··· 21 21 22 22 // for PT_SIGEXC to handle this operation synchronously 23 23 void darling_sigexc_self(void); 24 - void sigexc_handler(int linux_signum, struct linux_siginfo* info, void* ctxt); 24 + void sigexc_handler(int linux_signum, struct linux_siginfo* info, struct linux_ucontext* ctxt); 25 25 26 26 int linux_sigqueue(int pid, int rtsig, int value); 27 27 int linux_sigqueue_thread(int pid, int tid, int rtsig, int value);