Changeset View
Changeset View
Standalone View
Standalone View
sys/amd64/amd64/trap.c
Show First 20 Lines • Show All 442 Lines • ▼ Show 20 Lines | case T_SEGNPFLT: /* segment not present fault */ | ||||
* Invalid segment selectors and out of bounds | * Invalid segment selectors and out of bounds | ||||
* %rip's and %rsp's can be set up in user mode. | * %rip's and %rsp's can be set up in user mode. | ||||
* This causes a fault in kernel mode when the | * This causes a fault in kernel mode when the | ||||
* kernel tries to return to user mode. We want | * kernel tries to return to user mode. We want | ||||
* to get this fault so that we can fix the | * to get this fault so that we can fix the | ||||
* problem here and not have to check all the | * problem here and not have to check all the | ||||
* selectors and pointers when the user changes | * selectors and pointers when the user changes | ||||
* them. | * them. | ||||
* | |||||
* In case of PTI, the IRETQ faulted while the | |||||
* kernel used the pti stack, and exception | |||||
* frame records %rsp value pointing to that | |||||
* stack. If we return normally to | |||||
* doreti_iret_fault, the trapframe is | |||||
* reconstructed on pti stack, and calltrap() | |||||
* called on it as well. Due to the very | |||||
* limited pti stack size, kernel does not | |||||
* survive for too long. Switch to the normal | |||||
* thread stack for the trap handling. | |||||
* | |||||
* Magic '5' is the number of qwords occupied by | |||||
* the hardware trap frame. | |||||
*/ | */ | ||||
if (frame->tf_rip == (long)doreti_iret) { | if (frame->tf_rip == (long)doreti_iret) { | ||||
frame->tf_rip = (long)doreti_iret_fault; | frame->tf_rip = (long)doreti_iret_fault; | ||||
if (pti && frame->tf_rsp == (uintptr_t)PCPU_PTR( | |||||
pti_stack) + (PC_PTI_STACK_SZ - 5) * | |||||
sizeof(register_t)) | |||||
frame->tf_rsp = PCPU_GET(rsp0) - 5 * | |||||
kithrup_mac.com: Why -5? (I.e., can we get a comment on it or a macro?) | |||||
sizeof(register_t); | |||||
return; | return; | ||||
} | } | ||||
if (frame->tf_rip == (long)ld_ds) { | if (frame->tf_rip == (long)ld_ds) { | ||||
frame->tf_rip = (long)ds_load_fault; | frame->tf_rip = (long)ds_load_fault; | ||||
return; | return; | ||||
} | } | ||||
if (frame->tf_rip == (long)ld_es) { | if (frame->tf_rip == (long)ld_es) { | ||||
frame->tf_rip = (long)es_load_fault; | frame->tf_rip = (long)es_load_fault; | ||||
▲ Show 20 Lines • Show All 486 Lines • Show Last 20 Lines |
Why -5? (I.e., can we get a comment on it or a macro?)