-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfix-emacs25.3-unexmacosx.c.patch
108 lines (102 loc) · 3.26 KB
/
fix-emacs25.3-unexmacosx.c.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
diff --git a/src/unexmacosx.c b/src/unexmacosx.c
index 53a30e3627..59cbe3c18b 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-2020 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);
}
@@ -447,7 +447,7 @@ unexec_regions_recorder (task_t task, void *rr, unsigned type,
while (num && num_unexec_regions < MAX_UNEXEC_REGIONS)
{
- /* Subtract the size of trailing null bytes from filesize. It
+ /* Subtract the size of trailing NUL bytes from filesize. It
can be smaller than vmsize in segment commands. In such a
case, trailing bytes are initialized with zeros. */
for (p = ranges->address + ranges->size; p > ranges->address; p--)
@@ -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;