Changeset View
Changeset View
Standalone View
Standalone View
libexec/rtld-elf/rtld.c
Show First 20 Lines • Show All 2,976 Lines • ▼ Show 20 Lines | reloc_textrel_prot(Obj_Entry *obj, bool before) | ||||
for (l = obj->phsize / sizeof(*ph), ph = obj->phdr; l > 0; | for (l = obj->phsize / sizeof(*ph), ph = obj->phdr; l > 0; | ||||
l--, ph++) { | l--, ph++) { | ||||
if (ph->p_type != PT_LOAD || (ph->p_flags & PF_W) != 0) | if (ph->p_type != PT_LOAD || (ph->p_flags & PF_W) != 0) | ||||
continue; | continue; | ||||
base = obj->relocbase + trunc_page(ph->p_vaddr); | base = obj->relocbase + trunc_page(ph->p_vaddr); | ||||
sz = round_page(ph->p_vaddr + ph->p_filesz) - | sz = round_page(ph->p_vaddr + ph->p_filesz) - | ||||
trunc_page(ph->p_vaddr); | trunc_page(ph->p_vaddr); | ||||
prot = convert_prot(ph->p_flags) | (before ? PROT_WRITE : 0); | prot = before ? (PROT_READ | PROT_WRITE) : | ||||
convert_prot(ph->p_flags); | |||||
if (mprotect(base, sz, prot) == -1) { | if (mprotect(base, sz, prot) == -1) { | ||||
emaste: maybe clearer if we incorporate the PROT_WRITE part from above?
something like
```
prot =… | |||||
Not Done Inline ActionsThere is no much reason to use convert_prot() in'before' case at all, then. Only PF_R survives. It can be prot = before ? (PROT_READ | PROT_WRITE) : convert_prot(ph->p_flags); kib: There is no much reason to use convert_prot() in'before' case at all, then. Only PF_R survives. | |||||
_rtld_error("%s: Cannot write-%sable text segment: %s", | _rtld_error("%s: Cannot write-%sable text segment: %s", | ||||
obj->path, before ? "en" : "dis", | obj->path, before ? "en" : "dis", | ||||
rtld_strerror(errno)); | rtld_strerror(errno)); | ||||
return (-1); | return (-1); | ||||
} | } | ||||
} | } | ||||
return (0); | return (0); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 2,899 Lines • Show Last 20 Lines |
maybe clearer if we incorporate the PROT_WRITE part from above?
something like