source: trunk/dports/editors/emacs/files/apple-patches @ 21478

Last change on this file since 21478 was 21478, checked in by eridius@…, 13 years ago

Massive update to svn properties on files:
All patchfiles have svn:eol-style removed.
All files that are not in fact able to be executed have svn:executable removed
All binary files have svn:eol-style removed (and are probably corrupt)
All binary files have svn:mime-type set to application/octet-stream
All files which are not patchfiles or binary files have svn:eol-style set to native
All Portfiles have svn:eol-style set to native and svn:executable removed

File size: 53.8 KB
Line 
1Index: emacs/Makefile.in
2===================================================================
3RCS file: /cvs/Darwin/src/live/emacs/emacs/Makefile.in,v
4retrieving revision 1.1.1.7
5retrieving revision 1.7
6diff -u -r1.1.1.7 -r1.7
7--- Makefile.in 2002/09/10 23:31:56     1.1.1.7
8+++ Makefile.in 2002/09/11 01:34:01     1.7
9@@ -329,7 +329,6 @@
10            libexecdir=${libexecdir} archlibdir=${archlibdir} \
11            INSTALL_STRIP=${INSTALL_STRIP})
12        ${INSTALL_PROGRAM} $(INSTALL_STRIP) src/emacs ${bindir}/emacs-${version}
13-       -chmod 1755  ${bindir}/emacs-${version}
14        rm -f ${bindir}/$(EMACS)
15        -ln ${bindir}/emacs-${version} ${bindir}/$(EMACS)
16        -unset CDPATH; \
17@@ -447,7 +446,7 @@
18        -chmod -R a+r ${datadir}/emacs ${COPYDESTS} ${infodir}
19        thisdir=`/bin/pwd`; \
20        cd ${srcdir}/etc; \
21-       for page in emacs etags ctags gfdl ; do \
22+       for page in emacs etags gfdl ; do \
23          (cd $${thisdir}; \
24           ${INSTALL_DATA} ${srcdir}/etc/$${page}.1 ${man1dir}/$${page}${manext}; \
25           chmod a+r ${man1dir}/$${page}${manext}); \
26Index: emacs/lib-src/Makefile.in
27===================================================================
28RCS file: /cvs/Darwin/src/live/emacs/emacs/lib-src/Makefile.in,v
29retrieving revision 1.1.1.6
30retrieving revision 1.4
31diff -u -r1.1.1.6 -r1.4
32--- Makefile.in 2001/10/31 17:59:51     1.1.1.6
33+++ Makefile.in 2001/12/13 02:44:29     1.4
34@@ -92,7 +92,7 @@
35 
36 # Things that a user might actually run,
37 # which should be installed in bindir.
38-INSTALLABLES = etags ctags emacsclient b2m ebrowse
39+INSTALLABLES = etags emacsclient b2m ebrowse
40 INSTALLABLE_SCRIPTS = rcs-checkin grep-changelog
41 
42 # Things that Emacs runs internally, or during the build process,
43Index: emacs/lisp/abbrev.elc
44===================================================================
45RCS file: abbrev.elc
46diff -N abbrev.elc
47Binary files /dev/null and /tmp/cvs000907 differ
48Index: emacs/lisp/abbrevlist.elc
49===================================================================
50RCS file: abbrevlist.elc
51diff -N abbrevlist.elc
52Binary files /dev/null and /tmp/cvs000907 differ
53Index: emacs/lisp/add-log.elc
54===================================================================
55RCS file: add-log.elc
56diff -N add-log.elc
57Binary files /dev/null and /tmp/cvs000907 differ
58Index: emacs/lisp/align.elc
59===================================================================
60RCS file: align.elc
61diff -N align.elc
62Binary files /dev/null and /tmp/cvs000907 differ
63Index: emacs/lisp/site-init.el
64===================================================================
65RCS file: site-init.el
66diff -N site-init.el
67--- emacs/lisp/site-init.el     Tue Sep 17 14:45:13 2002
68+++ /tmp/cvs000907      Tue Sep 17 16:29:04 2002
69@@ -0,0 +1,4 @@
70+;; gnuserv setup.
71+(autoload 'gnuserv-start "gnuserv-compat"
72+  "Allow this Emacs process to be a server for client processes."
73+  t)
74Index: emacs/man/Makefile.in
75===================================================================
76RCS file: /cvs/Darwin/src/live/emacs/emacs/man/Makefile.in,v
77retrieving revision 1.1.1.7
78retrieving revision 1.3
79diff -u -r1.1.1.7 -r1.3
80--- Makefile.in 2002/09/10 23:34:32     1.1.1.7
81+++ Makefile.in 2002/09/11 01:34:03     1.3
82@@ -31,7 +31,7 @@
83 
84 
85 # The makeinfo program is part of the Texinfo distribution.
86-MAKEINFO = makeinfo
87+MAKEINFO = echo makeinfo
88 INFO_TARGETS = ../info/emacs ../info/ccmode ../info/cl \
89                ../info/dired-x ../info/ediff ../info/forms ../info/gnus \
90                ../info/info ../info/message ../info/mh-e ../info/reftex \
91Index: emacs/src/emacs.c
92===================================================================
93RCS file: /cvs/Darwin/src/live/emacs/emacs/src/emacs.c,v
94retrieving revision 1.1.1.7
95retrieving revision 1.10
96diff -u -r1.1.1.7 -r1.10
97--- emacs.c     2002/09/10 23:34:58     1.1.1.7
98+++ emacs.c     2002/09/11 01:34:03     1.10
99@@ -779,15 +779,20 @@
100     }
101 #endif
102 
103-#ifdef NeXT
104+#if defined(NeXT) || defined(RHAPSODY) || defined(DARWIN)
105   {
106     extern int malloc_cookie;
107-    /* This helps out unexnext.c.  */
108+    /* This helps out unexnext.c/unexdyld.c. */
109     if (initialized)
110-      if (malloc_jumpstart (malloc_cookie) != 0)
111-       printf ("malloc jumpstart failed!\n");
112+      {
113+       if (malloc_jumpstart (malloc_cookie) != 0)
114+         {
115+           fprintf (stderr, "Fatal malloc_jumpstart() error\n");
116+           exit (1);
117+         }
118+      }
119   }
120-#endif /* NeXT */
121+#endif /* NeXT || RHAPSODY || DARWIN */
122 
123 #ifdef VMS
124   /* If -map specified, map the data file in */
125@@ -1466,7 +1471,7 @@
126 #ifdef VMS
127   init_vmsfns ();
128 #endif /* VMS */
129-  init_process ();
130+  init_emacs_process ();
131 #ifdef HAVE_SOUND
132   init_sound ();
133 #endif
134Index: emacs/src/floatfns.c
135===================================================================
136RCS file: /cvs/Darwin/src/live/emacs/emacs/src/floatfns.c,v
137retrieving revision 1.1.1.7
138retrieving revision 1.4
139diff -u -r1.1.1.7 -r1.4
140--- floatfns.c  2002/09/10 23:34:59     1.1.1.7
141+++ floatfns.c  2002/09/11 01:34:04     1.4
142@@ -978,6 +978,9 @@
143 #endif /* FLOAT_CATCH_SIGILL */
144 
145 #ifdef HAVE_MATHERR
146+#ifdef __APPLE_CC__
147+__private_extern__
148+#endif
149 int
150 matherr (x)
151      struct exception *x;
152Index: emacs/src/getloadavg.c
153===================================================================
154RCS file: /cvs/Darwin/src/live/emacs/emacs/src/getloadavg.c,v
155retrieving revision 1.1.1.6
156retrieving revision 1.4
157diff -u -r1.1.1.6 -r1.4
158--- getloadavg.c        2001/10/31 17:58:36     1.1.1.6
159+++ getloadavg.c        2001/10/31 19:00:48     1.4
160@@ -54,6 +54,8 @@
161    hpux
162    __MSDOS__                   No-op for MSDOS.
163    NeXT
164+   RHAPSODY                    Mac OS X Server
165+   DARWIN                      Darwin (Mac OS)
166    sgi
167    sequent                     Sequent Dynix 3.x.x (BSD)
168    _SEQUENT_                   Sequent DYNIX/ptx 1.x.x (SYSV)
169@@ -401,7 +403,7 @@
170 #  define host_self mach_host_self
171 # endif
172 
173-# ifdef NeXT
174+# if defined(NeXT) || defined(RHAPSODY) || defined(DARWIN)
175 #  ifdef HAVE_MACH_MACH_H
176 #   include <mach/mach.h>
177 #  else
178@@ -449,7 +451,7 @@
179 
180 /* Avoid static vars inside a function since in HPUX they dump as pure.  */
181 
182-# ifdef NeXT
183+# if defined(NeXT) || defined(RHAPSODY) || defined(DARWIN)
184 static processor_set_t default_set;
185 static int getloadavg_initialized;
186 # endif /* NeXT */
187@@ -486,6 +488,9 @@
188    Return the number written (never more than 3, but may be less than NELEM),
189    or -1 if an error occurred.  */
190 
191+#ifdef __APPLE_CC__
192+__private_extern__
193+#endif
194 int
195 getloadavg (loadavg, nelem)
196      double loadavg[];
197@@ -626,14 +631,10 @@
198 
199 # endif /* __NetBSD__ */
200 
201-# if !defined (LDAV_DONE) && defined (NeXT)
202+# if !defined (LDAV_DONE) && (defined(NeXT) || defined(RHAPSODY) || defined(DARWIN))
203 #  define LDAV_DONE
204   /* The NeXT code was adapted from iscreen 3.2.  */
205 
206-  host_t host;
207-  struct processor_set_basic_info info;
208-  unsigned info_count;
209-
210   /* We only know how to get the 1-minute average for this system,
211      so even if the caller asks for more than 1, we only return 1.  */
212 
213@@ -643,10 +644,19 @@
214        getloadavg_initialized = 1;
215     }
216 
217+#ifndef DARWIN
218+#define processor_set_load_info processor_set_basic_info
219+#define PROCESSOR_SET_LOAD_INFO PROCESSOR_SET_BASIC_INFO
220+#define PROCESSOR_SET_LOAD_INFO_COUNT PROCESSOR_SET_BASIC_INFO_COUNT
221+#endif
222+
223   if (getloadavg_initialized)
224     {
225-      info_count = PROCESSOR_SET_BASIC_INFO_COUNT;
226-      if (processor_set_info (default_set, PROCESSOR_SET_BASIC_INFO, &host,
227+      struct processor_set_load_info info;
228+      host_t host;
229+      unsigned info_count = PROCESSOR_SET_LOAD_INFO_COUNT;
230+
231+      if (processor_set_info (default_set, PROCESSOR_SET_LOAD_INFO, &host,
232                              (processor_set_info_t) &info, &info_count)
233          != KERN_SUCCESS)
234        getloadavg_initialized = 0;
235Index: emacs/src/lisp.h
236===================================================================
237RCS file: /cvs/Darwin/src/live/emacs/emacs/src/lisp.h,v
238retrieving revision 1.1.1.7
239retrieving revision 1.4
240diff -u -r1.1.1.7 -r1.4
241--- lisp.h      2002/09/10 23:35:02     1.1.1.7
242+++ lisp.h      2002/09/11 01:34:04     1.4
243@@ -2770,7 +2770,7 @@
244 extern void close_process_descs P_ ((void));
245 extern void status_notify P_ ((void));
246 extern int read_process_output P_ ((Lisp_Object, int));
247-extern void init_process P_ ((void));
248+extern void init_emacs_process P_ ((void));
249 extern void syms_of_process P_ ((void));
250 
251 /* defined in callproc.c */
252Index: emacs/src/process.c
253===================================================================
254RCS file: /cvs/Darwin/src/live/emacs/emacs/src/process.c,v
255retrieving revision 1.1.1.7
256retrieving revision 1.6
257diff -u -r1.1.1.7 -r1.6
258--- process.c   2002/09/10 23:35:04     1.1.1.7
259+++ process.c   2002/09/11 01:34:04     1.6
260@@ -1482,7 +1482,11 @@
261     current_dir = ENCODE_FILE (current_dir);
262 
263 #ifndef WINDOWSNT
264+#ifndef PUMA_VFORK_ISSUES_CLEARED_UP
265+    pid = fork ();
266+#else
267     pid = vfork ();
268+#endif
269     if (pid == 0)
270 #endif /* not WINDOWSNT */
271       {
272@@ -4604,7 +4608,7 @@
273 }
274 
275 void
276-init_process ()
277+init_emacs_process ()
278 {
279   register int i;
280 
281@@ -5003,7 +5007,7 @@
282 }
283 
284 void
285-init_process ()
286+init_emacs_process ()
287 {
288 }
289 
290Index: emacs/src/regex.c
291===================================================================
292RCS file: /cvs/Darwin/src/live/emacs/emacs/src/regex.c,v
293retrieving revision 1.1.1.7
294retrieving revision 1.4
295diff -u -r1.1.1.7 -r1.4
296Index: emacs/src/sysdep.c
297===================================================================
298RCS file: /cvs/Darwin/src/live/emacs/emacs/src/sysdep.c,v
299retrieving revision 1.1.1.5
300retrieving revision 1.4
301diff -u -r1.1.1.5 -r1.4
302--- sysdep.c    2002/09/10 23:35:06     1.1.1.5
303+++ sysdep.c    2002/09/11 01:34:04     1.4
304@@ -813,7 +813,12 @@
305   synch_process_alive = 1;
306 #endif /* __DJGPP__ > 1 */
307 #else 
308+#ifndef PUMA_VFORK_ISSUES_CLEARED_UP
309+  pid = fork ();
310+#else
311   pid = vfork ();
312+#endif
313+
314   if (pid == -1)
315     error ("Can't spawn subshell");
316 #endif
317Index: emacs/src/term.c
318===================================================================
319RCS file: /cvs/Darwin/src/live/emacs/emacs/src/term.c,v
320retrieving revision 1.1.1.6
321retrieving revision 1.3
322diff -u -r1.1.1.6 -r1.3
323Index: emacs/src/termcap.c
324===================================================================
325RCS file: /cvs/Darwin/src/live/emacs/emacs/src/termcap.c,v
326retrieving revision 1.1.1.6
327retrieving revision 1.6
328diff -u -r1.1.1.6 -r1.6
329--- termcap.c   2001/10/31 17:58:46     1.1.1.6
330+++ termcap.c   2002/01/08 02:38:33     1.6
331@@ -144,6 +144,9 @@
332   return NULL;
333 }
334 
335+#ifdef __APPLE_CC__
336+__private_extern__
337+#endif
338 int
339 tgetnum (cap)
340      char *cap;
341@@ -154,6 +157,9 @@
342   return atoi (ptr);
343 }
344 
345+#ifdef __APPLE_CC__
346+__private_extern__
347+#endif
348 int
349 tgetflag (cap)
350      char *cap;
351@@ -167,6 +173,9 @@
352    to store the string.  That pointer is advanced over the space used.
353    If AREA is null, space is allocated with `malloc'.  */
354 
355+#ifdef __APPLE_CC__
356+__private_extern__
357+#endif
358 char *
359 tgetstr (cap, area)
360      char *cap;
361@@ -311,6 +320,9 @@
362 
363 #endif /* 0  */
364 
365+#ifdef __APPLE_CC__
366+__private_extern__
367+#endif
368 void
369 tputs (str, nlines, outfun)
370      register char *str;
371@@ -436,6 +448,9 @@
372    0 if the data base is accessible but the type NAME is not defined
373    in it, and some other value otherwise.  */
374 
375+#ifdef __APPLE_CC__
376+__private_extern__
377+#endif
378 int
379 tgetent (bp, name)
380      char *bp, *name;
381Index: emacs/src/tparam.c
382===================================================================
383RCS file: /cvs/Darwin/src/live/emacs/emacs/src/tparam.c,v
384retrieving revision 1.1.1.6
385retrieving revision 1.5
386diff -u -r1.1.1.6 -r1.5
387--- tparam.c    2001/10/31 17:58:47     1.1.1.6
388+++ tparam.c    2002/01/08 02:38:33     1.5
389@@ -110,6 +110,9 @@
390 
391 static char tgoto_buf[50];
392 
393+#ifdef __APPLE_CC__
394+__private_extern__
395+#endif
396 char *
397 tgoto (cm, hpos, vpos)
398      char *cm;
399Index: emacs/src/unexdyld.c
400===================================================================
401RCS file: unexdyld.c
402diff -N unexdyld.c
403--- emacs/src/unexdyld.c        Tue Sep 17 14:45:13 2002
404+++ /tmp/cvs000907      Tue Sep 17 16:29:09 2002
405@@ -0,0 +1,996 @@
406+/* Dump Emacs in macho format.
407+   Copyright (C) 1990, 1993 Free Software Foundation, Inc.
408+   Derived from unexnext.c by Bradley Taylor (btaylor@next.com).
409+
410+This file is part of GNU Emacs.
411+
412+GNU Emacs is free software; you can redistribute it and/or modify
413+it under the terms of the GNU General Public License as published by
414+the Free Software Foundation; either version 2, or (at your option)
415+any later version.
416+
417+GNU Emacs is distributed in the hope that it will be useful,
418+but WITHOUT ANY WARRANTY; without even the implied warranty of
419+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
420+GNU General Public License for more details.
421+
422+You should have received a copy of the GNU General Public License
423+along with GNU Emacs; see the file COPYING.  If not, write to
424+the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
425+Boston, MA 02111-1307, USA.  */
426+
427+#include "config.h"
428+#include <stdio.h>
429+#ifdef HAVE_UNISTD_H
430+#include <unistd.h>
431+#endif
432+#include <libc.h>
433+#include <mach-o/nlist.h>
434+#include <mach/mach.h>
435+#ifndef NeXT
436+#include <mach/machine/vm_param.h>
437+#endif
438+#include <mach-o/ldsyms.h>
439+#include <mach-o/loader.h>
440+#include <mach-o/reloc.h>
441+
442+extern int malloc_freezedry (void);
443+
444+int malloc_cookie;
445+
446+#define VERBOSE
447+
448+#ifdef VERBOSE
449+#define SHOW_MCOPY_WRITES
450+#define SHOW_MCOPY_READS
451+#endif
452+
453+typedef struct region_t
454+{
455+  struct region_t *next;
456+  vm_address_t address;
457+  vm_size_t size;
458+  vm_prot_t protection;
459+  vm_prot_t max_protection;
460+
461+  /* And some info about where it was written to disk. */
462+  unsigned long file_offset;
463+  unsigned long file_size;
464+} region_t;
465+
466+typedef struct section_list_t
467+{
468+  struct section_list_t *next;
469+  struct section section;
470+} section_list_t;
471+
472+static void fatal_unexec (char *format, ...)
473+{
474+  va_list ap;
475+   
476+  va_start (ap, format);
477+  fprintf (stderr, "unexec: ");
478+  vfprintf (stderr, format, ap);
479+  fprintf (stderr, "\n");
480+  va_end (ap);
481+  exit (1);
482+}
483+
484+static void print_region (struct region_t *region)
485+{
486+  printf ("0x%8lx - 0x%8lx, length: 0x%8lx, protection: %c%c%c, max_protection: %c%c%c\n",
487+         region->address, region->address + region->size, region->size,
488+         (region->protection & VM_PROT_READ) ? 'r' : '-',
489+         (region->protection & VM_PROT_WRITE) ? 'w' : '-',
490+         (region->protection & VM_PROT_EXECUTE) ? 'x' : '-',
491+         (region->max_protection & VM_PROT_READ) ? 'r' : '-',
492+         (region->max_protection & VM_PROT_WRITE) ? 'w' : '-',
493+         (region->max_protection & VM_PROT_EXECUTE) ? 'x' : '-');
494+}
495+
496+static void print_regions (struct region_t *regions)
497+{
498+  while (regions != NULL)
499+    {
500+      print_region (regions);
501+      regions = regions->next;
502+    }
503+}
504+
505+static void print_section (struct section *section)
506+{
507+  printf ("0x%8lx - 0x%8lx, length: 0x%8lx, offset: 0x%8lx\n",
508+         section->addr, section->addr + section->size, section->size, section->offset);
509+}
510+
511+static void print_sections (section_list_t *sections)
512+{
513+  while (sections != NULL)
514+    {
515+      print_section (&(sections->section));
516+      sections = sections->next;
517+    }
518+}
519+
520+static section_list_t *create_new_section_list(struct section *section_pointer)
521+{
522+    section_list_t *section_list;
523+
524+    section_list = malloc (sizeof (section_list_t));
525+    section_list->next = NULL;
526+    section_list->section = *section_pointer;
527+
528+    return section_list;
529+}
530+
531+static void append_section_list(section_list_t **first_list, section_list_t *last_list)
532+{
533+    section_list_t *current;
534+
535+    if (*first_list == NULL) {
536+        *first_list = last_list;
537+        return;
538+    }
539+
540+    current = *first_list;
541+    while (current->next != NULL)
542+        current = current->next;
543+
544+    current->next = last_list;
545+}
546+
547+static void free_section_list(section_list_t *section_list)
548+{
549+    section_list_t *next;
550+
551+    while (section_list != NULL)
552+    {
553+        next = section_list->next;
554+        free(section_list);
555+        section_list = next;
556+    }
557+}
558+
559+static void add_sections_from_segment(section_list_t **all_sections, struct segment_command *segment)
560+{
561+    struct section *section_pointer;
562+    int index;
563+
564+    section_pointer = (struct section *)(segment + 1);
565+    for (index = 0; index < segment->nsects; index++) {
566+        append_section_list (all_sections, create_new_section_list (section_pointer));
567+        section_pointer++;
568+    }
569+}
570+
571+static int section_with_address (section_list_t *sections, unsigned long address)
572+{
573+    int current_section, found_section;
574+
575+    found_section = 0;
576+    current_section = 1;
577+    while (sections != NULL)
578+    {
579+        if (address >= sections->section.addr && address < sections->section.addr + sections->section.size) {
580+            found_section = current_section;
581+            break;
582+        }
583+        sections = sections->next;
584+        current_section++;
585+    }
586+
587+    return found_section;
588+}
589+
590+/*
591+ * Copy len bytes from ffd@fpos to tfd@tpos.
592+ * If both file descriptors are -1, copy in memory (handles overlapping copies).
593+ * If either ffd or tfd are -1, either read or write len bytes.
594+ */
595+
596+static void mcopy (int ffd, int tfd,
597+                   unsigned long fpos, unsigned long tpos, unsigned long len, char *reason)
598+{
599+  if ((ffd == -1) && (tfd == -1))
600+    {
601+      char *f, *t, *e;
602+      if (fpos > tpos)
603+        {
604+         f = (char *)fpos;
605+         t = (char *)tpos;
606+         e = (char *)(fpos + len);
607+         while (f < e) *t++ = *f++;
608+        }
609+      else if (tpos > fpos)
610+        {
611+         f = (char *)(fpos + len);
612+         t = (char *)(tpos + len);
613+         e = (char *)fpos;
614+         while (f > e) *--t = *--f;         
615+        }   
616+#ifdef SHOW_MCOPY_READS
617+      printf ("read: %10lu - %10lu, length: %10lu [from MEM]  (%s)\n", tpos, tpos+len, len, reason);
618+#endif
619+    }
620+  else if (ffd == -1)
621+    {
622+      if (lseek (tfd, tpos, L_SET) < 0)
623+       fatal_unexec ("cannot seek target");
624+      if (write (tfd, (void *)fpos, len) != len)
625+       fatal_unexec ("cannot write target");
626+#ifdef SHOW_MCOPY_WRITES
627+      printf ("write: %10lu - %10lu, length: %10lu [from MEM]  (%s)\n", tpos, tpos+len, len, reason);
628+#endif
629+    }
630+  else if (tfd == -1)
631+    {
632+      if (lseek (ffd, fpos, L_SET) < 0)
633+       fatal_unexec ("cannot seek source");
634+      if (read (ffd, (void *)tpos, len) != len)
635+       fatal_unexec ("cannot read source");
636+#ifdef SHOW_MCOPY_READS
637+      printf ("read: %10lu - %10lu, length: %10lu [from DISK] (%s)\n", tpos, tpos+len, len, reason);
638+#endif
639+    }
640+  else
641+    {
642+      int bread;
643+      char *buf = alloca (1 << 16);
644+
645+#ifdef SHOW_MCOPY_WRITES
646+      printf ("write: %10lu - %10lu, length: %10lu [from DISK] (%s)\n", tpos, tpos+len, len, reason);
647+#endif
648+
649+      if (lseek (ffd, fpos, L_SET) < 0)
650+       fatal_unexec ("cannot seek source");
651+     
652+      if (lseek (tfd, tpos, L_SET) < 0)
653+       fatal_unexec ("cannot seek target");
654+     
655+      while((len > 0) && (bread = read (ffd, buf, MIN(1 << 16, len))) > 0)
656+        {
657+         if (bread < 0)
658+           fatal_unexec ("cannot read source");
659+         if (write (tfd, buf, bread) != bread)
660+           fatal_unexec ("cannot write target");
661+         len -= bread;
662+        }
663+    }
664+}
665+
666+/*
667+ * The process of dumping (or unexecing) is the opposite of exec().
668+ * It takes the original executable and parts of memory that have been
669+ * loaded with data, and creates a new executable.  This allows
670+ * standard lisp files to be loaded "instantly", because they are part
671+ * of the executable.
672+ *
673+ * This involves using vm_region() to build a list of allocated memory
674+ * regions, combining adjacent "similar" regions to reduce their
675+ * number, skipping read-only regions and parts of regions covered by
676+ * non-data segment load commands, and finally replacing the (usually
677+ * one) data segment with a new segment for each region.
678+ *
679+ * File offsets in load commands that follow the data segment must be
680+ * adjusted by the change in size of the data segment.  The size of
681+ * the load commands can increase without affecting file offsets --
682+ * see the note below.
683+ *
684+ * Data associated with the LC_SYMTAB and LC_DYSYMTAB is found in the
685+ * __LINKEDIT segment -- there is no extra data to be written for
686+ * these load commands.
687+ *
688+ * Relocatable symbols from the data segment, which we took from
689+ * memory, need to be unrelocated.  The relocatable address is found
690+ * in the new mach-o file and then zeroed out.  Failure to do this
691+ * typically results in a segmentation fault, with the offending
692+ * address being double what it is at the same point in temacs, since
693+ * it has been relocated twice.
694+ *
695+ * Be sure to study the loader.h file if you want to understand this.
696+ * otool -lv shows the load commands of the file, and is very useful
697+ * when debugging this code.  Also, 'size -m -x -l' gives a short
698+ * list of the sections, and 'nm -maxp' and 'nm -map' are useful
699+ * for the symbol table stuff.
700+ *
701+ * Note: This is not obvious, but the __TEXT section usually has a
702+ *       file offset of 0, and so when it is written it will overwrite
703+ *       any mach headers or load commands that have already been
704+ *       written...  How much room is there before critial parts are
705+ *       overwritten when we add load commands?
706+ *
707+ *    -- Steve Nygard
708+ */
709+
710+static void unexec_doit(int infd,int outfd)
711+{
712+  int i, j, l, header_position, output_position;
713+  region_t *regions = NULL, *cregion, **pregions;
714+  struct mach_header mach_header;
715+  struct load_command *load_command, *original_load_commands;
716+  struct segment_command *segment_pointer;
717+  struct symtab_command *symtab_pointer;
718+  struct section *section_pointer;
719+  section_list_t *all_sections = NULL;
720+
721+  unsigned long delta = 0;
722+#if defined(NS_TARGET) || !defined(NeXT)
723+  struct dysymtab_command *dysymtab;
724+  struct twolevel_hints_command *hinttab;
725+  unsigned long extreloff = 0;
726+  unsigned long nextrel = 0;
727+  unsigned long locreloff = 0;
728+  unsigned long nlocrel = 0;
729+  struct relocation_info reloc_info;
730+  unsigned long fixed_reloc_count = 0;
731+#endif
732+
733+  struct segment_command new_data_segment;
734+  section_list_t *original_sections, *new_sections, **sect_ptr, *section_item;
735+
736+  malloc_cookie = malloc_freezedry();
737+#ifdef VERBOSE
738+  printf ("malloc_cookie: %lx\n", malloc_cookie);
739+#endif
740+  if (malloc_cookie == 0)
741+    {
742+      fprintf(stderr, "Error in malloc_freezedry()\n");
743+      abort();
744+    }
745+
746+  {
747+    vm_address_t address;
748+    vm_size_t size;
749+    mach_port_t object_name;
750+#ifdef DARWIN
751+    task_t task = mach_task_self();
752+    struct vm_region_basic_info info;
753+    mach_msg_type_number_t info_count = VM_REGION_BASIC_INFO_COUNT;
754+#else
755+    task_t task = task_self();
756+    vm_prot_t protection, max_protection;
757+    vm_inherit_t inheritance;
758+    boolean_t shared;
759+    vm_offset_t offset;
760+#endif
761+
762+    for (address = VM_MIN_ADDRESS, pregions = &regions;
763+#ifdef DARWIN
764+        vm_region(task, &address, &size, VM_REGION_BASIC_INFO,
765+                  (vm_region_info_t)&info, &info_count, &object_name) == KERN_SUCCESS;
766+#else
767+        vm_region(task, &address, &size, &protection, &max_protection,
768+                  &inheritance, &shared, &object_name, &offset) == KERN_SUCCESS;
769+#endif
770+        address += size)
771+      {
772+       (*pregions) = alloca (sizeof(region_t));
773+       (*pregions)->address = address;
774+       (*pregions)->size = size;
775+#ifdef DARWIN
776+       (*pregions)->protection = info.protection;
777+       (*pregions)->max_protection = info.max_protection;
778+#else
779+       (*pregions)->protection = protection;
780+       (*pregions)->max_protection = max_protection;
781+#endif
782+       (*pregions)->file_offset = 0;
783+       (*pregions)->file_size = 0;
784+       (*pregions)->next = 0;
785+       pregions = &((*pregions)->next);
786+#ifdef DARWIN
787+       if (object_name != MACH_PORT_NULL)
788+         mach_port_deallocate(mach_task_self(), object_name);
789+       info_count = VM_REGION_BASIC_INFO_COUNT;
790+#endif
791+      }
792+  }
793+#ifdef VERBOSE   
794+  printf ("Regions.\n");
795+  print_regions (regions);
796+  printf ("----------------------------------------------------------------------\n");
797+#endif
798+   
799+  /*
800+   * Concatenate regions that are adjacent in memory and share the same
801+   * protection attributes.
802+   */
803+
804+  for (cregion = regions; cregion; cregion = cregion->next)
805+    {
806+      while ((cregion->next) &&
807+            (cregion->next->address == cregion->address + cregion->size) &&
808+            (cregion->next->protection == cregion->protection) &&
809+            (cregion->next->max_protection == cregion->max_protection))
810+        {
811+         cregion->size += cregion->next->size;
812+         cregion->next = cregion->next->next;
813+        }
814+    }
815+#ifdef VERBOSE   
816+  printf ("Concatenated regions.\n");
817+  print_regions (regions);
818+  printf ("----------------------------------------------------------------------\n");
819+#endif
820+
821+  /*
822+   * Remove read-only regions, and regions above a fixed limit.
823+   * Could have been done before allocating, but this way we can show
824+   * the regions before and after while debugging.
825+   */
826+
827+  for (pregions = &regions; *pregions != NULL;)
828+    {
829+      if ( !((*pregions)->protection & VM_PROT_WRITE)
830+          || ((*pregions)->address >= 0x3000000))
831+        {
832+         *pregions = (*pregions)->next;
833+        }
834+      else
835+        {
836+         pregions = &((*pregions)->next);
837+        }
838+    }
839+#ifdef VERBOSE
840+  printf ("Skipped regions.\n");
841+  print_regions (regions);
842+  printf ("----------------------------------------------------------------------\n");
843+#endif
844+  /*
845+     * Read original mach header and load commands.
846+     */
847+
848+  mcopy (infd, -1, 0, (unsigned long) &mach_header, sizeof(mach_header), "read original mach header");
849+  original_load_commands = alloca (mach_header.sizeofcmds);
850+  mcopy (infd, -1, sizeof(mach_header), (unsigned long) original_load_commands, mach_header.sizeofcmds,
851+         "read original load comands");
852+
853+  /*
854+     * Skip (or adjust) regions that intersect memory represented by non-data
855+     * segments from the original load commands.
856+     */
857+
858+  for (pregions = &regions; *pregions;)
859+    {
860+      for (load_command = original_load_commands, i = 0;
861+          i < mach_header.ncmds;
862+          i++, load_command = (struct load_command *)(((void *)load_command) + load_command->cmdsize))
863+        {
864+         unsigned long ob, oe;
865+         segment_pointer = (struct segment_command *)load_command;
866+         if (segment_pointer->cmd != LC_SEGMENT || (strcmp (segment_pointer->segname, SEG_DATA) == 0)) continue;
867+         ob = MAX((*pregions)->address, segment_pointer->vmaddr);
868+         oe = MIN((*pregions)->address + (*pregions)->size, segment_pointer->vmaddr + segment_pointer->vmsize);
869+         if (ob >= oe) continue;
870+         if (ob == (*pregions)->address)
871+            {
872+             if (oe == (*pregions)->address + (*pregions)->size)
873+                {
874+                 goto skip_region;
875+                }
876+             else
877+                {
878+                 (*pregions)->address = oe;
879+                 (*pregions)->size -= (oe - ob);
880+                }
881+            }
882+         else
883+            {
884+             if (oe == (*pregions)->address + (*pregions)->size)
885+                {
886+                 (*pregions)->size -= (oe - ob);
887+                }
888+             else
889+                {
890+                 cregion = alloca (sizeof(*cregion));
891+                 cregion->address = oe;
892+                 cregion->size = ((*pregions)->address + (*pregions)->size) - oe;
893+                 cregion->protection = (*pregions)->protection;
894+                 cregion->max_protection = (*pregions)->max_protection;
895+                 cregion->file_offset = 0;
896+                 cregion->file_size = 0;
897+                 cregion->next = (*pregions)->next;
898+                 (*pregions)->size = ob - (*pregions)->address;
899+                 (*pregions)->next = cregion;
900+                }
901+            }
902+        }
903+
904+      pregions = &((*pregions)->next);
905+      continue;
906+
907+    skip_region:
908+      *pregions = (*pregions)->next;
909+    }
910+#ifdef VERBOSE
911+  printf ("Munged regions (1).\n");
912+  print_regions (regions);
913+  printf ("----------------------------------------------------------------------\n");
914+#endif
915+
916+  for (load_command = original_load_commands, i = mach_header.ncmds, header_position = sizeof(mach_header), output_position = 0;
917+       i > 0;
918+       i--, load_command = (struct load_command *)(((void *)load_command) + load_command->cmdsize))
919+    {
920+      switch (load_command->cmd)
921+        {
922+       case LC_SEGMENT:
923+         segment_pointer = (struct segment_command *)load_command;
924+
925+         if (strcmp (segment_pointer->segname, SEG_DATA) == 0)
926+           {
927+#if 1
928+             unsigned long current_address;
929+
930+             original_sections = NULL;
931+             new_sections = NULL;
932+             sect_ptr = &original_sections;
933+
934+             section_pointer = (struct section *)(segment_pointer + 1);
935+             for (l = 0; l < segment_pointer->nsects; l++)
936+               {
937+                 if (!strncmp (section_pointer->sectname, "__la_symbol_ptr", 16))
938+                   {
939+                     section_item = alloca (sizeof (section_list_t));
940+                     section_item->next = *sect_ptr;
941+                     section_item->section = *section_pointer;
942+                     *sect_ptr = section_item;
943+                     sect_ptr = &(section_item->next);
944+                   }
945+                 else if (!strncmp (section_pointer->sectname, "__nl_symbol_ptr", 16))
946+                   {
947+                     section_item = alloca (sizeof (section_list_t));
948+                     section_item->next = *sect_ptr;
949+                     section_item->section = *section_pointer;
950+                     *sect_ptr = section_item;
951+                     sect_ptr = &(section_item->next);
952+                   }
953+                 else if (!strncmp (section_pointer->sectname, "__dyld", 16))
954+                   {
955+                     section_item = alloca (sizeof (section_list_t));
956+                     section_item->next = *sect_ptr;
957+                     section_item->section = *section_pointer;
958+                     *sect_ptr = section_item;
959+                     sect_ptr = &(section_item->next);
960+                   }
961+
962+                 section_pointer++;
963+               }
964+
965+             cregion = regions;
966+             /* new_data_segment */
967+             new_data_segment.cmd = LC_SEGMENT;
968+             strncpy (new_data_segment.segname, SEG_DATA, 16);
969+             new_data_segment.vmaddr = cregion->address;
970+             new_data_segment.vmsize = 0;
971+             new_data_segment.fileoff = 0;
972+             new_data_segment.filesize = 0;
973+             new_data_segment.maxprot = cregion->max_protection;
974+             new_data_segment.initprot = cregion->protection;
975+             new_data_segment.flags = segment_pointer->flags;
976+             new_data_segment.nsects = 0;
977+             new_data_segment.cmdsize = sizeof (struct segment_command);
978+#ifdef VERBOSE
979+             printf ("Original sections:\n");
980+             print_sections (original_sections);
981+             printf ("----------------------------------------------------------------------\n");
982+#endif
983+             /* Create list of new segments */
984+             sect_ptr = &new_sections;
985+             current_address = new_data_segment.vmaddr;
986+             while (original_sections != NULL)
987+               {
988+                 if (current_address < original_sections->section.addr)
989+                   {
990+                     /* Create new section for this. */
991+                     section_item = alloca (sizeof (section_list_t));
992+                     section_item->next = *sect_ptr;
993+
994+                     section_pointer = &(section_item->section);
995+                     strncpy (section_pointer->sectname, "__data", 16);
996+                     strncpy (section_pointer->segname, SEG_DATA, 16);
997+                     section_pointer->addr = current_address;
998+                     section_pointer->size = original_sections->section.addr - current_address;
999+                     section_pointer->offset = 0;
1000+                     section_pointer->align = 2; /* Yuck. */
1001+                     section_pointer->reloff = 0;
1002+                     section_pointer->nreloc = 0;
1003+                     section_pointer->flags = 0; /* S_REGULAR? */
1004+                     section_pointer->reserved1 = 0;
1005+                     section_pointer->reserved2 = 0;
1006+
1007+                     *sect_ptr = section_item;
1008+                     sect_ptr = &(section_item->next);
1009+                     current_address = original_sections->section.addr;
1010+                   }
1011+
1012+                 /* Put/copy this section into new list */
1013+                 section_item = original_sections;
1014+                 original_sections = original_sections->next;
1015+                 section_item->next = *sect_ptr; /* Should be NULL... */
1016+                 *sect_ptr = section_item;
1017+                 sect_ptr = &(section_item->next);
1018+
1019+                 /* increase current address */
1020+                 current_address += section_item->section.size;
1021+               }
1022+             /* if current address < end of region, add final section. */
1023+             if (current_address < cregion->address + cregion->size)
1024+               {
1025+                 /* Create new section for this. */
1026+                 section_item = alloca (sizeof (section_list_t));
1027+                 section_item->next = *sect_ptr;
1028+
1029+                 section_pointer = &(section_item->section);
1030+                 strncpy (section_pointer->sectname, "__data", 16);
1031+                 strncpy (section_pointer->segname, SEG_DATA, 16);
1032+                 section_pointer->addr = current_address;
1033+                 section_pointer->size = cregion->address + cregion->size - current_address;
1034+                 section_pointer->offset = 0;
1035+                 section_pointer->align = 2; /* Yuck. */
1036+                 section_pointer->reloff = 0;
1037+                 section_pointer->nreloc = 0;
1038+                 section_pointer->flags = 0; /* S_REGULAR? */
1039+                 section_pointer->reserved1 = 0;
1040+                 section_pointer->reserved2 = 0;
1041+
1042+                 *sect_ptr = section_item;
1043+                 sect_ptr = &(section_item->next);
1044+
1045+               }
1046+#ifdef VERBOSE
1047+             printf ("New sections:\n");
1048+             print_sections (new_sections);
1049+             printf ("----------------------------------------------------------------------\n");
1050+#endif
1051+             /**
1052+              * Go through new list of sections
1053+              *  - write section to disk, either from memory or original file
1054+              *  - say, if offset == 0, take from memory, otherwise from original file at that offset
1055+              *  - set offset of section
1056+              *  - set fileoff of segment to be that of the first section
1057+              *  - increase output position
1058+              **/
1059+
1060+             sect_ptr = &new_sections;
1061+             while (*sect_ptr != NULL)
1062+               {
1063+                 section_pointer = &((*sect_ptr)->section);
1064+                 if (new_data_segment.fileoff == 0)
1065+                   new_data_segment.fileoff = output_position;
1066+                 new_data_segment.vmsize += section_pointer->size;
1067+                 new_data_segment.filesize += section_pointer->size;
1068+                 new_data_segment.nsects++;
1069+                 new_data_segment.cmdsize += sizeof (struct section);
1070+                  printf ("section is '%s'\n", section_pointer->sectname);
1071+                 if (section_pointer->offset == 0)
1072+                   {
1073+                     mcopy (-1, outfd, (unsigned long) section_pointer->addr, output_position, section_pointer->size,
1074+                             "SEG_DATA: write section data from memory");
1075+                   }
1076+                 else
1077+                   {
1078+                     mcopy (infd, outfd, (unsigned long) section_pointer->offset, output_position, section_pointer->size,
1079+                             "SEG_DATA: write section data from original file");
1080+                   }
1081+                 section_pointer->offset = output_position;
1082+                 output_position += section_pointer->size;
1083+
1084+                 sect_ptr = &((*sect_ptr)->next);
1085+               }
1086+
1087+             /* Write data segment and sections, increasing the header position */
1088+             mcopy (-1, outfd, (unsigned long) &new_data_segment, header_position, sizeof (struct segment_command),
1089+                     "SEG_DATA: write segment command");
1090+             header_position += sizeof (struct segment_command);
1091+             while (new_sections != NULL)
1092+               {
1093+                 mcopy (-1, outfd, (unsigned long) &(new_sections->section), header_position, sizeof (struct section),
1094+                         "SEG_DATA: write section command");
1095+                  // Need to add this section to a list of all the sections
1096+                 header_position += sizeof (struct section);
1097+                  append_section_list (&all_sections, create_new_section_list (&(new_sections->section)));
1098+                 new_sections = new_sections->next;
1099+               }
1100+             mach_header.ncmds++;
1101+
1102+             /* Finally, skip first data segment. */
1103+             regions = regions->next;
1104+#endif
1105+
1106+#if 1
1107+             /* Write remainder of regions as data segments */
1108+             mach_header.ncmds--;
1109+             j = segment_pointer->cmdsize; /* Save original command size for loop. */
1110+             for (cregion = regions; cregion != NULL; cregion = cregion->next)
1111+               {
1112+                 mcopy (-1, outfd, cregion->address, output_position, cregion->size,
1113+                         "SEG_DATA: write remainder data");
1114+                 segment_pointer->cmd = LC_SEGMENT;
1115+                 segment_pointer->cmdsize = sizeof(*segment_pointer);
1116+                 strncpy (segment_pointer->segname, SEG_DATA, sizeof(segment_pointer->segname));
1117+                 segment_pointer->vmaddr = cregion->address;
1118+                 segment_pointer->vmsize = cregion->size;
1119+                 segment_pointer->filesize = cregion->size;
1120+                 segment_pointer->maxprot = cregion->max_protection;
1121+                 segment_pointer->initprot = cregion->protection;
1122+                 segment_pointer->nsects = 0;
1123+                 segment_pointer->flags = 0;
1124+                 segment_pointer->fileoff = output_position;
1125+                 output_position += segment_pointer->filesize;
1126+                 mcopy (-1, outfd, (unsigned long)segment_pointer, header_position, segment_pointer->cmdsize,
1127+                         "SEG_DATA: write segment command for remainder data");
1128+                 header_position += segment_pointer->cmdsize;
1129+                 mach_header.ncmds++;
1130+
1131+                 cregion->file_offset = segment_pointer->fileoff;
1132+                 cregion->file_size = segment_pointer->filesize;
1133+               }
1134+             segment_pointer->cmdsize = j;
1135+
1136+#endif
1137+           }
1138+         else
1139+           {
1140+#ifdef VERBOSE
1141+              printf ("segment is '%s':\n", segment_pointer->segname);
1142+#endif
1143+             mcopy (infd, outfd, segment_pointer->fileoff, output_position, segment_pointer->filesize,
1144+                     "SEG_OTHER: write segment data");
1145+             section_pointer = (struct section *) (((void *)segment_pointer)+sizeof(*segment_pointer));
1146+             for(j = 0; j < segment_pointer->nsects; j++)
1147+               {
1148+                 if (section_pointer[j].offset != 0)
1149+                   section_pointer[j].offset = (section_pointer[j].offset - segment_pointer->fileoff) + output_position;
1150+                 if (section_pointer[j].reloff != 0)
1151+                   section_pointer[j].reloff = (section_pointer[j].reloff - segment_pointer->fileoff) + output_position;
1152+               }
1153+
1154+             if (strcmp (segment_pointer->segname, SEG_LINKEDIT) == 0)
1155+               {
1156+                 delta = output_position - segment_pointer->fileoff;
1157+               }
1158+
1159+             segment_pointer->fileoff = output_position;
1160+             output_position += segment_pointer->filesize;
1161+
1162+             mcopy (-1, outfd, (unsigned long)load_command, header_position, load_command->cmdsize,
1163+                     "SEG_OTHER: write segment command and its sections");
1164+             header_position += load_command->cmdsize;
1165+
1166+              // Now, scan the segments for sections, so we have a list of all the sections to use to fix up
1167+              // the symbol table entries.
1168+              add_sections_from_segment(&all_sections, segment_pointer);
1169+           }
1170+         break;
1171+
1172+       case LC_SYMTAB:
1173+        {
1174+            struct nlist *symtab;
1175+
1176+            symtab_pointer = (struct symtab_command *)load_command;
1177+
1178+            symtab = malloc(symtab_pointer->nsyms * sizeof(struct nlist));
1179+            mcopy(infd, -1, symtab_pointer->symoff, (unsigned long)symtab, symtab_pointer->nsyms * sizeof(struct nlist),
1180+                  "Read old symbol table into memory");
1181+
1182+            symtab_pointer->symoff += delta;
1183+            symtab_pointer->stroff += delta;
1184+            mcopy (-1, outfd, (unsigned long)load_command, header_position, load_command->cmdsize,
1185+                   "write symtab command");
1186+            header_position += load_command->cmdsize;
1187+            printf ("LC_SYMTAB: symoff = %ld, nsyms = %ld, stroff = %ld, strsize = %ld\n",
1188+                    symtab_pointer->symoff, symtab_pointer->nsyms, symtab_pointer->stroff, symtab_pointer->strsize);
1189+
1190+            // We've already written out the symbol table, but we're going to read it back in, adjust the
1191+            // symbol table entries, and write out the result again.
1192+
1193+            if (all_sections != NULL)
1194+            {
1195+                int index;
1196+                struct nlist *nlist_pointer;
1197+                section_list_t *section;
1198+                int section_index;
1199+                int changed_symtabs;
1200+
1201+                printf ("All sections:\n");
1202+                print_sections (all_sections);
1203+
1204+                changed_symtabs = 0;
1205+                nlist_pointer = symtab;
1206+
1207+                for (index = 0; index < symtab_pointer->nsyms; index++) {
1208+                    if ((nlist_pointer->n_type & N_TYPE) == N_SECT) {
1209+                        section_index = section_with_address(all_sections, nlist_pointer->n_value);
1210+#if 0
1211+                        printf ("%5d: 0x%08lx 0x%02x 0x%02x (0x%02x) 0x%04x 0x%08lx\n",
1212+                                index, nlist_pointer->n_un.n_strx, nlist_pointer->n_type & 0xff, nlist_pointer->n_sect & 0xff,
1213+                                section_index,
1214+                                nlist_pointer->n_desc & 0xffff, nlist_pointer->n_value);
1215+#endif
1216+                        if (nlist_pointer->n_sect != section_index) {
1217+                            nlist_pointer->n_sect = section_index;
1218+                            changed_symtabs++;
1219+                        }
1220+                    }
1221+                    nlist_pointer++;
1222+                }
1223+
1224+                printf ("Adjusted n_sect for %d symbol table entries.\n", changed_symtabs);
1225+                mcopy(-1, outfd, (unsigned long)symtab, symtab_pointer->symoff, symtab_pointer->nsyms * sizeof(struct nlist),
1226+                      "write updated symbol table");
1227+
1228+                free_section_list(all_sections);
1229+            }
1230+
1231+            free(symtab);
1232+        }
1233+        break;
1234+#if defined(NS_TARGET) || !defined(NeXT)
1235+       case LC_DYSYMTAB:
1236+         dysymtab = (struct dysymtab_command *)load_command;
1237+         extreloff = dysymtab->extreloff;
1238+         nextrel = dysymtab->nextrel;
1239+
1240+         locreloff = dysymtab->locreloff;
1241+         nlocrel = dysymtab->nlocrel;
1242+
1243+         if (dysymtab->nindirectsyms > 0) {
1244+           dysymtab->indirectsymoff += delta;
1245+         }
1246+         if (nextrel > 0) {
1247+           dysymtab->extreloff += delta;
1248+         }
1249+
1250+         if (nlocrel > 0) {
1251+           dysymtab->locreloff += delta;
1252+         }
1253+         mcopy (-1, outfd, (unsigned long)load_command, header_position, load_command->cmdsize,
1254+                 "write dysymtab command");
1255+         header_position += load_command->cmdsize;
1256+
1257+         break;
1258+
1259+       case LC_TWOLEVEL_HINTS:
1260+          hinttab = (struct twolevel_hints_command *)load_command;
1261+          hinttab->offset += delta;
1262+         
1263+          mcopy (-1, outfd, (unsigned long)load_command, header_position, load_command->cmdsize,
1264+                 "write two-level hint command");
1265+          header_position += load_command->cmdsize;
1266+
1267+          break;
1268+#endif
1269+       default:
1270+         {
1271+           char *reason, *cmdstr;
1272+
1273+           /* Create a string that tells what load command is being left
1274+            * alone. */
1275+           switch (load_command->cmd)
1276+             {
1277+             case LC_UNIXTHREAD:
1278+               cmdstr = "LC_UNIXTHREAD";
1279+               break;
1280+             case LC_LOAD_DYLIB:
1281+               cmdstr = "LC_LOAD_DYLIB";
1282+               break;
1283+             case LC_LOAD_DYLINKER:
1284+               cmdstr = "LC_LOAD_DYLINKER";
1285+               break;
1286+             default:
1287+               cmdstr = NULL;
1288+             }
1289+           if (cmdstr != NULL)
1290+             {
1291+               asprintf(&reason, "write other load command (%s)", cmdstr);
1292+             }
1293+           else
1294+             {
1295+               asprintf(&reason, "write other load command (0x%x)", load_command->cmd);
1296+             }
1297+
1298+           mcopy (-1, outfd, (unsigned long)load_command, header_position, load_command->cmdsize,
1299+                  reason);
1300+           free(reason);
1301+           header_position += load_command->cmdsize;
1302+         }
1303+        }
1304+    }
1305+
1306+  mach_header.sizeofcmds = header_position - sizeof(mach_header);
1307+  mcopy (-1, outfd, (unsigned long) &mach_header, 0, sizeof(mach_header), "write mach header");
1308+
1309+#if defined(NS_TARGET) || !defined(NeXT)
1310+  if (mach_header.flags & MH_PREBOUND) {
1311+    /* Don't mess with prebound executables */
1312+    return;
1313+  }
1314+
1315+  /*
1316+     * Fix up relocation entries in the data segment(s).
1317+     */
1318+  if (lseek (infd, locreloff, L_SET) < 0)
1319+    fatal_unexec ("cannot seek input file");
1320+
1321+  fixed_reloc_count = 0;
1322+  for (i = 0; i < nlocrel; i++)
1323+    {
1324+      long zeroval = 0;
1325+      struct scattered_relocation_info *si;
1326+
1327+      if (read (infd, &reloc_info, sizeof(reloc_info)) != sizeof(reloc_info))
1328+       fatal_unexec ("cannot read input file");
1329+
1330+#if 1
1331+#ifdef VERBOSE
1332+      printf ("%2d: reloc: %lx, start: %lx, end: %lx\n", i, reloc_info.r_address,
1333+             new_data_segment.vmaddr, new_data_segment.vmaddr + new_data_segment.filesize);
1334+#endif
1335+      if (reloc_info.r_address >= new_data_segment.vmaddr
1336+         && reloc_info.r_address < new_data_segment.vmaddr + new_data_segment.filesize)
1337+        {
1338+         fixed_reloc_count++;
1339+         mcopy (-1, outfd, (unsigned long) &zeroval,
1340+                new_data_segment.fileoff + reloc_info.r_address - new_data_segment.vmaddr,
1341+                1 << reloc_info.r_length, "fix local relocation entry");
1342+        }
1343+#endif
1344+    }
1345+  printf ("Fixed %lu/%lu local relocation entries in data segment(s).\n", fixed_reloc_count, nlocrel);
1346+
1347+  if (lseek (infd, extreloff, L_SET) < 0)
1348+    fatal_unexec ("cannot seek input file");
1349+
1350+  for (i = 0; i < nextrel; i++)
1351+    {
1352+      long zeroval = 0;
1353+
1354+      if (read (infd, &reloc_info, sizeof(reloc_info)) != sizeof(reloc_info))
1355+       fatal_unexec ("cannot read input file");
1356+
1357+#if 1
1358+#ifdef VERBOSE
1359+      printf ("%2d: reloc: %lx, start: %lx, end: %lx\n", i, reloc_info.r_address,
1360+             new_data_segment.vmaddr, new_data_segment.vmaddr + new_data_segment.filesize);
1361+#endif
1362+      if (reloc_info.r_address >= new_data_segment.vmaddr
1363+         && reloc_info.r_address < new_data_segment.vmaddr + new_data_segment.filesize)
1364+        {
1365+         fixed_reloc_count++;
1366+         mcopy (-1, outfd, (unsigned long) &zeroval,
1367+                new_data_segment.fileoff + reloc_info.r_address - new_data_segment.vmaddr,
1368+                1 << reloc_info.r_length, "fix external relocation entry");
1369+        }
1370+#endif
1371+    }
1372+
1373+  printf ("Fixed %lu/%lu external relocation entries in data segment(s).\n", fixed_reloc_count, nextrel);
1374+
1375+#endif
1376+}
1377+
1378+void unexec (char *outfile, char *infile)
1379+{
1380+  char tmpfile[MAXPATHLEN + 1];
1381+  int infd, outfd;
1382+   
1383+  if ((infd = open (infile, O_RDONLY, 0)) < 0)
1384+    fatal_unexec ("cannot open input file `%s'", infile);
1385+
1386+  strcpy (tmpfile, outfile);
1387+  strcat (tmpfile, "-temp");
1388+   
1389+  if ((outfd = open (tmpfile, O_RDWR|O_TRUNC|O_CREAT, 0755)) < 0)
1390+    fatal_unexec ("cannot open temporary output file `%s'", tmpfile);
1391+
1392+  unexec_doit (infd, outfd);
1393+
1394+  close (infd);
1395+  close (outfd);
1396+  if (rename (tmpfile, outfile) < 0)
1397+    {
1398+      unlink (tmpfile);
1399+      fatal_unexec ("cannot rename `%s' to `%s'", tmpfile, outfile);
1400+    } 
1401+}
1402Index: emacs/src/unexnext.c
1403===================================================================
1404RCS file: /cvs/Darwin/src/live/emacs/emacs/src/unexnext.c,v
1405retrieving revision 1.1.1.5
1406retrieving revision 1.3
1407diff -u -r1.1.1.5 -r1.3
1408Index: emacs/src/m/powermacintosh.h
1409===================================================================
1410RCS file: powermacintosh.h
1411diff -N powermacintosh.h
1412--- /dev/null   Tue Sep 17 14:45:13 2002
1413+++ emacs/src/m/powermacintosh.h        Tue Sep 17 16:29:09 2002
1414@@ -0,0 +1,45 @@
1415+/* Apple Power Macintosh machine/system dependent defines
1416+   Copyright (C) 1997 Free Software Foundation, Inc.
1417+
1418+This file is part of GNU Emacs.
1419+
1420+GNU Emacs is free software; you can redistribute it and/or modify
1421+it under the terms of the GNU General Public License as published by
1422+the Free Software Foundation; either version 2, or (at your option)
1423+any later version.
1424+
1425+GNU Emacs is distributed in the hope that it will be useful,
1426+but WITHOUT ANY WARRANTY; without even the implied warranty of
1427+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1428+GNU General Public License for more details.
1429+
1430+You should have received a copy of the GNU General Public License
1431+along with GNU Emacs; see the file COPYING.  If not, write to
1432+the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
1433+Boston, MA 02111-1307, USA.  */
1434+
1435+
1436+/* The following line tells the configuration script what sort of
1437+   operating system this machine is likely to run.
1438+   USUAL-OPSYS="darwin"  */
1439+
1440+/* Define WORDS_BIG_ENDIAN iff lowest-numbered byte in a word
1441+   is the most significant byte.  */
1442+
1443+#define WORDS_BIG_ENDIAN
1444+
1445+/* Define NO_ARG_ARRAY if you cannot take the address of the first of a
1446+ * group of arguments and treat it as an array of the arguments.  */
1447+
1448+#define NO_ARG_ARRAY
1449+
1450+/* Use type int rather than a union, to represent Lisp_Object */
1451+/* This is desirable for most machines.         */
1452+
1453+#define NO_UNION_TYPE
1454+
1455+/* Define addresses, macros, change some setup for dump */
1456+
1457+#define NO_REMAP
1458+
1459+#define DATA_SEG_BITS 0
1460Index: emacs/src/s/darwin.h
1461===================================================================
1462RCS file: darwin.h
1463diff -N darwin.h
1464--- /dev/null   Tue Sep 17 14:45:13 2002
1465+++ emacs/src/s/darwin.h        Tue Sep 17 16:29:09 2002
1466@@ -0,0 +1,104 @@
1467+/* Configuration file for Darwin OS.
1468+   Copyright (C) 1997 Free Software Foundation, Inc.
1469+
1470+This file is part of GNU Emacs.
1471+
1472+GNU Emacs is free software; you can redistribute it and/or modify
1473+it under the terms of the GNU General Public License as published by
1474+the Free Software Foundation; either version 2, or (at your option)
1475+any later version.
1476+
1477+GNU Emacs is distributed in the hope that it will be useful,
1478+but WITHOUT ANY WARRANTY; without even the implied warranty of
1479+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1480+GNU General Public License for more details.
1481+
1482+You should have received a copy of the GNU General Public License
1483+along with GNU Emacs; see the file COPYING.  If not, write to
1484+the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
1485+Boston, MA 02111-1307, USA.  */
1486+
1487+/* We give these symbols the numeric values found in <sys/param.h> to
1488+   avoid warnings about redefined macros.  */
1489+#define BSD 199506
1490+#define BSD4_3 1
1491+#define BSD4_4 1
1492+
1493+#include "bsd4-3.h"
1494+
1495+/* SYSTEM_TYPE should indicate the kind of system you are using.
1496+   It sets the Lisp variable system-type.  We'll need to undo the bsd one. */
1497+
1498+#undef SYSTEM_TYPE
1499+#define SYSTEM_TYPE "darwin"
1500+
1501+#ifndef DARWIN
1502+#define DARWIN
1503+#endif
1504+
1505+#undef KERNEL_FILE
1506+#define KERNEL_FILE "/mach_kernel"
1507+
1508+#define HAVE_ALLOCA
1509+
1510+#define HAVE_MACH_MACH_H
1511+
1512+#define SYSTEM_MALLOC
1513+
1514+#define WAIT_USE_INT
1515+
1516+#define SOCKLEN_TYPE int
1517+
1518+#define GETPGRP_NO_ARG
1519+
1520+#ifdef HAVE_LIBNCURSES
1521+#define TERMINFO
1522+#define LIBS_TERMCAP -lncurses
1523+#else
1524+#define TERMCAP_FILE "/usr/share/misc/termcap"
1525+#endif
1526+
1527+#define PENDING_OUTPUT_COUNT(FILE) ((FILE)->_p - (FILE)->_bf._base)
1528+
1529+#define A_OUT_H_FILE <sys/exec.h>
1530+
1531+/* Data type of load average, as read out of kmem.  */
1532+#define LOAD_AVE_TYPE long
1533+
1534+#define ABORT_RETURN_TYPE __private_extern__ void
1535+
1536+/* Convert that into an integer that is 100 for a load average of 1.0  */
1537+#define LOAD_AVE_CVT(x) (int) (((double)(x)) * 100.0 / FSCALE)
1538+
1539+#define UNEXEC unexdyld.o
1540+
1541+/* Definitions for how to compile & link.  */
1542+
1543+/* Link this program just by running cc.  */
1544+#define ORDINARY_LINK
1545+
1546+/* #define C_SWITCH_SYSTEM */
1547+
1548+/* We don't have a g library, so override the -lg LIBS_DEBUG switch */
1549+#define LIBS_DEBUG
1550+
1551+/* Adding -lm confuses the dynamic linker, so omit it. */
1552+#define LIB_MATH
1553+
1554+/* Definitions for how to dump.  */
1555+
1556+#define START_FILES pre-crt0.o
1557+
1558+/* start_of_text isn't actually used, so make it compile without error.  */
1559+#define TEXT_START (0)
1560+
1561+/* This seems to be right for end_of_text, but it may not be used anyway.  */
1562+#define TEXT_END get_etext()
1563+
1564+/* This seems to be right for end_of_data, but it may not be used anyway.  */
1565+#define DATA_END get_edata()
1566+
1567+/* Don't close pty in process.c to make it a controlling terminal.  It is
1568+ * already the controlling terminal of the subprocess, because we did ioctl
1569+ * TIOCSCTTY.  */
1570+#define DONT_REOPEN_PTY
1571Index: emacs/src/s/rhapsody.h
1572===================================================================
1573RCS file: rhapsody.h
1574diff -N rhapsody.h
1575--- /dev/null   Tue Sep 17 14:45:13 2002
1576+++ emacs/src/s/rhapsody.h      Tue Sep 17 16:29:09 2002
1577@@ -0,0 +1,89 @@
1578+/* Configuration file for Mac OS X Server.
1579+   Copyright (C) 1997 Free Software Foundation, Inc.
1580+
1581+This file is part of GNU Emacs.
1582+
1583+GNU Emacs is free software; you can redistribute it and/or modify
1584+it under the terms of the GNU General Public License as published by
1585+the Free Software Foundation; either version 2, or (at your option)
1586+any later version.
1587+
1588+GNU Emacs is distributed in the hope that it will be useful,
1589+but WITHOUT ANY WARRANTY; without even the implied warranty of
1590+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1591+GNU General Public License for more details.
1592+
1593+You should have received a copy of the GNU General Public License
1594+along with GNU Emacs; see the file COPYING.  If not, write to
1595+the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
1596+Boston, MA 02111-1307, USA.  */
1597+
1598+/* We give these symbols the numeric values found in <sys/param.h> to
1599+   avoid warnings about redefined macros.  */
1600+#define BSD 199506
1601+#define BSD4_3 1
1602+#define BSD4_4 1
1603+
1604+#include "bsd4-3.h"
1605+
1606+/* SYSTEM_TYPE should indicate the kind of system you are using.
1607+   It sets the Lisp variable system-type.  We'll need to undo the bsd one. */
1608+
1609+#undef SYSTEM_TYPE
1610+#define SYSTEM_TYPE "apple-rhapsody"
1611+
1612+#ifndef RHAPSODY
1613+#define RHAPSODY
1614+#endif
1615+
1616+#define HAVE_ALLOCA
1617+
1618+#define HAVE_MACH_MACH_H
1619+
1620+#define SYSTEM_MALLOC
1621+
1622+#define WAIT_USE_INT
1623+
1624+#define SOCKLEN_TYPE int
1625+
1626+#define GETPGRP_NO_ARG
1627+
1628+#define TERMCAP_FILE "/usr/share/misc/termcap"
1629+
1630+#define PENDING_OUTPUT_COUNT(FILE) ((FILE)->_p - (FILE)->_bf._base)
1631+
1632+#define A_OUT_H_FILE <sys/exec.h>
1633+
1634+/* Data type of load average, as read out of kmem.  */
1635+#define LOAD_AVE_TYPE long
1636+
1637+/* Convert that into an integer that is 100 for a load average of 1.0  */
1638+#define LOAD_AVE_CVT(x) (int) (((double)(x)) * 100.0 / FSCALE)
1639+
1640+#define UNEXEC unexdyld.o
1641+
1642+/* Definitions for how to compile & link.  */
1643+
1644+/* Link this program just by running cc.  */
1645+#define ORDINARY_LINK
1646+
1647+/* #define C_SWITCH_SYSTEM */
1648+
1649+/* We don't have a g library, so override the -lg LIBS_DEBUG switch */
1650+#define LIBS_DEBUG
1651+
1652+/* Adding -lm confuses the dynamic linker, so omit it. */
1653+#define LIB_MATH
1654+
1655+/* Definitions for how to dump.  */
1656+
1657+#define START_FILES pre-crt0.o
1658+
1659+/* start_of_text isn't actually used, so make it compile without error.  */
1660+#define TEXT_START (0)
1661+
1662+/* This seems to be right for end_of_text, but it may not be used anyway.  */
1663+#define TEXT_END get_etext()
1664+
1665+/* This seems to be right for end_of_data, but it may not be used anyway.  */
1666+#define DATA_END get_edata()
1667Index: emacs/configure
1668--- configure.orig      Tue Oct 19 23:56:50 2004
1669+++ configure   Tue Oct 19 23:58:32 2004
1670@@ -1179,6 +1179,24 @@
1671     machine=hp800 opsys=nextstep
1672   ;;
1673 
1674+  ## Mac OS X Server
1675+  *-*-rhapsody*)
1676+     opsys=rhapsody
1677+     case "${canonical}" in
1678+       powerpc-*-rhapsody*) machine=powermacintosh ;;
1679+       i386-*-rhapsody*)    machine=intel386 ;;
1680+     esac
1681+   ;;
1682+
1683+   ## Darwin / Mac OS X
1684+   *-*-darwin*)
1685+     opsys=darwin
1686+     case "${canonical}" in
1687+       powerpc-*-darwin*) machine=powermacintosh ;;
1688+       i?86-*-darwin*)    machine=intel386 ;;
1689+     esac
1690+   ;;
1691+
1692   ## Orion machines
1693   orion-orion-bsd* )
1694     machine=orion opsys=bsd4-2
1695Index: emacs/configure.in
1696--- configure.in.orig   Tue Oct 19 23:56:54 2004
1697+++ configure.in        Tue Oct 19 23:59:29 2004
1698@@ -553,6 +553,24 @@
1699     machine=hp800 opsys=nextstep
1700   ;;
1701 
1702+   ## Mac OS X Server
1703+   *-*-rhapsody*)
1704+     opsys=rhapsody
1705+     case "${canonical}" in
1706+       powerpc-*-rhapsody*) machine=powermacintosh ;;
1707+       i386-*-rhapsody*)    machine=intel386 ;;
1708+     esac
1709+   ;;
1710+
1711+   ## Darwin / Mac OS X
1712+   *-*-darwin*)
1713+     opsys=darwin
1714+     case "${canonical}" in
1715+       powerpc-*-darwin*) machine=powermacintosh ;;
1716+       i?86-*-darwin*)    machine=intel386 ;;
1717+     esac
1718+   ;;
1719+
1720   ## Orion machines
1721   orion-orion-bsd* )
1722     machine=orion opsys=bsd4-2
Note: See TracBrowser for help on using the repository browser.