From 04f903c09aa37259be40a39eeadf344e1ae7eb1a Mon Sep 17 00:00:00 2001 From: Karl Heuer Date: Tue, 16 May 1995 01:46:20 +0000 Subject: [PATCH] (unexec) [UNEXEC_USE_MAP_PRIVATE]: New logic for systems that don't support MAP_SHARED with PROT_WRITE. --- src/unexelf.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/unexelf.c b/src/unexelf.c index edfaedb1dd2..c61f4c368f1 100644 --- a/src/unexelf.c +++ b/src/unexelf.c @@ -583,8 +583,13 @@ unexec (new_name, old_name, data_start, bss_start, entry_address) if (ftruncate (new_file, new_file_size)) fatal ("Can't ftruncate (%s): errno %d\n", new_name, errno); +#ifdef UNEXEC_USE_MAP_PRIVATE + new_base = mmap (0, new_file_size, PROT_READ | PROT_WRITE, MAP_PRIVATE, + new_file, 0); +#else new_base = mmap (0, new_file_size, PROT_READ | PROT_WRITE, MAP_SHARED, new_file, 0); +#endif if (new_base == (caddr_t) -1) fatal ("Can't mmap (%s): errno %d\n", new_name, errno); @@ -802,6 +807,14 @@ unexec (new_name, old_name, data_start, bss_start, entry_address) memcpy (&symp->st_value, &new_bss_addr, sizeof (new_bss_addr)); } +#ifdef UNEXEC_USE_MAP_PRIVATE + if (lseek (new_file, 0, SEEK_SET) == -1) + fatal ("Can't rewind (%s): errno %d\n", new_name, errno); + + if (write (new_file, new_base, new_file_size) != new_file_size) + fatal ("Can't write (%s): errno %d\n", new_name, errno); +#endif + /* Close the files and make the new file executable. */ if (close (old_file)) -- 2.39.2