diff options
| author | Sam Steingold | 2001-11-19 15:13:45 +0000 |
|---|---|---|
| committer | Sam Steingold | 2001-11-19 15:13:45 +0000 |
| commit | aff37336ea0e27a5cbc61b42b63d28a9d74b1498 (patch) | |
| tree | 9c0327bcb180a4387fc1bff32477ad2067744e96 /src | |
| parent | 7243105827747388bec152c6c3457924c4f7ade3 (diff) | |
| download | emacs-aff37336ea0e27a5cbc61b42b63d28a9d74b1498.tar.gz emacs-aff37336ea0e27a5cbc61b42b63d28a9d74b1498.zip | |
[!defined MAP_ANON]: Define MAP_ANON to MAP_ANONYMOUS if defined, 0 otherwise.
(MAP_FAILED): Define if not defined and use it for testing mmap failure.
(unexec) [!MAP_ANON]: Use /dev/zero as file to map.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 8 | ||||
| -rw-r--r-- | src/unexelf.c | 36 |
2 files changed, 40 insertions, 4 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 991c7648689..f7c5a5895df 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,11 @@ | |||
| 1 | 2001-11-14 Andreas Schwab <schwab@suse.de> | ||
| 2 | |||
| 3 | * unexelf.c [!defined MAP_ANON]: Define MAP_ANON to MAP_ANONYMOUS | ||
| 4 | if defined, 0 otherwise. | ||
| 5 | (MAP_FAILED): Define if not defined and use it for testing mmap | ||
| 6 | failure. | ||
| 7 | (unexec) [!MAP_ANON]: Use /dev/zero as file to map. | ||
| 8 | |||
| 1 | 2001-11-19 Richard M. Stallman <rms@gnu.org> | 9 | 2001-11-19 Richard M. Stallman <rms@gnu.org> |
| 2 | 10 | ||
| 3 | * indent.c (current_column_1): Fix handling of scan_bytes for mb chars. | 11 | * indent.c (current_column_1): Fix handling of scan_bytes for mb chars. |
diff --git a/src/unexelf.c b/src/unexelf.c index 5b0b3704266..32fdbc77cba 100644 --- a/src/unexelf.c +++ b/src/unexelf.c | |||
| @@ -434,6 +434,18 @@ extern void fatal (char *, ...); | |||
| 434 | #include <syms.h> /* for HDRR declaration */ | 434 | #include <syms.h> /* for HDRR declaration */ |
| 435 | #endif /* __sgi */ | 435 | #endif /* __sgi */ |
| 436 | 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 | |||
| 437 | #if defined (__alpha__) && !defined (__NetBSD__) && !defined (__OpenBSD__) | 449 | #if defined (__alpha__) && !defined (__NetBSD__) && !defined (__OpenBSD__) |
| 438 | /* Declare COFF debugging symbol table. This used to be in | 450 | /* Declare COFF debugging symbol table. This used to be in |
| 439 | /usr/include/sym.h, but this file is no longer included in Red Hat | 451 | /usr/include/sym.h, but this file is no longer included in Red Hat |
| @@ -649,6 +661,12 @@ unexec (new_name, old_name, data_start, bss_start, entry_address) | |||
| 649 | /* Pointers to the base of the image of the two files. */ | 661 | /* Pointers to the base of the image of the two files. */ |
| 650 | caddr_t old_base, new_base; | 662 | caddr_t old_base, new_base; |
| 651 | 663 | ||
| 664 | #if MAP_ANON == 0 | ||
| 665 | int mmap_fd; | ||
| 666 | #else | ||
| 667 | # define mmap_fd -1 | ||
| 668 | #endif | ||
| 669 | |||
| 652 | /* Pointers to the file, program and section headers for the old and | 670 | /* Pointers to the file, program and section headers for the old and |
| 653 | new files. */ | 671 | new files. */ |
| 654 | ElfW(Ehdr) *old_file_h, *new_file_h; | 672 | ElfW(Ehdr) *old_file_h, *new_file_h; |
| @@ -681,14 +699,20 @@ unexec (new_name, old_name, data_start, bss_start, entry_address) | |||
| 681 | if (fstat (old_file, &stat_buf) == -1) | 699 | if (fstat (old_file, &stat_buf) == -1) |
| 682 | fatal ("Can't fstat (%s): errno %d\n", old_name, errno); | 700 | fatal ("Can't fstat (%s): errno %d\n", old_name, errno); |
| 683 | 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 | |||
| 684 | /* We cannot use malloc here because that may use sbrk. If it does, | 708 | /* 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 | 709 | we'd dump our temporary buffers with Emacs, and we'd have to be |
| 686 | extra careful to use the correct value of sbrk(0) after | 710 | extra careful to use the correct value of sbrk(0) after |
| 687 | allocating all buffers in the code below, which we aren't. */ | 711 | allocating all buffers in the code below, which we aren't. */ |
| 688 | old_file_size = stat_buf.st_size; | 712 | old_file_size = stat_buf.st_size; |
| 689 | old_base = mmap (NULL, old_file_size, PROT_READ | PROT_WRITE, | 713 | old_base = mmap (NULL, old_file_size, PROT_READ | PROT_WRITE, |
| 690 | MAP_ANON | MAP_PRIVATE, -1, 0); | 714 | MAP_ANON | MAP_PRIVATE, mmap_fd, 0); |
| 691 | if (old_base == (caddr_t) -1) | 715 | if (old_base == MAP_FAILED) |
| 692 | fatal ("Can't allocate buffer for %s\n", old_name); | 716 | fatal ("Can't allocate buffer for %s\n", old_name); |
| 693 | 717 | ||
| 694 | if (read (old_file, old_base, stat_buf.st_size) != stat_buf.st_size) | 718 | if (read (old_file, old_base, stat_buf.st_size) != stat_buf.st_size) |
| @@ -776,8 +800,8 @@ unexec (new_name, old_name, data_start, bss_start, entry_address) | |||
| 776 | fatal ("Can't ftruncate (%s): errno %d\n", new_name, errno); | 800 | fatal ("Can't ftruncate (%s): errno %d\n", new_name, errno); |
| 777 | 801 | ||
| 778 | new_base = mmap (NULL, new_file_size, PROT_READ | PROT_WRITE, | 802 | new_base = mmap (NULL, new_file_size, PROT_READ | PROT_WRITE, |
| 779 | MAP_ANON | MAP_PRIVATE, -1, 0); | 803 | MAP_ANON | MAP_PRIVATE, mmap_fd, 0); |
| 780 | if (new_base == (caddr_t) -1) | 804 | if (new_base == MAP_FAILED) |
| 781 | fatal ("Can't allocate buffer for %s\n", old_name); | 805 | fatal ("Can't allocate buffer for %s\n", old_name); |
| 782 | 806 | ||
| 783 | new_file_h = (ElfW(Ehdr) *) new_base; | 807 | new_file_h = (ElfW(Ehdr) *) new_base; |
| @@ -1203,6 +1227,10 @@ unexec (new_name, old_name, data_start, bss_start, entry_address) | |||
| 1203 | 1227 | ||
| 1204 | /* Close the files and make the new file executable. */ | 1228 | /* Close the files and make the new file executable. */ |
| 1205 | 1229 | ||
| 1230 | #if MAP_ANON == 0 | ||
| 1231 | close (mmap_fd); | ||
| 1232 | #endif | ||
| 1233 | |||
| 1206 | if (close (old_file)) | 1234 | if (close (old_file)) |
| 1207 | fatal ("Can't close (%s): errno %d\n", old_name, errno); | 1235 | fatal ("Can't close (%s): errno %d\n", old_name, errno); |
| 1208 | 1236 | ||