summaryrefslogtreecommitdiff
path: root/src/unexmacosx.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/unexmacosx.c')
-rw-r--r--src/unexmacosx.c55
1 files changed, 28 insertions, 27 deletions
diff --git a/src/unexmacosx.c b/src/unexmacosx.c
index 7fb5750cef2..be1ef43e62c 100644
--- a/src/unexmacosx.c
+++ b/src/unexmacosx.c
@@ -1,5 +1,5 @@
/* Dump Emacs in Mach-O format for use on macOS.
- Copyright (C) 2001-2017 Free Software Foundation, Inc.
+ Copyright (C) 2001-2022 Free Software Foundation, Inc.
This file is part of GNU Emacs.
@@ -97,9 +97,9 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
#include "unexec.h"
#include "lisp.h"
+#include "sysstdio.h"
#include <errno.h>
-#include <stdio.h>
#include <fcntl.h>
#include <stdarg.h>
#include <stdint.h>
@@ -303,9 +303,9 @@ unexec_error (const char *format, ...)
va_list ap;
va_start (ap, format);
- fprintf (stderr, "unexec: ");
+ fputs ("unexec: ", stderr);
vfprintf (stderr, format, ap);
- fprintf (stderr, "\n");
+ putc ('\n', stderr);
va_end (ap);
exit (1);
}
@@ -503,22 +503,34 @@ unexec_regions_sort_compare (const void *a, const void *b)
static void
unexec_regions_merge (void)
{
- int i, n;
- unexec_region_info r;
- vm_size_t padsize;
-
qsort (unexec_regions, num_unexec_regions, sizeof (unexec_regions[0]),
&unexec_regions_sort_compare);
- n = 0;
- r = unexec_regions[0];
- padsize = r.range.address & (pagesize - 1);
- if (padsize)
+
+ /* Align each region start address to a page boundary. */
+ for (unexec_region_info *cur = unexec_regions;
+ cur < unexec_regions + num_unexec_regions; cur++)
{
- r.range.address -= padsize;
- r.range.size += padsize;
- r.filesize += padsize;
+ vm_size_t padsize = cur->range.address & (pagesize - 1);
+ if (padsize)
+ {
+ cur->range.address -= padsize;
+ cur->range.size += padsize;
+ cur->filesize += padsize;
+
+ unexec_region_info *prev = cur == unexec_regions ? NULL : cur - 1;
+ if (prev
+ && prev->range.address + prev->range.size > cur->range.address)
+ {
+ prev->range.size = cur->range.address - prev->range.address;
+ if (prev->filesize > prev->range.size)
+ prev->filesize = prev->range.size;
+ }
+ }
}
- for (i = 1; i < num_unexec_regions; i++)
+
+ int n = 0;
+ unexec_region_info r = unexec_regions[0];
+ for (int i = 1; i < num_unexec_regions; i++)
{
if (r.range.address + r.range.size == unexec_regions[i].range.address
&& r.range.size - r.filesize < 2 * pagesize)
@@ -530,17 +542,6 @@ unexec_regions_merge (void)
{
unexec_regions[n++] = r;
r = unexec_regions[i];
- padsize = r.range.address & (pagesize - 1);
- if (padsize)
- {
- if ((unexec_regions[n-1].range.address
- + unexec_regions[n-1].range.size) == r.range.address)
- unexec_regions[n-1].range.size -= padsize;
-
- r.range.address -= padsize;
- r.range.size += padsize;
- r.filesize += padsize;
- }
}
}
unexec_regions[n++] = r;