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 |
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; |
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) |
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; |
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 |
|
|