MCPcopy Create free account
hub / github.com/F-Stack/f-stack / preload_protect

Function preload_protect

freebsd/kern/link_elf.c:773–804  ·  view source on GitHub ↗

* Apply the specified protection to the loadable segments of a preloaded linker * file. */

Source from the content-addressed store, hash-verified

771 * file.
772 */
773static int
774preload_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/*

Callers 2

link_elf_link_preloadFunction · 0.85

Calls 1

pmap_change_protFunction · 0.50

Tested by

no test coverage detected