* Apply the specified protection to the loadable segments of a preloaded linker * file. */
| 771 | * file. |
| 772 | */ |
| 773 | static int |
| 774 | preload_protect(elf_file_t ef, vm_prot_t prot) |
| 775 | { |
| 776 | #ifdef __amd64__ |
| 777 | Elf_Ehdr *hdr; |
| 778 | Elf_Phdr *phdr, *phlimit; |
| 779 | vm_prot_t nprot; |
| 780 | int error; |
| 781 | |
| 782 | error = 0; |
| 783 | hdr = (Elf_Ehdr *)ef->address; |
| 784 | phdr = (Elf_Phdr *)(ef->address + hdr->e_phoff); |
| 785 | phlimit = phdr + hdr->e_phnum; |
| 786 | for (; phdr < phlimit; phdr++) { |
| 787 | if (phdr->p_type != PT_LOAD) |
| 788 | continue; |
| 789 | |
| 790 | nprot = prot | VM_PROT_READ; |
| 791 | if ((phdr->p_flags & PF_W) != 0) |
| 792 | nprot |= VM_PROT_WRITE; |
| 793 | if ((phdr->p_flags & PF_X) != 0) |
| 794 | nprot |= VM_PROT_EXECUTE; |
| 795 | error = pmap_change_prot((vm_offset_t)ef->address + |
| 796 | phdr->p_vaddr, round_page(phdr->p_memsz), nprot); |
| 797 | if (error != 0) |
| 798 | break; |
| 799 | } |
| 800 | return (error); |
| 801 | #else |
| 802 | return (0); |
| 803 | #endif |
| 804 | } |
| 805 | |
| 806 | #ifdef __arm__ |
| 807 | /* |
no test coverage detected