]> code.delx.au - gnu-emacs/blobdiff - src/unexmacosx.c
Merged in changes from CVS trunk. Plus added lisp/term tweaks.
[gnu-emacs] / src / unexmacosx.c
index 1f2b4c9662098197d113da37b0d1888a41e8c3b5..9db9622f6f5dcb9a8982ec59b5a07a2364e954b0 100644 (file)
@@ -1,5 +1,5 @@
 /* Dump Emacs in Mach-O format for use on Mac OS X.
-   Copyright (C) 2001, 2002 Free Software Foundation, Inc.
+   Copyright (C) 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -15,8 +15,8 @@ GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with GNU Emacs; see the file COPYING.  If not, write to
-the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-Boston, MA 02111-1307, USA.  */
+the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA.  */
 
 /* Contributed by Andrew Choi (akochoi@mac.com).  */
 
@@ -105,6 +105,8 @@ Boston, MA 02111-1307, USA.  */
 #include <objc/malloc.h>
 #endif
 
+#include <assert.h>
+
 
 #define VERBOSE 1
 
@@ -693,6 +695,7 @@ copy_data_segment (struct load_command *lc)
        }
       else if (strncmp (sectp->sectname, "__la_symbol_ptr", 16) == 0
               || strncmp (sectp->sectname, "__nl_symbol_ptr", 16) == 0
+              || strncmp (sectp->sectname, "__la_sym_ptr2", 16) == 0
               || strncmp (sectp->sectname, "__dyld", 16) == 0
               || strncmp (sectp->sectname, "__const", 16) == 0
               || strncmp (sectp->sectname, "__cfstring", 16) == 0)
@@ -998,6 +1001,23 @@ unexec_init_emacs_zone ()
   malloc_set_zone_name (emacs_zone, "EmacsZone");
 }
 
+#ifndef MACOSX_MALLOC_MULT16
+#define MACOSX_MALLOC_MULT16 1
+#endif
+
+typedef struct unexec_malloc_header {
+  union {
+    char c[8];
+    size_t size;
+  } u;
+} unexec_malloc_header_t;
+
+#if MACOSX_MALLOC_MULT16
+
+#define ptr_in_unexec_regions(p) ((((vm_address_t) (p)) & 8) != 0)
+
+#else
+
 int
 ptr_in_unexec_regions (void *ptr)
 {
@@ -1011,36 +1031,75 @@ ptr_in_unexec_regions (void *ptr)
   return 0;
 }
 
+#endif
+
 void *
 unexec_malloc (size_t size)
 {
   if (in_dumped_exec)
-    return malloc (size);
+    {
+      void *p;
+
+      p = malloc (size);
+#if MACOSX_MALLOC_MULT16
+      assert (((vm_address_t) p % 16) == 0);
+#endif
+      return p;
+    }
   else
-    return malloc_zone_malloc (emacs_zone, size);
+    {
+      unexec_malloc_header_t *ptr;
+
+      ptr = (unexec_malloc_header_t *)
+       malloc_zone_malloc (emacs_zone, size + sizeof (unexec_malloc_header_t));
+      ptr->u.size = size;
+      ptr++;
+#if MACOSX_MALLOC_MULT16
+      assert (((vm_address_t) ptr % 16) == 8);
+#endif
+      return (void *) ptr;
+    }
 }
 
 void *
 unexec_realloc (void *old_ptr, size_t new_size)
 {
   if (in_dumped_exec)
-    if (ptr_in_unexec_regions (old_ptr))
-      {
-       char *p = malloc (new_size);
-       /* 2002-04-15 T. Ikegami <ikegami@adam.uprr.pr>.  The original
-          code to get size failed to reallocate read_buffer
-          (lread.c).  */
-       int old_size = malloc_default_zone()->size (emacs_zone, old_ptr);
-       int size = new_size > old_size ? old_size : new_size;
-
-       if (size)
-         memcpy (p, old_ptr, size);
-       return p;
-      }
-    else
-      return realloc (old_ptr, new_size);
+    {
+      void *p;
+
+      if (ptr_in_unexec_regions (old_ptr))
+       {
+         size_t old_size = ((unexec_malloc_header_t *) old_ptr)[-1].u.size;
+         size_t size = new_size > old_size ? old_size : new_size;
+
+         p = (size_t *) malloc (new_size);
+         if (size)
+           memcpy (p, old_ptr, size);
+       }
+      else
+       {
+         p = realloc (old_ptr, new_size);
+       }
+#if MACOSX_MALLOC_MULT16
+      assert (((vm_address_t) p % 16) == 0);
+#endif
+      return p;
+    }
   else
-    return malloc_zone_realloc (emacs_zone, old_ptr, new_size);
+    {
+      unexec_malloc_header_t *ptr;
+
+      ptr = (unexec_malloc_header_t *)
+       malloc_zone_realloc (emacs_zone, (unexec_malloc_header_t *) old_ptr - 1,
+                            new_size + sizeof (unexec_malloc_header_t));
+      ptr->u.size = new_size;
+      ptr++;
+#if MACOSX_MALLOC_MULT16
+      assert (((vm_address_t) ptr % 16) == 8);
+#endif
+      return (void *) ptr;
+    }
 }
 
 void
@@ -1052,7 +1111,7 @@ unexec_free (void *ptr)
        free (ptr);
     }
   else
-    malloc_zone_free (emacs_zone, ptr);
+    malloc_zone_free (emacs_zone, (unexec_malloc_header_t *) ptr - 1);
 }
 
 /* arch-tag: 1a784f7b-a184-4c4f-9544-da8619593d72