/[emacs]/emacs/src/unexelf.c
ViewVC logotype

Diff of /emacs/src/unexelf.c

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

revision 1.40 by rms, Mon Nov 5 22:17:42 2001 UTC revision 1.41 by gerd, Sat Nov 10 11:39:39 2001 UTC
# Line 668  unexec (new_name, old_name, data_start, Line 668  unexec (new_name, old_name, data_start,
668    int old_data_index, new_data2_index;    int old_data_index, new_data2_index;
669    int old_mdebug_index;    int old_mdebug_index;
670    struct stat stat_buf;    struct stat stat_buf;
671      int old_file_size;
672    
673    /* Open the old file, allocate a buffer of the right size, and read    /* Open the old file, allocate a buffer of the right size, and read
674       in the file contents.  */       in the file contents.  */
# Line 680  unexec (new_name, old_name, data_start, Line 681  unexec (new_name, old_name, data_start,
681    if (fstat (old_file, &stat_buf) == -1)    if (fstat (old_file, &stat_buf) == -1)
682      fatal ("Can't fstat (%s): errno %d\n", old_name, errno);      fatal ("Can't fstat (%s): errno %d\n", old_name, errno);
683    
684    old_base = malloc (stat_buf.st_size);    /* We cannot use malloc here because that may use sbrk.  If it does,
685         we'd dump our temporary buffers with Emacs, and we'd have to be
686    if (old_base == 0)       extra careful to use the correct value of sbrk(0) after
687         allocating all buffers in the code below, which we aren't.  */
688      old_file_size = stat_buf.st_size;
689      old_base = mmap (NULL, old_file_size, PROT_READ | PROT_WRITE,
690                       MAP_ANON | MAP_PRIVATE, -1, 0);
691      if (old_base == (caddr_t) -1)
692      fatal ("Can't allocate buffer for %s\n", old_name);      fatal ("Can't allocate buffer for %s\n", old_name);
693    
 #ifdef DEBUG  
   fprintf (stderr, "%s: malloc(%d) -> %x\n", old_name, stat_buf.st_size,  
            old_base);  
 #endif  
   
694    if (read (old_file, old_base, stat_buf.st_size) != stat_buf.st_size)    if (read (old_file, old_base, stat_buf.st_size) != stat_buf.st_size)
695      fatal ("Didn't read all of %s: errno %d\n", old_name, errno);      fatal ("Didn't read all of %s: errno %d\n", old_name, errno);
696    
# Line 774  unexec (new_name, old_name, data_start, Line 775  unexec (new_name, old_name, data_start,
775    if (ftruncate (new_file, new_file_size))    if (ftruncate (new_file, new_file_size))
776      fatal ("Can't ftruncate (%s): errno %d\n", new_name, errno);      fatal ("Can't ftruncate (%s): errno %d\n", new_name, errno);
777    
778    new_base = malloc (new_file_size);    new_base = mmap (NULL, new_file_size, PROT_READ | PROT_WRITE,
779                       MAP_ANON | MAP_PRIVATE, -1, 0);
780    if (new_base == 0)    if (new_base == (caddr_t) -1)
781      fatal ("Can't allocate buffer for %s\n", old_name);      fatal ("Can't allocate buffer for %s\n", old_name);
782    
 #ifdef DEBUG  
   fprintf (stderr, "%s: malloc(%d) -> %x\n", new_name, new_file_size  
            new_base);  
 #endif  
   
783    new_file_h = (ElfW(Ehdr) *) new_base;    new_file_h = (ElfW(Ehdr) *) new_base;
784    new_program_h = (ElfW(Phdr) *) ((byte *) new_base + old_file_h->e_phoff);    new_program_h = (ElfW(Phdr) *) ((byte *) new_base + old_file_h->e_phoff);
785    new_section_h = (ElfW(Shdr) *)    new_section_h = (ElfW(Shdr) *)
# Line 1202  unexec (new_name, old_name, data_start, Line 1198  unexec (new_name, old_name, data_start,
1198      fatal ("Didn't write %d bytes to %s: errno %d\n",      fatal ("Didn't write %d bytes to %s: errno %d\n",
1199             new_file_size, new_base, errno);             new_file_size, new_base, errno);
1200    
1201    free (old_base);    munmap (old_base, old_file_size);
1202    free (new_base);    munmap (new_base, new_file_size);
1203    
1204    /* Close the files and make the new file executable.  */    /* Close the files and make the new file executable.  */
1205    

Legend:
Removed from v.1.40  
changed lines
  Added in v.1.41

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