* vm_fault_trap: * * Handle a page fault occurring at the given address, * requiring the given permissions, in the map specified. * If successful, the page is inserted into the * associated physical map. * * NOTE: the given address should be truncated to the * proper page address. * * KERN_SUCCESS is returned if the page fault is handled; otherwise, * a standard error specifying why the
| 618 | * Caller may hold no locks. |
| 619 | */ |
| 620 | int |
| 621 | vm_fault_trap(vm_map_t map, vm_offset_t vaddr, vm_prot_t fault_type, |
| 622 | int fault_flags, int *signo, int *ucode) |
| 623 | { |
| 624 | int result; |
| 625 | |
| 626 | MPASS(signo == NULL || ucode != NULL); |
| 627 | #ifdef KTRACE |
| 628 | if (map != kernel_map && KTRPOINT(curthread, KTR_FAULT)) |
| 629 | ktrfault(vaddr, fault_type); |
| 630 | #endif |
| 631 | result = vm_fault(map, trunc_page(vaddr), fault_type, fault_flags, |
| 632 | NULL); |
| 633 | KASSERT(result == KERN_SUCCESS || result == KERN_FAILURE || |
| 634 | result == KERN_INVALID_ADDRESS || |
| 635 | result == KERN_RESOURCE_SHORTAGE || |
| 636 | result == KERN_PROTECTION_FAILURE || |
| 637 | result == KERN_OUT_OF_BOUNDS, |
| 638 | ("Unexpected Mach error %d from vm_fault()", result)); |
| 639 | #ifdef KTRACE |
| 640 | if (map != kernel_map && KTRPOINT(curthread, KTR_FAULTEND)) |
| 641 | ktrfaultend(result); |
| 642 | #endif |
| 643 | if (result != KERN_SUCCESS && signo != NULL) { |
| 644 | switch (result) { |
| 645 | case KERN_FAILURE: |
| 646 | case KERN_INVALID_ADDRESS: |
| 647 | *signo = SIGSEGV; |
| 648 | *ucode = SEGV_MAPERR; |
| 649 | break; |
| 650 | case KERN_RESOURCE_SHORTAGE: |
| 651 | *signo = SIGBUS; |
| 652 | *ucode = BUS_OOMERR; |
| 653 | break; |
| 654 | case KERN_OUT_OF_BOUNDS: |
| 655 | *signo = SIGBUS; |
| 656 | *ucode = BUS_OBJERR; |
| 657 | break; |
| 658 | case KERN_PROTECTION_FAILURE: |
| 659 | if (prot_fault_translation == 0) { |
| 660 | /* |
| 661 | * Autodetect. This check also covers |
| 662 | * the images without the ABI-tag ELF |
| 663 | * note. |
| 664 | */ |
| 665 | if (SV_CURPROC_ABI() == SV_ABI_FREEBSD && |
| 666 | curproc->p_osrel >= P_OSREL_SIGSEGV) { |
| 667 | *signo = SIGSEGV; |
| 668 | *ucode = SEGV_ACCERR; |
| 669 | } else { |
| 670 | *signo = SIGBUS; |
| 671 | *ucode = UCODE_PAGEFLT; |
| 672 | } |
| 673 | } else if (prot_fault_translation == 1) { |
| 674 | /* Always compat mode. */ |
| 675 | *signo = SIGBUS; |
| 676 | *ucode = UCODE_PAGEFLT; |
| 677 | } else { |
no test coverage detected