/[hurd]/hurd/exec/exec.c
ViewVC logotype

Diff of /hurd/exec/exec.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.90 by roland, Sun Sep 26 20:25:11 2004 UTC revision 1.91 by roland, Fri Oct 22 23:34:50 2004 UTC
# Line 39  the Free Software Foundation, 675 Mass A Line 39  the Free Software Foundation, 675 Mass A
39  #include <sys/stat.h>  #include <sys/stat.h>
40  #include <sys/param.h>  #include <sys/param.h>
41  #include <unistd.h>  #include <unistd.h>
42    #include <stdbool.h>
43    
44  mach_port_t procserver; /* Our proc port.  */  mach_port_t procserver; /* Our proc port.  */
45    
# Line 898  static void Line 899  static void
899  check_elf_phdr (struct execdata *e, const ElfW(Phdr) *mapped_phdr)  check_elf_phdr (struct execdata *e, const ElfW(Phdr) *mapped_phdr)
900  {  {
901    const ElfW(Phdr) *phdr;    const ElfW(Phdr) *phdr;
902      bool seen_phdr = false;
903    
904    memcpy (e->info.elf.phdr, mapped_phdr,    memcpy (e->info.elf.phdr, mapped_phdr,
905            e->info.elf.phnum * sizeof (ElfW(Phdr)));            e->info.elf.phnum * sizeof (ElfW(Phdr)));
# Line 917  check_elf_phdr (struct execdata *e, cons Line 919  check_elf_phdr (struct execdata *e, cons
919          e->interp.phdr = phdr;          e->interp.phdr = phdr;
920          break;          break;
921        case PT_LOAD:        case PT_LOAD:
         /* Sanity check.  */  
         if ((phdr->p_offset & -phdr->p_align) == 0)  
           e->info.elf.phdr_addr += phdr->p_vaddr - phdr->p_offset;  
922          if (e->file_size <= (off_t) (phdr->p_offset +          if (e->file_size <= (off_t) (phdr->p_offset +
923                                       phdr->p_filesz))                                       phdr->p_filesz))
924            e->error = ENOEXEC;            {
925                e->error = ENOEXEC;
926                return;
927              }
928            /* Check if this is the segment that contains the phdr image.  */
929            if (!seen_phdr
930                && (phdr->p_offset & -phdr->p_align) == 0 /* Sanity check.  */
931                && phdr->p_offset <= e->info.elf.phdr_addr
932                && e->info.elf.phdr_addr - phdr->p_offset < phr->p_filesz)
933              {
934                e->info.elf.phdr_addr += phdr->p_vaddr - phdr->p_offset;
935                seen_phdr = true;
936              }
937          break;          break;
938        case PT_GNU_STACK:        case PT_GNU_STACK:
939          e->info.elf.execstack = phdr->p_flags & PF_X;          e->info.elf.execstack = phdr->p_flags & PF_X;
940          break;          break;
941        }        }
942    
943      if (!seen_phdr)
944        e->info.elf.phdr_addr = 0;
945  }  }
946    
947    
# Line 1807  do_exec (file_t file, Line 1821  do_exec (file_t file,
1821    /* Now record some essential addresses from the image itself that the    /* Now record some essential addresses from the image itself that the
1822       program's startup code will need to know.  We do this after loading       program's startup code will need to know.  We do this after loading
1823       the image so that a load-anywhere image gets the adjusted addresses.  */       the image so that a load-anywhere image gets the adjusted addresses.  */
1824        if (e.info.elf.phdr_addr != 0)
1825          {
1826  #ifdef BFD  #ifdef BFD
1827    if (!e.bfd)          if (!e.bfd)
1828  #endif  #endif
1829      e.info.elf.phdr_addr += e.info.elf.loadbase;            e.info.elf.phdr_addr += e.info.elf.loadbase;
1830    boot->phdr_addr = e.info.elf.phdr_addr;          boot->phdr_addr = e.info.elf.phdr_addr;
1831    boot->phdr_size = e.info.elf.phnum * sizeof (ElfW(Phdr));          boot->phdr_size = e.info.elf.phnum * sizeof (ElfW(Phdr));
1832          }
1833    boot->user_entry = e.entry;   /* already adjusted in `load' */    boot->user_entry = e.entry;   /* already adjusted in `load' */
1834    
1835    /* Create the initial thread.  */    /* Create the initial thread.  */

Legend:
Removed from v.1.90  
changed lines
  Added in v.1.91

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26