/[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.42 by gerd, Sat Nov 10 11:43:07 2001 UTC revision 1.43 by sds, Mon Nov 19 15:13:45 2001 UTC
# Line 434  extern void fatal (char *, ...); Line 434  extern void fatal (char *, ...);
434  #include <syms.h> /* for HDRR declaration */  #include <syms.h> /* for HDRR declaration */
435  #endif /* __sgi */  #endif /* __sgi */
436    
437    #ifndef MAP_ANON
438    #ifdef MAP_ANONYMOUS
439    #define MAP_ANON MAP_ANONYMOUS
440    #else
441    #define MAP_ANON 0
442    #endif
443    #endif
444    
445    #ifndef MAP_FAILED
446    #define MAP_FAILED ((void *) -1)
447    #endif
448    
449  #if defined (__alpha__) && !defined (__NetBSD__) && !defined (__OpenBSD__)  #if defined (__alpha__) && !defined (__NetBSD__) && !defined (__OpenBSD__)
450  /* Declare COFF debugging symbol table.  This used to be in  /* Declare COFF debugging symbol table.  This used to be in
451     /usr/include/sym.h, but this file is no longer included in Red Hat     /usr/include/sym.h, but this file is no longer included in Red Hat
# Line 649  unexec (new_name, old_name, data_start, Line 661  unexec (new_name, old_name, data_start,
661    /* Pointers to the base of the image of the two files.  */    /* Pointers to the base of the image of the two files.  */
662    caddr_t old_base, new_base;    caddr_t old_base, new_base;
663    
664    #if MAP_ANON == 0
665      int mmap_fd;
666    #else
667    # define mmap_fd -1
668    #endif
669    
670    /* Pointers to the file, program and section headers for the old and    /* Pointers to the file, program and section headers for the old and
671       new files.  */       new files.  */
672    ElfW(Ehdr) *old_file_h, *new_file_h;    ElfW(Ehdr) *old_file_h, *new_file_h;
# Line 681  unexec (new_name, old_name, data_start, Line 699  unexec (new_name, old_name, data_start,
699    if (fstat (old_file, &stat_buf) == -1)    if (fstat (old_file, &stat_buf) == -1)
700      fatal ("Can't fstat (%s): errno %d\n", old_name, errno);      fatal ("Can't fstat (%s): errno %d\n", old_name, errno);
701    
702    #if MAP_ANON == 0
703      mmap_fd = open ("/dev/zero", O_RDONLY);
704      if (mmap_fd < 0)
705        fatal ("Can't open /dev/zero for reading: errno %d\n", errno);
706    #endif
707    
708    /* We cannot use malloc here because that may use sbrk.  If it does,    /* We cannot use malloc here because that may use sbrk.  If it does,
709       we'd dump our temporary buffers with Emacs, and we'd have to be       we'd dump our temporary buffers with Emacs, and we'd have to be
710       extra careful to use the correct value of sbrk(0) after       extra careful to use the correct value of sbrk(0) after
711       allocating all buffers in the code below, which we aren't.  */       allocating all buffers in the code below, which we aren't.  */
712    old_file_size = stat_buf.st_size;    old_file_size = stat_buf.st_size;
713    old_base = mmap (NULL, old_file_size, PROT_READ | PROT_WRITE,    old_base = mmap (NULL, old_file_size, PROT_READ | PROT_WRITE,
714                     MAP_ANON | MAP_PRIVATE, -1, 0);                     MAP_ANON | MAP_PRIVATE, mmap_fd, 0);
715    if (old_base == (caddr_t) -1)    if (old_base == MAP_FAILED)
716      fatal ("Can't allocate buffer for %s\n", old_name);      fatal ("Can't allocate buffer for %s\n", old_name);
717    
718    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)
# Line 776  unexec (new_name, old_name, data_start, Line 800  unexec (new_name, old_name, data_start,
800      fatal ("Can't ftruncate (%s): errno %d\n", new_name, errno);      fatal ("Can't ftruncate (%s): errno %d\n", new_name, errno);
801    
802    new_base = mmap (NULL, new_file_size, PROT_READ | PROT_WRITE,    new_base = mmap (NULL, new_file_size, PROT_READ | PROT_WRITE,
803                     MAP_ANON | MAP_PRIVATE, -1, 0);                     MAP_ANON | MAP_PRIVATE, mmap_fd, 0);
804    if (new_base == (caddr_t) -1)    if (new_base == MAP_FAILED)
805      fatal ("Can't allocate buffer for %s\n", old_name);      fatal ("Can't allocate buffer for %s\n", old_name);
806    
807    new_file_h = (ElfW(Ehdr) *) new_base;    new_file_h = (ElfW(Ehdr) *) new_base;
# Line 1203  unexec (new_name, old_name, data_start, Line 1227  unexec (new_name, old_name, data_start,
1227    
1228    /* Close the files and make the new file executable.  */    /* Close the files and make the new file executable.  */
1229    
1230    #if MAP_ANON == 0
1231      close (mmap_fd);
1232    #endif
1233    
1234    if (close (old_file))    if (close (old_file))
1235      fatal ("Can't close (%s): errno %d\n", old_name, errno);      fatal ("Can't close (%s): errno %d\n", old_name, errno);
1236    

Legend:
Removed from v.1.42  
changed lines
  Added in v.1.43

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