aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGerd Moellmann2001-11-10 11:40:04 +0000
committerGerd Moellmann2001-11-10 11:40:04 +0000
commit86928dfb6f6a76bb2762afcef2dc0a2922b7b2bf (patch)
treedf0b6161cacbf7463b66d578b47069bcf5040ef7 /src
parentdbe3a58a447e5ec8462cd60d83593b626e2eb89f (diff)
downloademacs-86928dfb6f6a76bb2762afcef2dc0a2922b7b2bf.tar.gz
emacs-86928dfb6f6a76bb2762afcef2dc0a2922b7b2bf.zip
(unexec): Use mmap/munmap to allocate buffers
instead of malloc/free.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog5
-rw-r--r--src/unexelf.c32
2 files changed, 19 insertions, 18 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 4ac5ee52967..0a19005c33f 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,8 @@
12001-11-10 Gerd Moellmann <gerd@gnu.org>
2
3 * unexelf.c (unexec): Use mmap/munmap to allocate buffers
4 instead of malloc/free.
5
12001-11-09 Pavel Jan,Bm(Bk <Pavel@Janik.cz> 62001-11-09 Pavel Jan,Bm(Bk <Pavel@Janik.cz>
2 7
3 * xfaces.c (merge_face_vectors): Use braces to follow GNU 8 * xfaces.c (merge_face_vectors): Use braces to follow GNU
diff --git a/src/unexelf.c b/src/unexelf.c
index 222de55ed56..8ea893e532f 100644
--- a/src/unexelf.c
+++ b/src/unexelf.c
@@ -668,6 +668,7 @@ unexec (new_name, old_name, data_start, bss_start, entry_address)
668 int old_data_index, new_data2_index; 668 int old_data_index, new_data2_index;
669 int old_mdebug_index; 669 int old_mdebug_index;
670 struct stat stat_buf; 670 struct stat stat_buf;
671 int old_file_size;
671 672
672 /* Open the old file, allocate a buffer of the right size, and read 673 /* Open the old file, allocate a buffer of the right size, and read
673 in the file contents. */ 674 in the file contents. */
@@ -680,16 +681,16 @@ unexec (new_name, old_name, data_start, bss_start, entry_address)
680 if (fstat (old_file, &stat_buf) == -1) 681 if (fstat (old_file, &stat_buf) == -1)
681 fatal ("Can't fstat (%s): errno %d\n", old_name, errno); 682 fatal ("Can't fstat (%s): errno %d\n", old_name, errno);
682 683
683 old_base = malloc (stat_buf.st_size); 684 /* We cannot use malloc here because that may use sbrk. If it does,
684 685 we'd dump our temporary buffers with Emacs, and we'd have to be
685 if (old_base == 0) 686 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)
686 fatal ("Can't allocate buffer for %s\n", old_name); 692 fatal ("Can't allocate buffer for %s\n", old_name);
687 693
688#ifdef DEBUG
689 fprintf (stderr, "%s: malloc(%d) -> %x\n", old_name, stat_buf.st_size,
690 old_base);
691#endif
692
693 if (read (old_file, old_base, stat_buf.st_size) != stat_buf.st_size) 694 if (read (old_file, old_base, stat_buf.st_size) != stat_buf.st_size)
694 fatal ("Didn't read all of %s: errno %d\n", old_name, errno); 695 fatal ("Didn't read all of %s: errno %d\n", old_name, errno);
695 696
@@ -774,16 +775,11 @@ unexec (new_name, old_name, data_start, bss_start, entry_address)
774 if (ftruncate (new_file, new_file_size)) 775 if (ftruncate (new_file, new_file_size))
775 fatal ("Can't ftruncate (%s): errno %d\n", new_name, errno); 776 fatal ("Can't ftruncate (%s): errno %d\n", new_name, errno);
776 777
777 new_base = malloc (new_file_size); 778 new_base = mmap (NULL, new_file_size, PROT_READ | PROT_WRITE,
778 779 MAP_ANON | MAP_PRIVATE, -1, 0);
779 if (new_base == 0) 780 if (new_base == (caddr_t) -1)
780 fatal ("Can't allocate buffer for %s\n", old_name); 781 fatal ("Can't allocate buffer for %s\n", old_name);
781 782
782#ifdef DEBUG
783 fprintf (stderr, "%s: malloc(%d) -> %x\n", new_name, new_file_size
784 new_base);
785#endif
786
787 new_file_h = (ElfW(Ehdr) *) new_base; 783 new_file_h = (ElfW(Ehdr) *) new_base;
788 new_program_h = (ElfW(Phdr) *) ((byte *) new_base + old_file_h->e_phoff); 784 new_program_h = (ElfW(Phdr) *) ((byte *) new_base + old_file_h->e_phoff);
789 new_section_h = (ElfW(Shdr) *) 785 new_section_h = (ElfW(Shdr) *)
@@ -1202,8 +1198,8 @@ unexec (new_name, old_name, data_start, bss_start, entry_address)
1202 fatal ("Didn't write %d bytes to %s: errno %d\n", 1198 fatal ("Didn't write %d bytes to %s: errno %d\n",
1203 new_file_size, new_base, errno); 1199 new_file_size, new_base, errno);
1204 1200
1205 free (old_base); 1201 munmap (old_base, old_file_size);
1206 free (new_base); 1202 munmap (new_base, new_file_size);
1207 1203
1208 /* Close the files and make the new file executable. */ 1204 /* Close the files and make the new file executable. */
1209 1205