Skip to content

Commit

Permalink
backout OS-4141: needs more work
Browse files Browse the repository at this point in the history
backout OS-4128: needs more work
  • Loading branch information
jclulow committed Apr 2, 2015
1 parent 576877c commit 271935c
Showing 1 changed file with 7 additions and 48 deletions.
55 changes: 7 additions & 48 deletions usr/src/uts/common/exec/elf/elf.c
Expand Up @@ -216,8 +216,6 @@ mapexec_brand(vnode_t *vp, uarg_t *args, Ehdr *ehdr, Addr *uphdr_vaddr,
&junk, &dtrphdr, NULL, bssbase, brkbase, voffset, &minaddr,
len, &execsz, brksize)) {
uprintf("%s: Cannot map %s\n", exec_file, args->pathname);
if (uphdr != NULL && uphdr->p_flags == 0)
kmem_free(uphdr, sizeof (Phdr));
kmem_free(phdrbase, phdrsize);
return (error);
}
Expand Down Expand Up @@ -272,9 +270,6 @@ mapexec_brand(vnode_t *vp, uarg_t *args, Ehdr *ehdr, Addr *uphdr_vaddr,

if (uphdr != NULL) {
*uphdr_vaddr = uphdr->p_vaddr;

if (uphdr->p_flags == 0)
kmem_free(uphdr, sizeof (Phdr));
} else {
*uphdr_vaddr = (Addr)-1;
}
Expand Down Expand Up @@ -746,13 +741,8 @@ elfexec(vnode_t *vp, execa_t *uap, uarg_t *args, intpdata_t *idatap,

/*
* Now obtain the ELF header along with the entire program
* header contained in "nvp". Before we free our program
* headers, we need to be sure to let go of the uphdr if it
* wasn't dynamically allocated.
* header contained in "nvp".
*/
if (uphdr != NULL && uphdr->p_flags != 0)
uphdr = NULL;

kmem_free(phdrbase, phdrsize);
phdrbase = NULL;
if ((error = getelfhead(nvp, CRED(), ehdrp, &nshdrs,
Expand All @@ -778,10 +768,9 @@ elfexec(vnode_t *vp, execa_t *uap, uarg_t *args, intpdata_t *idatap,

dtrphdr = NULL;

error = mapelfexec(nvp, ehdrp, nphdrs, phdrbase, NULL, &junk,
error = mapelfexec(nvp, ehdrp, nphdrs, phdrbase, &junk, &junk,
&junk, &dtrphdr, NULL, NULL, NULL, &voffset, NULL, len,
execsz, NULL);

if (error || junk != NULL) {
VN_RELE(nvp);
uprintf("%s: Cannot map %s\n", exec_file, dlnp);
Expand Down Expand Up @@ -988,8 +977,6 @@ elfexec(vnode_t *vp, execa_t *uap, uarg_t *args, intpdata_t *idatap,
if (error == 0)
error = ENOEXEC;
out:
if (uphdr != NULL && uphdr->p_flags == 0)
kmem_free(uphdr, sizeof (Phdr));
if (phdrbase != NULL)
kmem_free(phdrbase, phdrsize);
if (cap != NULL)
Expand Down Expand Up @@ -1320,6 +1307,9 @@ mapelfexec(
for (i = nphdrs; i > 0; i--) {
switch (phdr->p_type) {
case PT_LOAD:
if ((*dyphdr != NULL) && (*uphdr == NULL))
return (0);

ptload = 1;
prot = PROT_USER;
if (phdr->p_flags & PF_R)
Expand All @@ -1331,34 +1321,6 @@ mapelfexec(

addr = (caddr_t)((uintptr_t)phdr->p_vaddr + *voffset);

if ((*dyphdr != NULL) && uphdr != NULL &&
(*uphdr == NULL)) {
/*
* The PT_PHDR program header is, strictly
* speaking, optional. If we find that this
* is missing, we will determine the location
* of the program headers based on the address
* of the lowest PT_LOAD segment (namely, this
* one): we subtract the p_offset to get to
* the ELF header and then add back the program
* header offset to get to the program headers.
* We then cons up a Phdr that corresponds to
* the (missing) PT_PHDR, setting the flags
* to 0 to denote that this is artificial and
* should (must) be freed by the caller.
*/
Phdr *cons;

cons = kmem_zalloc(sizeof (Phdr), KM_SLEEP);

cons->p_flags = 0;
cons->p_type = PT_PHDR;
cons->p_vaddr = ((uintptr_t)addr -
phdr->p_offset) + ehdr->e_phoff;

*uphdr = cons;
}

/*
* Keep track of the segment with the lowest starting
* address.
Expand Down Expand Up @@ -1475,12 +1437,9 @@ mapelfexec(
break;

case PT_PHDR:
if (ptload || phdr->p_flags == 0)
if (ptload)
goto bad;

if (uphdr != NULL)
*uphdr = phdr;

*uphdr = phdr;
break;

case PT_NULL:
Expand Down

0 comments on commit 271935c

Please sign in to comment.