Changeset View
Changeset View
Standalone View
Standalone View
head/sys/amd64/amd64/trap.c
Show First 20 Lines • Show All 602 Lines • ▼ Show 20 Lines | trap_pfault(struct trapframe *frame, int usermode) | ||||
vm_offset_t va; | vm_offset_t va; | ||||
int rv; | int rv; | ||||
vm_prot_t ftype; | vm_prot_t ftype; | ||||
vm_offset_t eva; | vm_offset_t eva; | ||||
td = curthread; | td = curthread; | ||||
p = td->td_proc; | p = td->td_proc; | ||||
eva = frame->tf_addr; | eva = frame->tf_addr; | ||||
rv = 0; | |||||
if (__predict_false((td->td_pflags & TDP_NOFAULTING) != 0)) { | if (__predict_false((td->td_pflags & TDP_NOFAULTING) != 0)) { | ||||
/* | /* | ||||
* Due to both processor errata and lazy TLB invalidation when | * Due to both processor errata and lazy TLB invalidation when | ||||
* access restrictions are removed from virtual pages, memory | * access restrictions are removed from virtual pages, memory | ||||
* accesses that are allowed by the physical mapping layer may | * accesses that are allowed by the physical mapping layer may | ||||
* nonetheless cause one spurious page fault per virtual page. | * nonetheless cause one spurious page fault per virtual page. | ||||
* When the thread is executing a "no faulting" section that | * When the thread is executing a "no faulting" section that | ||||
Show All 35 Lines | if (__predict_false((td->td_pflags & TDP_NOFAULTING) != 0)) { | ||||
} | } | ||||
} | } | ||||
va = trunc_page(eva); | va = trunc_page(eva); | ||||
if (va >= VM_MIN_KERNEL_ADDRESS) { | if (va >= VM_MIN_KERNEL_ADDRESS) { | ||||
/* | /* | ||||
* Don't allow user-mode faults in kernel address space. | * Don't allow user-mode faults in kernel address space. | ||||
*/ | */ | ||||
if (usermode) | if (usermode) | ||||
goto nogo; | return (SIGSEGV); | ||||
map = kernel_map; | map = kernel_map; | ||||
} else { | } else { | ||||
map = &p->p_vmspace->vm_map; | map = &p->p_vmspace->vm_map; | ||||
/* | /* | ||||
* When accessing a usermode address, kernel must be | * When accessing a usermode address, kernel must be | ||||
* ready to accept the page fault, and provide a | * ready to accept the page fault, and provide a | ||||
Show All 38 Lines | if (ftype == VM_PROT_READ || ftype == VM_PROT_WRITE) { | ||||
frame); | frame); | ||||
else | else | ||||
PMC_SOFT_CALL_TF( , , page_fault, write, | PMC_SOFT_CALL_TF( , , page_fault, write, | ||||
frame); | frame); | ||||
} | } | ||||
#endif | #endif | ||||
return (0); | return (0); | ||||
} | } | ||||
nogo: | |||||
if (!usermode) { | if (!usermode) { | ||||
if (td->td_intr_nesting_level == 0 && | if (td->td_intr_nesting_level == 0 && | ||||
curpcb->pcb_onfault != NULL) { | curpcb->pcb_onfault != NULL) { | ||||
frame->tf_rip = (long)curpcb->pcb_onfault; | frame->tf_rip = (long)curpcb->pcb_onfault; | ||||
return (0); | return (0); | ||||
} | } | ||||
trap_fatal(frame, eva); | trap_fatal(frame, eva); | ||||
return (-1); | return (-1); | ||||
▲ Show 20 Lines • Show All 223 Lines • Show Last 20 Lines |