Author: kib
Date: Sat Jan 15 09:25:19 2011
New Revision: 217442
URL: http://svn.freebsd.org/changeset/base/217442

Log:
  MFC r217150:
  Collect code to translate between vm_prot_t and p_flags into helper
  functions.

Modified:
  stable/8/sys/kern/imgact_elf.c
Directory Properties:
  stable/8/sys/   (props changed)
  stable/8/sys/amd64/include/xen/   (props changed)
  stable/8/sys/cddl/contrib/opensolaris/   (props changed)
  stable/8/sys/contrib/dev/acpica/   (props changed)
  stable/8/sys/contrib/pf/   (props changed)

Modified: stable/8/sys/kern/imgact_elf.c
==============================================================================
--- stable/8/sys/kern/imgact_elf.c      Sat Jan 15 08:37:33 2011        
(r217441)
+++ stable/8/sys/kern/imgact_elf.c      Sat Jan 15 09:25:19 2011        
(r217442)
@@ -86,6 +86,8 @@ static boolean_t __elfN(freebsd_trans_os
 static boolean_t kfreebsd_trans_osrel(const Elf_Note *note, int32_t *osrel);
 static boolean_t __elfN(check_note)(struct image_params *imgp,
     Elf_Brandnote *checknote, int32_t *osrel);
+static vm_prot_t __elfN(trans_prot)(Elf_Word);
+static Elf_Word __elfN(untrans_prot)(vm_prot_t);
 
 SYSCTL_NODE(_kern, OID_AUTO, __CONCAT(elf, __ELF_WORD_SIZE), CTLFLAG_RW, 0,
     "");
@@ -632,14 +634,7 @@ __elfN(load_file)(struct proc *p, const 
        for (i = 0, numsegs = 0; i < hdr->e_phnum; i++) {
                if (phdr[i].p_type == PT_LOAD && phdr[i].p_memsz != 0) {
                        /* Loadable segment */
-                       prot = 0;
-                       if (phdr[i].p_flags & PF_X)
-                               prot |= VM_PROT_EXECUTE;
-                       if (phdr[i].p_flags & PF_W)
-                               prot |= VM_PROT_WRITE;
-                       if (phdr[i].p_flags & PF_R)
-                               prot |= VM_PROT_READ;
-
+                       prot = __elfN(trans_prot)(phdr[i].p_flags);
                        if ((error = __elfN(load_section)(vmspace,
                            imgp->object, phdr[i].p_offset,
                            (caddr_t)(uintptr_t)phdr[i].p_vaddr + rbase,
@@ -780,13 +775,7 @@ __CONCAT(exec_, __elfN(imgact))(struct i
                case PT_LOAD:   /* Loadable segment */
                        if (phdr[i].p_memsz == 0)
                                break;
-                       prot = 0;
-                       if (phdr[i].p_flags & PF_X)
-                               prot |= VM_PROT_EXECUTE;
-                       if (phdr[i].p_flags & PF_W)
-                               prot |= VM_PROT_WRITE;
-                       if (phdr[i].p_flags & PF_R)
-                               prot |= VM_PROT_READ;
+                       prot = __elfN(trans_prot)(phdr[i].p_flags);
 
 #if defined(__ia64__) && __ELF_WORD_SIZE == 32 && defined(IA32_ME_HARDER)
                        /*
@@ -1086,13 +1075,7 @@ cb_put_phdr(entry, closure)
        phdr->p_paddr = 0;
        phdr->p_filesz = phdr->p_memsz = entry->end - entry->start;
        phdr->p_align = PAGE_SIZE;
-       phdr->p_flags = 0;
-       if (entry->protection & VM_PROT_READ)
-               phdr->p_flags |= PF_R;
-       if (entry->protection & VM_PROT_WRITE)
-               phdr->p_flags |= PF_W;
-       if (entry->protection & VM_PROT_EXECUTE)
-               phdr->p_flags |= PF_X;
+       phdr->p_flags = __elfN(untrans_prot)(entry->protection);
 
        phc->offset += phdr->p_filesz;
        phc->phdr++;
@@ -1483,3 +1466,33 @@ static struct execsw __elfN(execsw) = {
        __XSTRING(__CONCAT(ELF, __ELF_WORD_SIZE))
 };
 EXEC_SET(__CONCAT(elf, __ELF_WORD_SIZE), __elfN(execsw));
+
+static vm_prot_t
+__elfN(trans_prot)(Elf_Word flags)
+{
+       vm_prot_t prot;
+
+       prot = 0;
+       if (flags & PF_X)
+               prot |= VM_PROT_EXECUTE;
+       if (flags & PF_W)
+               prot |= VM_PROT_WRITE;
+       if (flags & PF_R)
+               prot |= VM_PROT_READ;
+       return (prot);
+}
+
+static Elf_Word
+__elfN(untrans_prot)(vm_prot_t prot)
+{
+       Elf_Word flags;
+
+       flags = 0;
+       if (prot & VM_PROT_EXECUTE)
+               flags |= PF_X;
+       if (prot & VM_PROT_READ)
+               flags |= PF_R;
+       if (prot & VM_PROT_WRITE)
+               flags |= PF_W;
+       return (flags);
+}
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to