|
|
bb3be4 |
From 7ffe5bd31f9cb53a37f91c5fd1a9b6ce0df51c81 Mon Sep 17 00:00:00 2001
|
|
|
bb3be4 |
From: Jan Synacek <jsynacek@redhat.com>
|
|
|
bb3be4 |
Date: Tue, 24 May 2016 09:39:42 +0200
|
|
|
bb3be4 |
Subject: [PATCH 01/11] ppc64 fixes prepatch
|
|
|
bb3be4 |
|
|
|
bb3be4 |
---
|
|
|
bb3be4 |
src/unexelf.c | 210 +++++++++++++++++++++++++++++-----------------------------
|
|
|
bb3be4 |
1 file changed, 105 insertions(+), 105 deletions(-)
|
|
|
bb3be4 |
|
|
|
bb3be4 |
diff --git a/src/unexelf.c b/src/unexelf.c
|
|
|
bb3be4 |
index d365940..483da6e 100644
|
|
|
bb3be4 |
--- a/src/unexelf.c
|
|
|
bb3be4 |
+++ b/src/unexelf.c
|
|
|
bb3be4 |
@@ -1,4 +1,4 @@
|
|
|
bb3be4 |
-/* Copyright (C) 1985-1988, 1990, 1992, 1999-2013 Free Software
|
|
|
bb3be4 |
+/* Copyright (C) 1985-1988, 1990, 1992, 1999-2015 Free Software
|
|
|
bb3be4 |
Foundation, Inc.
|
|
|
bb3be4 |
|
|
|
bb3be4 |
This file is part of GNU Emacs.
|
|
|
bb3be4 |
@@ -386,18 +386,19 @@ temacs:
|
|
|
bb3be4 |
Instead we read the whole file, modify it, and write it out. */
|
|
|
bb3be4 |
|
|
|
bb3be4 |
#include <config.h>
|
|
|
bb3be4 |
-#include <unexec.h>
|
|
|
bb3be4 |
+#include "unexec.h"
|
|
|
bb3be4 |
+#include "lisp.h"
|
|
|
bb3be4 |
|
|
|
bb3be4 |
-extern void fatal (const char *msgid, ...);
|
|
|
bb3be4 |
-
|
|
|
bb3be4 |
-#include <sys/types.h>
|
|
|
bb3be4 |
+#include <errno.h>
|
|
|
bb3be4 |
+#include <fcntl.h>
|
|
|
bb3be4 |
+#include <limits.h>
|
|
|
bb3be4 |
+#include <memory.h>
|
|
|
bb3be4 |
#include <stdint.h>
|
|
|
bb3be4 |
#include <stdio.h>
|
|
|
bb3be4 |
#include <sys/stat.h>
|
|
|
bb3be4 |
-#include <memory.h>
|
|
|
bb3be4 |
-#include <errno.h>
|
|
|
bb3be4 |
+#include <sys/types.h>
|
|
|
bb3be4 |
#include <unistd.h>
|
|
|
bb3be4 |
-#include <fcntl.h>
|
|
|
bb3be4 |
+
|
|
|
bb3be4 |
#if !defined (__NetBSD__) && !defined (__OpenBSD__)
|
|
|
bb3be4 |
#include <elf.h>
|
|
|
bb3be4 |
#endif /* not __NetBSD__ and not __OpenBSD__ */
|
|
|
bb3be4 |
@@ -519,6 +520,18 @@ typedef struct {
|
|
|
bb3be4 |
# define ElfW(type) ElfExpandBitsW (ELFSIZE, type)
|
|
|
bb3be4 |
#endif
|
|
|
bb3be4 |
|
|
|
bb3be4 |
+/* The code often converts ElfW (Half) values like e_shentsize to ptrdiff_t;
|
|
|
bb3be4 |
+ check that this doesn't lose information. */
|
|
|
bb3be4 |
+#include <intprops.h>
|
|
|
bb3be4 |
+#include <verify.h>
|
|
|
bb3be4 |
+verify ((! TYPE_SIGNED (ElfW (Half))
|
|
|
bb3be4 |
+ || PTRDIFF_MIN <= TYPE_MINIMUM (ElfW (Half)))
|
|
|
bb3be4 |
+ && TYPE_MAXIMUM (ElfW (Half)) <= PTRDIFF_MAX);
|
|
|
bb3be4 |
+
|
|
|
bb3be4 |
+#ifdef UNEXELF_DEBUG
|
|
|
bb3be4 |
+# define DEBUG_LOG(expr) fprintf (stderr, #expr " 0x%jx\n", (uintmax_t) (expr))
|
|
|
bb3be4 |
+#endif
|
|
|
bb3be4 |
+
|
|
|
bb3be4 |
/* Get the address of a particular section or program header entry,
|
|
|
bb3be4 |
* accounting for the size of the entries.
|
|
|
bb3be4 |
*/
|
|
|
bb3be4 |
@@ -546,17 +559,21 @@ typedef struct {
|
|
|
bb3be4 |
Apr 23, 1996
|
|
|
bb3be4 |
*/
|
|
|
bb3be4 |
|
|
|
bb3be4 |
+static void *
|
|
|
bb3be4 |
+entry_address (void *section_h, ptrdiff_t idx, ptrdiff_t entsize)
|
|
|
bb3be4 |
+{
|
|
|
bb3be4 |
+ char *h = section_h;
|
|
|
bb3be4 |
+ return h + idx * entsize;
|
|
|
bb3be4 |
+}
|
|
|
bb3be4 |
+
|
|
|
bb3be4 |
#define OLD_SECTION_H(n) \
|
|
|
bb3be4 |
- (*(ElfW (Shdr) *) ((byte *) old_section_h + old_file_h->e_shentsize * (n)))
|
|
|
bb3be4 |
+ (*(ElfW (Shdr) *) entry_address (old_section_h, n, old_file_h->e_shentsize))
|
|
|
bb3be4 |
#define NEW_SECTION_H(n) \
|
|
|
bb3be4 |
- (*(ElfW (Shdr) *) ((byte *) new_section_h + new_file_h->e_shentsize * (n)))
|
|
|
bb3be4 |
+ (*(ElfW (Shdr) *) entry_address (new_section_h, n, new_file_h->e_shentsize))
|
|
|
bb3be4 |
#define NEW_PROGRAM_H(n) \
|
|
|
bb3be4 |
- (*(ElfW (Phdr) *) ((byte *) new_program_h + new_file_h->e_phentsize * (n)))
|
|
|
bb3be4 |
+ (*(ElfW (Phdr) *) entry_address (new_program_h, n, new_file_h->e_phentsize))
|
|
|
bb3be4 |
|
|
|
bb3be4 |
-#define PATCH_INDEX(n) \
|
|
|
bb3be4 |
- do { \
|
|
|
bb3be4 |
- if ((int) (n) >= old_bss_index) \
|
|
|
bb3be4 |
- (n)++; } while (0)
|
|
|
bb3be4 |
+#define PATCH_INDEX(n) ((n) += old_bss_index <= (n))
|
|
|
bb3be4 |
typedef unsigned char byte;
|
|
|
bb3be4 |
|
|
|
bb3be4 |
/* Round X up to a multiple of Y. */
|
|
|
bb3be4 |
@@ -564,7 +581,7 @@ typedef unsigned char byte;
|
|
|
bb3be4 |
static ElfW (Addr)
|
|
|
bb3be4 |
round_up (ElfW (Addr) x, ElfW (Addr) y)
|
|
|
bb3be4 |
{
|
|
|
bb3be4 |
- int rem = x % y;
|
|
|
bb3be4 |
+ ElfW (Addr) rem = x % y;
|
|
|
bb3be4 |
if (rem == 0)
|
|
|
bb3be4 |
return x;
|
|
|
bb3be4 |
return x - rem + y;
|
|
|
bb3be4 |
@@ -575,33 +592,28 @@ round_up (ElfW (Addr) x, ElfW (Addr) y)
|
|
|
bb3be4 |
about the file we are looking in.
|
|
|
bb3be4 |
|
|
|
bb3be4 |
If we don't find the section NAME, that is a fatal error
|
|
|
bb3be4 |
- if NOERROR is 0; we return -1 if NOERROR is nonzero. */
|
|
|
bb3be4 |
+ if NOERROR is false; return -1 if NOERROR is true. */
|
|
|
bb3be4 |
|
|
|
bb3be4 |
-static int
|
|
|
bb3be4 |
+static ptrdiff_t
|
|
|
bb3be4 |
find_section (const char *name, const char *section_names, const char *file_name,
|
|
|
bb3be4 |
- ElfW (Ehdr) *old_file_h, ElfW (Shdr) *old_section_h, int noerror)
|
|
|
bb3be4 |
+ ElfW (Ehdr) *old_file_h, ElfW (Shdr) *old_section_h,
|
|
|
bb3be4 |
+ bool noerror)
|
|
|
bb3be4 |
{
|
|
|
bb3be4 |
- int idx;
|
|
|
bb3be4 |
+ ptrdiff_t idx;
|
|
|
bb3be4 |
|
|
|
bb3be4 |
for (idx = 1; idx < old_file_h->e_shnum; idx++)
|
|
|
bb3be4 |
{
|
|
|
bb3be4 |
-#ifdef DEBUG
|
|
|
bb3be4 |
- fprintf (stderr, "Looking for %s - found %s\n", name,
|
|
|
bb3be4 |
- section_names + OLD_SECTION_H (idx).sh_name);
|
|
|
bb3be4 |
+ char const *found_name = section_names + OLD_SECTION_H (idx).sh_name;
|
|
|
bb3be4 |
+#ifdef UNEXELF_DEBUG
|
|
|
bb3be4 |
+ fprintf (stderr, "Looking for %s - found %s\n", name, found_name);
|
|
|
bb3be4 |
#endif
|
|
|
bb3be4 |
- if (!strcmp (section_names + OLD_SECTION_H (idx).sh_name,
|
|
|
bb3be4 |
- name))
|
|
|
bb3be4 |
- break;
|
|
|
bb3be4 |
- }
|
|
|
bb3be4 |
- if (idx == old_file_h->e_shnum)
|
|
|
bb3be4 |
- {
|
|
|
bb3be4 |
- if (noerror)
|
|
|
bb3be4 |
- return -1;
|
|
|
bb3be4 |
- else
|
|
|
bb3be4 |
- fatal ("Can't find %s in %s.\n", name, file_name);
|
|
|
bb3be4 |
+ if (strcmp (name, found_name) == 0)
|
|
|
bb3be4 |
+ return idx;
|
|
|
bb3be4 |
}
|
|
|
bb3be4 |
|
|
|
bb3be4 |
- return idx;
|
|
|
bb3be4 |
+ if (! noerror)
|
|
|
bb3be4 |
+ fatal ("Can't find %s in %s", name, file_name);
|
|
|
bb3be4 |
+ return -1;
|
|
|
bb3be4 |
}
|
|
|
bb3be4 |
|
|
|
bb3be4 |
/* ****************************************************************
|
|
|
bb3be4 |
@@ -616,11 +628,9 @@ find_section (const char *name, const char *section_names, const char *file_name
|
|
|
bb3be4 |
void
|
|
|
bb3be4 |
unexec (const char *new_name, const char *old_name)
|
|
|
bb3be4 |
{
|
|
|
bb3be4 |
- int new_file, old_file, new_file_size;
|
|
|
bb3be4 |
-
|
|
|
bb3be4 |
-#if defined (emacs) || !defined (DEBUG)
|
|
|
bb3be4 |
+ int new_file, old_file;
|
|
|
bb3be4 |
+ off_t new_file_size;
|
|
|
bb3be4 |
void *new_break;
|
|
|
bb3be4 |
-#endif
|
|
|
bb3be4 |
|
|
|
bb3be4 |
/* Pointers to the base of the image of the two files. */
|
|
|
bb3be4 |
caddr_t old_base, new_base;
|
|
|
bb3be4 |
@@ -647,30 +657,30 @@ unexec (const char *new_name, const char *old_name)
|
|
|
bb3be4 |
ElfW (Off) old_bss_offset;
|
|
|
bb3be4 |
ElfW (Word) new_data2_incr;
|
|
|
bb3be4 |
|
|
|
bb3be4 |
- int n, nn;
|
|
|
bb3be4 |
- int old_bss_index, old_sbss_index, old_plt_index;
|
|
|
bb3be4 |
- int old_data_index, new_data2_index;
|
|
|
bb3be4 |
+ ptrdiff_t n, nn;
|
|
|
bb3be4 |
+ ptrdiff_t old_bss_index, old_sbss_index, old_plt_index;
|
|
|
bb3be4 |
+ ptrdiff_t old_data_index, new_data2_index;
|
|
|
bb3be4 |
#if defined _SYSTYPE_SYSV || defined __sgi
|
|
|
bb3be4 |
- int old_mdebug_index;
|
|
|
bb3be4 |
+ ptrdiff_t old_mdebug_index;
|
|
|
bb3be4 |
#endif
|
|
|
bb3be4 |
struct stat stat_buf;
|
|
|
bb3be4 |
- int old_file_size;
|
|
|
bb3be4 |
+ off_t old_file_size;
|
|
|
bb3be4 |
|
|
|
bb3be4 |
/* Open the old file, allocate a buffer of the right size, and read
|
|
|
bb3be4 |
in the file contents. */
|
|
|
bb3be4 |
|
|
|
bb3be4 |
- old_file = open (old_name, O_RDONLY);
|
|
|
bb3be4 |
+ old_file = emacs_open (old_name, O_RDONLY, 0);
|
|
|
bb3be4 |
|
|
|
bb3be4 |
if (old_file < 0)
|
|
|
bb3be4 |
- fatal ("Can't open %s for reading: errno %d\n", old_name, errno);
|
|
|
bb3be4 |
+ fatal ("Can't open %s for reading: %s", old_name, strerror (errno));
|
|
|
bb3be4 |
|
|
|
bb3be4 |
- if (fstat (old_file, &stat_buf) == -1)
|
|
|
bb3be4 |
- fatal ("Can't fstat (%s): errno %d\n", old_name, errno);
|
|
|
bb3be4 |
+ if (fstat (old_file, &stat_buf) != 0)
|
|
|
bb3be4 |
+ fatal ("Can't fstat (%s): %s", old_name, strerror (errno));
|
|
|
bb3be4 |
|
|
|
bb3be4 |
#if MAP_ANON == 0
|
|
|
bb3be4 |
- mmap_fd = open ("/dev/zero", O_RDONLY);
|
|
|
bb3be4 |
+ mmap_fd = emacs_open ("/dev/zero", O_RDONLY, 0);
|
|
|
bb3be4 |
if (mmap_fd < 0)
|
|
|
bb3be4 |
- fatal ("Can't open /dev/zero for reading: errno %d\n", errno, 0);
|
|
|
bb3be4 |
+ fatal ("Can't open /dev/zero for reading: %s", strerror (errno));
|
|
|
bb3be4 |
#endif
|
|
|
bb3be4 |
|
|
|
bb3be4 |
/* We cannot use malloc here because that may use sbrk. If it does,
|
|
|
bb3be4 |
@@ -678,13 +688,15 @@ unexec (const char *new_name, const char *old_name)
|
|
|
bb3be4 |
extra careful to use the correct value of sbrk(0) after
|
|
|
bb3be4 |
allocating all buffers in the code below, which we aren't. */
|
|
|
bb3be4 |
old_file_size = stat_buf.st_size;
|
|
|
bb3be4 |
+ if (! (0 <= old_file_size && old_file_size <= SIZE_MAX))
|
|
|
bb3be4 |
+ fatal ("File size out of range");
|
|
|
bb3be4 |
old_base = mmap (NULL, old_file_size, PROT_READ | PROT_WRITE,
|
|
|
bb3be4 |
MAP_ANON | MAP_PRIVATE, mmap_fd, 0);
|
|
|
bb3be4 |
if (old_base == MAP_FAILED)
|
|
|
bb3be4 |
- fatal ("Can't allocate buffer for %s\n", old_name, 0);
|
|
|
bb3be4 |
+ fatal ("Can't allocate buffer for %s: %s", old_name, strerror (errno));
|
|
|
bb3be4 |
|
|
|
bb3be4 |
- if (read (old_file, old_base, stat_buf.st_size) != stat_buf.st_size)
|
|
|
bb3be4 |
- fatal ("Didn't read all of %s: errno %d\n", old_name, errno);
|
|
|
bb3be4 |
+ if (read (old_file, old_base, old_file_size) != old_file_size)
|
|
|
bb3be4 |
+ fatal ("Didn't read all of %s: %s", old_name, strerror (errno));
|
|
|
bb3be4 |
|
|
|
bb3be4 |
/* Get pointers to headers & section names */
|
|
|
bb3be4 |
|
|
|
bb3be4 |
@@ -755,12 +767,8 @@ unexec (const char *new_name, const char *old_name)
|
|
|
bb3be4 |
old_data_index = find_section (".data", old_section_names,
|
|
|
bb3be4 |
old_name, old_file_h, old_section_h, 0);
|
|
|
bb3be4 |
|
|
|
bb3be4 |
-#if defined (emacs) || !defined (DEBUG)
|
|
|
bb3be4 |
new_break = sbrk (0);
|
|
|
bb3be4 |
new_bss_addr = (ElfW (Addr)) new_break;
|
|
|
bb3be4 |
-#else
|
|
|
bb3be4 |
- new_bss_addr = old_bss_addr + old_bss_size + 0x1234;
|
|
|
bb3be4 |
-#endif
|
|
|
bb3be4 |
new_data2_addr = old_bss_addr;
|
|
|
bb3be4 |
new_data2_size = new_bss_addr - old_bss_addr;
|
|
|
bb3be4 |
new_data2_offset = OLD_SECTION_H (old_data_index).sh_offset
|
|
|
bb3be4 |
@@ -771,38 +779,38 @@ unexec (const char *new_name, const char *old_name)
|
|
|
bb3be4 |
section) was unaligned. */
|
|
|
bb3be4 |
new_data2_incr = new_data2_size + (new_data2_offset - old_bss_offset);
|
|
|
bb3be4 |
|
|
|
bb3be4 |
-#ifdef DEBUG
|
|
|
bb3be4 |
- fprintf (stderr, "old_bss_index %d\n", old_bss_index);
|
|
|
bb3be4 |
- fprintf (stderr, "old_bss_addr %x\n", old_bss_addr);
|
|
|
bb3be4 |
- fprintf (stderr, "old_bss_size %x\n", old_bss_size);
|
|
|
bb3be4 |
- fprintf (stderr, "old_bss_offset %x\n", old_bss_offset);
|
|
|
bb3be4 |
- fprintf (stderr, "new_bss_addr %x\n", new_bss_addr);
|
|
|
bb3be4 |
- fprintf (stderr, "new_data2_addr %x\n", new_data2_addr);
|
|
|
bb3be4 |
- fprintf (stderr, "new_data2_size %x\n", new_data2_size);
|
|
|
bb3be4 |
- fprintf (stderr, "new_data2_offset %x\n", new_data2_offset);
|
|
|
bb3be4 |
- fprintf (stderr, "new_data2_incr %x\n", new_data2_incr);
|
|
|
bb3be4 |
+#ifdef UNEXELF_DEBUG
|
|
|
bb3be4 |
+ fprintf (stderr, "old_bss_index %td\n", old_bss_index);
|
|
|
bb3be4 |
+ DEBUG_LOG (old_bss_addr);
|
|
|
bb3be4 |
+ DEBUG_LOG (old_bss_size);
|
|
|
bb3be4 |
+ DEBUG_LOG (old_bss_offset);
|
|
|
bb3be4 |
+ DEBUG_LOG (new_bss_addr);
|
|
|
bb3be4 |
+ DEBUG_LOG (new_data2_addr);
|
|
|
bb3be4 |
+ DEBUG_LOG (new_data2_size);
|
|
|
bb3be4 |
+ DEBUG_LOG (new_data2_offset);
|
|
|
bb3be4 |
+ DEBUG_LOG (new_data2_incr);
|
|
|
bb3be4 |
#endif
|
|
|
bb3be4 |
|
|
|
bb3be4 |
- if ((uintptr_t) new_bss_addr < (uintptr_t) old_bss_addr + old_bss_size)
|
|
|
bb3be4 |
- fatal (".bss shrank when undumping???\n", 0, 0);
|
|
|
bb3be4 |
+ if (new_bss_addr < old_bss_addr + old_bss_size)
|
|
|
bb3be4 |
+ fatal (".bss shrank when undumping");
|
|
|
bb3be4 |
|
|
|
bb3be4 |
/* Set the output file to the right size. Allocate a buffer to hold
|
|
|
bb3be4 |
the image of the new file. Set pointers to various interesting
|
|
|
bb3be4 |
- objects. stat_buf still has old_file data. */
|
|
|
bb3be4 |
+ objects. */
|
|
|
bb3be4 |
|
|
|
bb3be4 |
- new_file = open (new_name, O_RDWR | O_CREAT, 0666);
|
|
|
bb3be4 |
+ new_file = emacs_open (new_name, O_RDWR | O_CREAT, 0777);
|
|
|
bb3be4 |
if (new_file < 0)
|
|
|
bb3be4 |
- fatal ("Can't creat (%s): errno %d\n", new_name, errno);
|
|
|
bb3be4 |
+ fatal ("Can't creat (%s): %s", new_name, strerror (errno));
|
|
|
bb3be4 |
|
|
|
bb3be4 |
- new_file_size = stat_buf.st_size + old_file_h->e_shentsize + new_data2_incr;
|
|
|
bb3be4 |
+ new_file_size = old_file_size + old_file_h->e_shentsize + new_data2_incr;
|
|
|
bb3be4 |
|
|
|
bb3be4 |
if (ftruncate (new_file, new_file_size))
|
|
|
bb3be4 |
- fatal ("Can't ftruncate (%s): errno %d\n", new_name, errno);
|
|
|
bb3be4 |
+ fatal ("Can't ftruncate (%s): %s", new_name, strerror (errno));
|
|
|
bb3be4 |
|
|
|
bb3be4 |
new_base = mmap (NULL, new_file_size, PROT_READ | PROT_WRITE,
|
|
|
bb3be4 |
MAP_ANON | MAP_PRIVATE, mmap_fd, 0);
|
|
|
bb3be4 |
if (new_base == MAP_FAILED)
|
|
|
bb3be4 |
- fatal ("Can't allocate buffer for %s\n", old_name, 0);
|
|
|
bb3be4 |
+ fatal ("Can't allocate buffer for %s: %s", old_name, strerror (errno));
|
|
|
bb3be4 |
|
|
|
bb3be4 |
new_file_h = (ElfW (Ehdr) *) new_base;
|
|
|
bb3be4 |
new_program_h = (ElfW (Phdr) *) ((byte *) new_base + old_file_h->e_phoff);
|
|
|
bb3be4 |
@@ -825,11 +833,11 @@ unexec (const char *new_name, const char *old_name)
|
|
|
bb3be4 |
new_file_h->e_shoff += new_data2_incr;
|
|
|
bb3be4 |
new_file_h->e_shnum += 1;
|
|
|
bb3be4 |
|
|
|
bb3be4 |
-#ifdef DEBUG
|
|
|
bb3be4 |
- fprintf (stderr, "Old section offset %x\n", old_file_h->e_shoff);
|
|
|
bb3be4 |
- fprintf (stderr, "Old section count %d\n", old_file_h->e_shnum);
|
|
|
bb3be4 |
- fprintf (stderr, "New section offset %x\n", new_file_h->e_shoff);
|
|
|
bb3be4 |
- fprintf (stderr, "New section count %d\n", new_file_h->e_shnum);
|
|
|
bb3be4 |
+#ifdef UNEXELF_DEBUG
|
|
|
bb3be4 |
+ DEBUG_LOG (old_file_h->e_shoff);
|
|
|
bb3be4 |
+ fprintf (stderr, "Old section count %td\n", (ptrdiff_t) old_file_h->e_shnum);
|
|
|
bb3be4 |
+ DEBUG_LOG (new_file_h->e_shoff);
|
|
|
bb3be4 |
+ fprintf (stderr, "New section count %td\n", (ptrdiff_t) new_file_h->e_shnum);
|
|
|
bb3be4 |
#endif
|
|
|
bb3be4 |
|
|
|
bb3be4 |
/* Fix up a new program header. Extend the writable data segment so
|
|
|
bb3be4 |
@@ -839,7 +847,7 @@ unexec (const char *new_name, const char *old_name)
|
|
|
bb3be4 |
to adjust the offset and address of any segment that is above
|
|
|
bb3be4 |
data2, just in case we decide to allow this later. */
|
|
|
bb3be4 |
|
|
|
bb3be4 |
- for (n = new_file_h->e_phnum - 1; n >= 0; n--)
|
|
|
bb3be4 |
+ for (n = new_file_h->e_phnum; --n >= 0; )
|
|
|
bb3be4 |
{
|
|
|
bb3be4 |
/* Compute maximum of all requirements for alignment of section. */
|
|
|
bb3be4 |
ElfW (Word) alignment = (NEW_PROGRAM_H (n)).p_align;
|
|
|
bb3be4 |
@@ -857,7 +865,7 @@ unexec (const char *new_name, const char *old_name)
|
|
|
bb3be4 |
> (old_sbss_index == -1
|
|
|
bb3be4 |
? old_bss_addr
|
|
|
bb3be4 |
: round_up (old_bss_addr, alignment)))
|
|
|
bb3be4 |
- fatal ("Program segment above .bss in %s\n", old_name, 0);
|
|
|
bb3be4 |
+ fatal ("Program segment above .bss in %s", old_name);
|
|
|
bb3be4 |
|
|
|
bb3be4 |
if (NEW_PROGRAM_H (n).p_type == PT_LOAD
|
|
|
bb3be4 |
&& (round_up ((NEW_PROGRAM_H (n)).p_vaddr
|
|
|
bb3be4 |
@@ -867,7 +875,7 @@ unexec (const char *new_name, const char *old_name)
|
|
|
bb3be4 |
break;
|
|
|
bb3be4 |
}
|
|
|
bb3be4 |
if (n < 0)
|
|
|
bb3be4 |
- fatal ("Couldn't find segment next to .bss in %s\n", old_name, 0);
|
|
|
bb3be4 |
+ fatal ("Couldn't find segment next to .bss in %s", old_name);
|
|
|
bb3be4 |
|
|
|
bb3be4 |
/* Make sure that the size includes any padding before the old .bss
|
|
|
bb3be4 |
section. */
|
|
|
bb3be4 |
@@ -875,7 +883,7 @@ unexec (const char *new_name, const char *old_name)
|
|
|
bb3be4 |
NEW_PROGRAM_H (n).p_memsz = NEW_PROGRAM_H (n).p_filesz;
|
|
|
bb3be4 |
|
|
|
bb3be4 |
#if 0 /* Maybe allow section after data2 - does this ever happen? */
|
|
|
bb3be4 |
- for (n = new_file_h->e_phnum - 1; n >= 0; n--)
|
|
|
bb3be4 |
+ for (n = new_file_h->e_phnum; --n >= 0; )
|
|
|
bb3be4 |
{
|
|
|
bb3be4 |
if (NEW_PROGRAM_H (n).p_vaddr
|
|
|
bb3be4 |
&& NEW_PROGRAM_H (n).p_vaddr >= new_data2_addr)
|
|
|
bb3be4 |
@@ -894,7 +902,7 @@ unexec (const char *new_name, const char *old_name)
|
|
|
bb3be4 |
|
|
|
bb3be4 |
/* Walk through all section headers, insert the new data2 section right
|
|
|
bb3be4 |
before the new bss section. */
|
|
|
bb3be4 |
- for (n = 1, nn = 1; n < (int) old_file_h->e_shnum; n++, nn++)
|
|
|
bb3be4 |
+ for (n = 1, nn = 1; n < old_file_h->e_shnum; n++, nn++)
|
|
|
bb3be4 |
{
|
|
|
bb3be4 |
caddr_t src;
|
|
|
bb3be4 |
/* If it is (s)bss section, insert the new data2 section before it. */
|
|
|
bb3be4 |
@@ -1076,8 +1084,9 @@ temacs:
|
|
|
bb3be4 |
if (NEW_SECTION_H (nn).sh_type == SHT_MIPS_DEBUG
|
|
|
bb3be4 |
&& old_mdebug_index != -1)
|
|
|
bb3be4 |
{
|
|
|
bb3be4 |
- int diff = NEW_SECTION_H (nn).sh_offset
|
|
|
bb3be4 |
- - OLD_SECTION_H (old_mdebug_index).sh_offset;
|
|
|
bb3be4 |
+ ptrdiff_t new_offset = NEW_SECTION_H (nn).sh_offset;
|
|
|
bb3be4 |
+ ptrdiff_t old_offset = OLD_SECTION_H (old_mdebug_index).sh_offset;
|
|
|
bb3be4 |
+ ptrdiff_t diff = new_offset - old_offset;
|
|
|
bb3be4 |
HDRR *phdr = (HDRR *)(NEW_SECTION_H (nn).sh_offset + new_base);
|
|
|
bb3be4 |
|
|
|
bb3be4 |
if (diff)
|
|
|
bb3be4 |
@@ -1157,7 +1166,7 @@ temacs:
|
|
|
bb3be4 |
|| NEW_SECTION_H (nn).sh_type == SHT_DYNSYM)
|
|
|
bb3be4 |
{
|
|
|
bb3be4 |
ElfW (Shdr) *spt = &NEW_SECTION_H (nn);
|
|
|
bb3be4 |
- unsigned int num = spt->sh_size / spt->sh_entsize;
|
|
|
bb3be4 |
+ ptrdiff_t num = spt->sh_size / spt->sh_entsize;
|
|
|
bb3be4 |
ElfW (Sym) * sym = (ElfW (Sym) *) (NEW_SECTION_H (nn).sh_offset +
|
|
|
bb3be4 |
new_base);
|
|
|
bb3be4 |
for (; num--; sym++)
|
|
|
bb3be4 |
@@ -1173,7 +1182,7 @@ temacs:
|
|
|
bb3be4 |
}
|
|
|
bb3be4 |
|
|
|
bb3be4 |
/* Update the symbol values of _edata and _end. */
|
|
|
bb3be4 |
- for (n = new_file_h->e_shnum - 1; n; n--)
|
|
|
bb3be4 |
+ for (n = new_file_h->e_shnum; 0 < --n; )
|
|
|
bb3be4 |
{
|
|
|
bb3be4 |
byte *symnames;
|
|
|
bb3be4 |
ElfW (Sym) *symp, *symendp;
|
|
|
bb3be4 |
@@ -1233,7 +1242,7 @@ temacs:
|
|
|
bb3be4 |
|
|
|
bb3be4 |
/* This loop seeks out relocation sections for the data section, so
|
|
|
bb3be4 |
that it can undo relocations performed by the runtime linker. */
|
|
|
bb3be4 |
- for (n = new_file_h->e_shnum - 1; n; n--)
|
|
|
bb3be4 |
+ for (n = new_file_h->e_shnum; 0 < --n; )
|
|
|
bb3be4 |
{
|
|
|
bb3be4 |
ElfW (Shdr) section = NEW_SECTION_H (n);
|
|
|
bb3be4 |
|
|
|
bb3be4 |
@@ -1293,29 +1302,20 @@ temacs:
|
|
|
bb3be4 |
/* Write out new_file, and free the buffers. */
|
|
|
bb3be4 |
|
|
|
bb3be4 |
if (write (new_file, new_base, new_file_size) != new_file_size)
|
|
|
bb3be4 |
- fatal ("Didn't write %d bytes to %s: errno %d\n",
|
|
|
bb3be4 |
- new_file_size, new_name, errno);
|
|
|
bb3be4 |
+ fatal ("Didn't write %lu bytes to %s: %s",
|
|
|
bb3be4 |
+ (unsigned long) new_file_size, new_name, strerror (errno));
|
|
|
bb3be4 |
munmap (old_base, old_file_size);
|
|
|
bb3be4 |
munmap (new_base, new_file_size);
|
|
|
bb3be4 |
|
|
|
bb3be4 |
/* Close the files and make the new file executable. */
|
|
|
bb3be4 |
|
|
|
bb3be4 |
#if MAP_ANON == 0
|
|
|
bb3be4 |
- close (mmap_fd);
|
|
|
bb3be4 |
+ emacs_close (mmap_fd);
|
|
|
bb3be4 |
#endif
|
|
|
bb3be4 |
|
|
|
bb3be4 |
- if (close (old_file))
|
|
|
bb3be4 |
- fatal ("Can't close (%s): errno %d\n", old_name, errno);
|
|
|
bb3be4 |
-
|
|
|
bb3be4 |
- if (close (new_file))
|
|
|
bb3be4 |
- fatal ("Can't close (%s): errno %d\n", new_name, errno);
|
|
|
bb3be4 |
-
|
|
|
bb3be4 |
- if (stat (new_name, &stat_buf) == -1)
|
|
|
bb3be4 |
- fatal ("Can't stat (%s): errno %d\n", new_name, errno);
|
|
|
bb3be4 |
+ if (emacs_close (old_file) != 0)
|
|
|
bb3be4 |
+ fatal ("Can't close (%s): %s", old_name, strerror (errno));
|
|
|
bb3be4 |
|
|
|
bb3be4 |
- n = umask (777);
|
|
|
bb3be4 |
- umask (n);
|
|
|
bb3be4 |
- stat_buf.st_mode |= 0111 & ~n;
|
|
|
bb3be4 |
- if (chmod (new_name, stat_buf.st_mode) == -1)
|
|
|
bb3be4 |
- fatal ("Can't chmod (%s): errno %d\n", new_name, errno);
|
|
|
bb3be4 |
+ if (emacs_close (new_file) != 0)
|
|
|
bb3be4 |
+ fatal ("Can't close (%s): %s", new_name, strerror (errno));
|
|
|
bb3be4 |
}
|
|
|
bb3be4 |
--
|
|
|
bb3be4 |
2.7.4
|
|
|
bb3be4 |
|