summaryrefslogtreecommitdiff
path: root/src/unexmacosx.c
diff options
context:
space:
mode:
authorAndrew Choi <akochoi@shaw.ca>2003-07-22 17:54:50 +0000
committerAndrew Choi <akochoi@shaw.ca>2003-07-22 17:54:50 +0000
commit39e2c1fb1a1f5bb53b874dd8fadd5dee17492d04 (patch)
treef22526444412ce462a02e76f3719794dfa0f6fe2 /src/unexmacosx.c
parent14126d74c8cd582bc3c7a30d1f0a59f36484716c (diff)
downloademacs-39e2c1fb1a1f5bb53b874dd8fadd5dee17492d04.tar.gz
unexmacosx.c: Sort and merge unexec regions before dumping them.
Diffstat (limited to 'src/unexmacosx.c')
-rw-r--r--src/unexmacosx.c43
1 files changed, 42 insertions, 1 deletions
diff --git a/src/unexmacosx.c b/src/unexmacosx.c
index ac87f9e6c63..c84e5c95d03 100644
--- a/src/unexmacosx.c
+++ b/src/unexmacosx.c
@@ -364,7 +364,7 @@ build_region_list ()
}
-#define MAX_UNEXEC_REGIONS 30
+#define MAX_UNEXEC_REGIONS 200
int num_unexec_regions;
vm_range_t unexec_regions[MAX_UNEXEC_REGIONS];
@@ -403,6 +403,46 @@ find_emacs_zone_regions ()
unexec_regions_recorder);
}
+static int
+unexec_regions_sort_compare (const void *a, const void *b)
+{
+ vm_address_t aa = ((vm_range_t *) a)->address;
+ vm_address_t bb = ((vm_range_t *) b)->address;
+
+ if (aa < bb)
+ return -1;
+ else if (aa > bb)
+ return 1;
+ else
+ return 0;
+}
+
+static void
+unexec_regions_merge ()
+{
+ int i, n;
+ vm_range_t r;
+
+ qsort (unexec_regions, num_unexec_regions, sizeof (unexec_regions[0]),
+ &unexec_regions_sort_compare);
+ n = 0;
+ r = unexec_regions[0];
+ for (i = 1; i < num_unexec_regions; i++)
+ {
+ if (r.address + r.size == unexec_regions[i].address)
+ {
+ r.size += unexec_regions[i].size;
+ }
+ else
+ {
+ unexec_regions[n++] = r;
+ r = unexec_regions[i];
+ }
+ }
+ unexec_regions[n++] = r;
+ num_unexec_regions = n;
+}
+
/* More informational messages routines. */
@@ -863,6 +903,7 @@ unexec (char *outfile, char *infile, void *start_data, void *start_bss,
read_load_commands ();
find_emacs_zone_regions ();
+ unexec_regions_merge ();
in_dumped_exec = 1;