/[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.38.16.3 by rms, Mon Nov 26 01:22:12 2001 UTC revision 1.38.16.4 by eliz, Mon Jan 14 13:02:46 2002 UTC
# Line 448  extern void fatal (char *, ...); Line 448  extern void fatal (char *, ...);
448  #include <syms.h> /* for HDRR declaration */  #include <syms.h> /* for HDRR declaration */
449  #endif /* __sgi */  #endif /* __sgi */
450    
451    #ifndef MAP_ANON
452    #ifdef MAP_ANONYMOUS
453    #define MAP_ANON MAP_ANONYMOUS
454    #else
455    #define MAP_ANON 0
456    #endif
457    #endif
458    
459    #ifndef MAP_FAILED
460    #define MAP_FAILED ((void *) -1)
461    #endif
462    
463  #if defined (__alpha__) && !defined (__NetBSD__) && !defined (__OpenBSD__)  #if defined (__alpha__) && !defined (__NetBSD__) && !defined (__OpenBSD__)
464  /* Declare COFF debugging symbol table.  This used to be in  /* Declare COFF debugging symbol table.  This used to be in
465     /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 663  unexec (new_name, old_name, data_start, Line 675  unexec (new_name, old_name, data_start,
675    /* Pointers to the base of the image of the two files. */    /* Pointers to the base of the image of the two files. */
676    caddr_t old_base, new_base;    caddr_t old_base, new_base;
677    
678    #if MAP_ANON == 0
679      int mmap_fd;
680    #else
681    # define mmap_fd -1
682    #endif
683    
684    /* Pointers to the file, program and section headers for the old and new    /* Pointers to the file, program and section headers for the old and new
685     * files.     * files.
686     */     */
# Line 696  unexec (new_name, old_name, data_start, Line 714  unexec (new_name, old_name, data_start,
714    if (fstat (old_file, &stat_buf) == -1)    if (fstat (old_file, &stat_buf) == -1)
715      fatal ("Can't fstat (%s): errno %d\n", old_name, errno);      fatal ("Can't fstat (%s): errno %d\n", old_name, errno);
716    
717    #if MAP_ANON == 0
718      mmap_fd = open ("/dev/zero", O_RDONLY);
719      if (mmap_fd < 0)
720        fatal ("Can't open /dev/zero for reading: errno %d\n", errno);
721    #endif
722    
723    /* 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,
724       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
725       extra careful to use the correct value of sbrk(0) after       extra careful to use the correct value of sbrk(0) after
726       allocating all buffers in the code below, which we aren't.  */       allocating all buffers in the code below, which we aren't.  */
727    old_file_size = stat_buf.st_size;    old_file_size = stat_buf.st_size;
728    old_base = mmap (NULL, old_file_size, PROT_READ | PROT_WRITE,    old_base = mmap (NULL, old_file_size, PROT_READ | PROT_WRITE,
729                     MAP_ANON | MAP_PRIVATE, -1, 0);                     MAP_ANON | MAP_PRIVATE, mmap_fd, 0);
730    if (old_base == (caddr_t) -1)    if (old_base == MAP_FAILED)
731      fatal ("Can't allocate buffer for %s\n", old_name);      fatal ("Can't allocate buffer for %s\n", old_name);
732    
733    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 793  unexec (new_name, old_name, data_start, Line 817  unexec (new_name, old_name, data_start,
817      fatal ("Can't ftruncate (%s): errno %d\n", new_name, errno);      fatal ("Can't ftruncate (%s): errno %d\n", new_name, errno);
818    
819    new_base = mmap (NULL, new_file_size, PROT_READ | PROT_WRITE,    new_base = mmap (NULL, new_file_size, PROT_READ | PROT_WRITE,
820                     MAP_ANON | MAP_PRIVATE, -1, 0);                     MAP_ANON | MAP_PRIVATE, mmap_fd, 0);
821    if (new_base == (caddr_t) -1)    if (new_base == MAP_FAILED)
822      fatal ("Can't allocate buffer for %s\n", old_name);      fatal ("Can't allocate buffer for %s\n", old_name);
823    
824    new_file_h = (ElfW(Ehdr) *) new_base;    new_file_h = (ElfW(Ehdr) *) new_base;
# Line 1227  unexec (new_name, old_name, data_start, Line 1251  unexec (new_name, old_name, data_start,
1251    
1252    /* Close old_file, and free the corresponding buffer */    /* Close old_file, and free the corresponding buffer */
1253    
1254    #if MAP_ANON == 0
1255      close (mmap_fd);
1256    #endif
1257    
1258    if (close (old_file))    if (close (old_file))
1259      fatal ("Can't close (%s): errno %d\n", old_name, errno);      fatal ("Can't close (%s): errno %d\n", old_name, errno);
1260    

Legend:
Removed from v.1.38.16.3  
changed lines
  Added in v.1.38.16.4

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