aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPip Cet2024-08-20 18:40:29 +0000
committerStefan Kangas2024-12-12 22:48:11 +0100
commitb2bc337a5f8d84978029873ce8e51b8d3d53121a (patch)
treef80a5ea808dbdd8997f6f0e2860dc16c42e84c61 /src
parent15e2b14f03796467fab8e8086d293a5813afaa5b (diff)
downloademacs-b2bc337a5f8d84978029873ce8e51b8d3d53121a.tar.gz
emacs-b2bc337a5f8d84978029873ce8e51b8d3d53121a.zip
Unexec removal: Remove HYBRID_MALLOC support
* src/gmalloc.c (gdefault_morecore): Remove HYBRID_MALLOC code. (allocated_via_gmalloc, hybrid_malloc, hybrid_calloc, hybrid_free_1) (hybrid_free, hybrid_aligned_alloc, hybrid_realloc): Remove functions. * msdos/sed1v2.inp: * msdos/sedlibmk.inp: * src/alloc.c (GC_MALLOC_CHECK, USE_ALIGNED_ALLOC) (refill_memory_reserve, aligned_alloc): * src/emacs.c (main): * src/lastfile.c (my_edata): * src/lisp.h: * src/ralloc.c: * src/sysdep.c (get_current_dir_name_or_unreachable): * src/xdisp.c (decode_mode_spec): Remove HYBRID_MALLOC conditions. * configure.ac (hybrid_malloc, HYBRID_MALLOC): Remove variables and dependent code. * src/conf_post.h (hybrid_malloc, hybrid_calloc, hybrid_free) (hybrid_aligned_alloc, hybrid_realloc): Remove conditional prototypes. * src/Makefile.in (HYBRID_MALLOC): Remove variable. (base_obj): Remove sheap.o (LIBEGNU_ARCHIVE): * lib/Makefile.in (libgnu_a_OBJECTS): Remove libegnu.a support.
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.in5
-rw-r--r--src/alloc.c30
-rw-r--r--src/conf_post.h25
-rw-r--r--src/emacs.c7
-rw-r--r--src/gmalloc.c167
-rw-r--r--src/lastfile.c2
-rw-r--r--src/lisp.h4
-rw-r--r--src/ralloc.c6
-rw-r--r--src/sysdep.c4
-rw-r--r--src/xdisp.c2
10 files changed, 32 insertions, 220 deletions
diff --git a/src/Makefile.in b/src/Makefile.in
index c35fb3a1bc4..03c2c8d6e0a 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -306,8 +306,6 @@ XSHAPE_CFLAGS = @XSHAPE_CFLAGS@
306## widget.o if USE_X_TOOLKIT, otherwise empty. 306## widget.o if USE_X_TOOLKIT, otherwise empty.
307WIDGET_OBJ=@WIDGET_OBJ@ 307WIDGET_OBJ=@WIDGET_OBJ@
308 308
309HYBRID_MALLOC = @HYBRID_MALLOC@
310
311## cygw32.o if CYGWIN, otherwise empty. 309## cygw32.o if CYGWIN, otherwise empty.
312CYGWIN_OBJ=@CYGWIN_OBJ@ 310CYGWIN_OBJ=@CYGWIN_OBJ@
313 311
@@ -477,7 +475,6 @@ base_obj = dispnew.o frame.o scroll.o xdisp.o menu.o $(XMENU_OBJ) window.o \
477 profiler.o decompress.o \ 475 profiler.o decompress.o \
478 thread.o systhread.o sqlite.o treesit.o \ 476 thread.o systhread.o sqlite.o treesit.o \
479 itree.o json.o \ 477 itree.o json.o \
480 $(if $(HYBRID_MALLOC),sheap.o) \
481 $(MSDOS_OBJ) $(MSDOS_X_OBJ) $(NS_OBJ) $(CYGWIN_OBJ) $(FONT_OBJ) \ 478 $(MSDOS_OBJ) $(MSDOS_X_OBJ) $(NS_OBJ) $(CYGWIN_OBJ) $(FONT_OBJ) \
482 $(W32_OBJ) $(WINDOW_SYSTEM_OBJ) $(XGSELOBJ) \ 479 $(W32_OBJ) $(WINDOW_SYSTEM_OBJ) $(XGSELOBJ) \
483 $(HAIKU_OBJ) $(PGTK_OBJ) $(ANDROID_OBJ) 480 $(HAIKU_OBJ) $(PGTK_OBJ) $(ANDROID_OBJ)
@@ -718,7 +715,7 @@ globals.h: gl-stamp; @true
718 715
719$(ALLOBJS): globals.h 716$(ALLOBJS): globals.h
720 717
721LIBEGNU_ARCHIVE = $(lib)/lib$(if $(HYBRID_MALLOC),e)gnu.a 718LIBEGNU_ARCHIVE = $(lib)/libgnu.a
722 719
723$(LIBEGNU_ARCHIVE): $(config_h) 720$(LIBEGNU_ARCHIVE): $(config_h)
724 $(MAKE) -C $(dir $@) all 721 $(MAKE) -C $(dir $@) all
diff --git a/src/alloc.c b/src/alloc.c
index eb2e9fae783..642cccc97c6 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -127,7 +127,7 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
127 marked objects. */ 127 marked objects. */
128 128
129#if (defined SYSTEM_MALLOC || defined DOUG_LEA_MALLOC \ 129#if (defined SYSTEM_MALLOC || defined DOUG_LEA_MALLOC \
130 || defined HYBRID_MALLOC || GC_CHECK_MARKED_OBJECTS) 130 || GC_CHECK_MARKED_OBJECTS)
131#undef GC_MALLOC_CHECK 131#undef GC_MALLOC_CHECK
132#endif 132#endif
133 133
@@ -460,7 +460,7 @@ static void gc_sweep (void);
460static Lisp_Object make_pure_vector (ptrdiff_t); 460static Lisp_Object make_pure_vector (ptrdiff_t);
461static void mark_buffer (struct buffer *); 461static void mark_buffer (struct buffer *);
462 462
463#if !defined REL_ALLOC || defined SYSTEM_MALLOC || defined HYBRID_MALLOC 463#if !defined REL_ALLOC || defined SYSTEM_MALLOC
464static void refill_memory_reserve (void); 464static void refill_memory_reserve (void);
465#endif 465#endif
466static void compact_small_strings (void); 466static void compact_small_strings (void);
@@ -644,7 +644,7 @@ struct Lisp_Finalizer doomed_finalizers;
644 Malloc 644 Malloc
645 ************************************************************************/ 645 ************************************************************************/
646 646
647#if defined SIGDANGER || (!defined SYSTEM_MALLOC && !defined HYBRID_MALLOC) 647#if defined SIGDANGER || (!defined SYSTEM_MALLOC)
648 648
649/* Function malloc calls this if it finds we are near exhausting storage. */ 649/* Function malloc calls this if it finds we are near exhausting storage. */
650 650
@@ -1066,19 +1066,14 @@ lisp_free (void *block)
1066# define BLOCK_ALIGN (1 << 15) 1066# define BLOCK_ALIGN (1 << 15)
1067static_assert (POWER_OF_2 (BLOCK_ALIGN)); 1067static_assert (POWER_OF_2 (BLOCK_ALIGN));
1068 1068
1069/* Use aligned_alloc if it or a simple substitute is available. 1069/* Use aligned_alloc if it or a simple substitute is available. */
1070 Aligned allocation is incompatible with unexmacosx.c, so don't use 1070
1071 it on Darwin if HAVE_UNEXEC. */ 1071#if (defined HAVE_ALIGNED_ALLOC \
1072 1072 || (!defined SYSTEM_MALLOC && !defined DOUG_LEA_MALLOC))
1073#if ! (defined DARWIN_OS && defined HAVE_UNEXEC) 1073# define USE_ALIGNED_ALLOC 1
1074# if (defined HAVE_ALIGNED_ALLOC \ 1074#elif defined HAVE_POSIX_MEMALIGN
1075 || (defined HYBRID_MALLOC \ 1075# define USE_ALIGNED_ALLOC 1
1076 ? defined HAVE_POSIX_MEMALIGN \ 1076# define aligned_alloc my_aligned_alloc /* Avoid collision with lisp.h. */
1077 : !defined SYSTEM_MALLOC && !defined DOUG_LEA_MALLOC))
1078# define USE_ALIGNED_ALLOC 1
1079# elif !defined HYBRID_MALLOC && defined HAVE_POSIX_MEMALIGN
1080# define USE_ALIGNED_ALLOC 1
1081# define aligned_alloc my_aligned_alloc /* Avoid collision with lisp.h. */
1082static void * 1077static void *
1083aligned_alloc (size_t alignment, size_t size) 1078aligned_alloc (size_t alignment, size_t size)
1084{ 1079{
@@ -1095,7 +1090,6 @@ aligned_alloc (size_t alignment, size_t size)
1095 void *p; 1090 void *p;
1096 return posix_memalign (&p, alignment, size) == 0 ? p : 0; 1091 return posix_memalign (&p, alignment, size) == 0 ? p : 0;
1097} 1092}
1098# endif
1099#endif 1093#endif
1100 1094
1101/* Padding to leave at the end of a malloc'd block. This is to give 1095/* Padding to leave at the end of a malloc'd block. This is to give
@@ -4433,7 +4427,7 @@ memory_full (size_t nbytes)
4433void 4427void
4434refill_memory_reserve (void) 4428refill_memory_reserve (void)
4435{ 4429{
4436#if !defined SYSTEM_MALLOC && !defined HYBRID_MALLOC 4430#if !defined SYSTEM_MALLOC
4437 if (spare_memory[0] == 0) 4431 if (spare_memory[0] == 0)
4438 spare_memory[0] = malloc (SPARE_MEMORY); 4432 spare_memory[0] = malloc (SPARE_MEMORY);
4439 if (spare_memory[1] == 0) 4433 if (spare_memory[1] == 0)
diff --git a/src/conf_post.h b/src/conf_post.h
index 8d523c62eee..94d9342f154 100644
--- a/src/conf_post.h
+++ b/src/conf_post.h
@@ -93,31 +93,6 @@ typedef bool bool_bf;
93# define ADDRESS_SANITIZER false 93# define ADDRESS_SANITIZER false
94#endif 94#endif
95 95
96/* If HYBRID_MALLOC is defined (e.g., on Cygwin), emacs will use
97 gmalloc before dumping and the system malloc after dumping.
98 hybrid_malloc and friends, defined in gmalloc.c, are wrappers that
99 accomplish this. */
100#ifdef HYBRID_MALLOC
101#ifdef emacs
102#undef malloc
103#define malloc hybrid_malloc
104#undef realloc
105#define realloc hybrid_realloc
106#undef aligned_alloc
107#define aligned_alloc hybrid_aligned_alloc
108#undef calloc
109#define calloc hybrid_calloc
110#undef free
111#define free hybrid_free
112
113extern void *hybrid_malloc (size_t);
114extern void *hybrid_calloc (size_t, size_t);
115extern void hybrid_free (void *);
116extern void *hybrid_aligned_alloc (size_t, size_t);
117extern void *hybrid_realloc (void *, size_t);
118#endif /* emacs */
119#endif /* HYBRID_MALLOC */
120
121/* We have to go this route, rather than the old hpux9 approach of 96/* We have to go this route, rather than the old hpux9 approach of
122 renaming the functions via macros. The system's stdlib.h has fully 97 renaming the functions via macros. The system's stdlib.h has fully
123 prototyped declarations, which yields a conflicting definition of 98 prototyped declarations, which yields a conflicting definition of
diff --git a/src/emacs.c b/src/emacs.c
index 4e6f286d888..8e606604d6b 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -110,7 +110,6 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
110#include "composite.h" 110#include "composite.h"
111#include "dispextern.h" 111#include "dispextern.h"
112#include "regex-emacs.h" 112#include "regex-emacs.h"
113#include "sheap.h"
114#include "syntax.h" 113#include "syntax.h"
115#include "sysselect.h" 114#include "sysselect.h"
116#include "systime.h" 115#include "systime.h"
@@ -1565,7 +1564,7 @@ main (int argc, char **argv)
1565 1564
1566 emacs_backtrace (-1); 1565 emacs_backtrace (-1);
1567 1566
1568#if !defined SYSTEM_MALLOC && !defined HYBRID_MALLOC 1567#if !defined SYSTEM_MALLOC
1569 /* Arrange to get warning messages as memory fills up. */ 1568 /* Arrange to get warning messages as memory fills up. */
1570 memory_warnings (0, malloc_warning); 1569 memory_warnings (0, malloc_warning);
1571 1570
@@ -1573,7 +1572,7 @@ main (int argc, char **argv)
1573 Also call realloc and free for consistency. */ 1572 Also call realloc and free for consistency. */
1574 free (realloc (malloc (4), 4)); 1573 free (realloc (malloc (4), 4));
1575 1574
1576#endif /* not SYSTEM_MALLOC and not HYBRID_MALLOC */ 1575#endif /* not SYSTEM_MALLOC */
1577 1576
1578#ifdef MSDOS 1577#ifdef MSDOS
1579 set_binary_mode (STDIN_FILENO, O_BINARY); 1578 set_binary_mode (STDIN_FILENO, O_BINARY);
@@ -1879,7 +1878,7 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem
1879 } 1878 }
1880 1879
1881#if defined HAVE_PTHREAD && !defined SYSTEM_MALLOC \ 1880#if defined HAVE_PTHREAD && !defined SYSTEM_MALLOC \
1882 && !defined DOUG_LEA_MALLOC && !defined HYBRID_MALLOC 1881 && !defined DOUG_LEA_MALLOC
1883 /* Do not make gmalloc thread-safe when creating bootstrap-emacs, as 1882 /* Do not make gmalloc thread-safe when creating bootstrap-emacs, as
1884 that causes an infinite recursive loop with FreeBSD. See 1883 that causes an infinite recursive loop with FreeBSD. See
1885 Bug#14569. The part of this bug involving Cygwin is no longer 1884 Bug#14569. The part of this bug involving Cygwin is no longer
diff --git a/src/gmalloc.c b/src/gmalloc.c
index 1faf6506167..8377cb7bf94 100644
--- a/src/gmalloc.c
+++ b/src/gmalloc.c
@@ -21,7 +21,7 @@ License along with this library. If not, see <https://www.gnu.org/licenses/>.
21 21
22#include <config.h> 22#include <config.h>
23 23
24#if defined HAVE_PTHREAD && !defined HYBRID_MALLOC 24#if defined HAVE_PTHREAD
25#define USE_PTHREAD 25#define USE_PTHREAD
26#endif 26#endif
27 27
@@ -57,13 +57,6 @@ extern void *(*__morecore) (ptrdiff_t);
57extern void (*__MALLOC_HOOK_VOLATILE __malloc_initialize_hook) (void); 57extern void (*__MALLOC_HOOK_VOLATILE __malloc_initialize_hook) (void);
58#endif /* !defined HAVE_MALLOC_H || glibc >= 2.24 */ 58#endif /* !defined HAVE_MALLOC_H || glibc >= 2.24 */
59 59
60/* If HYBRID_MALLOC is defined, then temacs will use malloc,
61 realloc... as defined in this file (and renamed gmalloc,
62 grealloc... via the macros that follow). The dumped emacs,
63 however, will use the system malloc, realloc.... In other source
64 files, malloc, realloc... are renamed hybrid_malloc,
65 hybrid_realloc... via macros in conf_post.h. hybrid_malloc and
66 friends are wrapper functions defined later in this file. */
67#undef malloc 60#undef malloc
68#undef realloc 61#undef realloc
69#undef calloc 62#undef calloc
@@ -76,19 +69,11 @@ extern void (*__MALLOC_HOOK_VOLATILE __malloc_initialize_hook) (void);
76#define free gfree 69#define free gfree
77#define malloc_info gmalloc_info 70#define malloc_info gmalloc_info
78 71
79#ifdef HYBRID_MALLOC
80# include "sheap.h"
81#endif
82
83#ifdef __cplusplus 72#ifdef __cplusplus
84extern "C" 73extern "C"
85{ 74{
86#endif 75#endif
87 76
88#ifdef HYBRID_MALLOC
89#define extern static
90#endif
91
92/* Allocate SIZE bytes of memory. */ 77/* Allocate SIZE bytes of memory. */
93extern void *malloc (size_t size) ATTRIBUTE_MALLOC_SIZE ((1)); 78extern void *malloc (size_t size) ATTRIBUTE_MALLOC_SIZE ((1));
94/* Re-allocate the previously allocated block 79/* Re-allocate the previously allocated block
@@ -326,8 +311,6 @@ void (*__MALLOC_HOOK_VOLATILE __malloc_initialize_hook) (void);
326void (*__MALLOC_HOOK_VOLATILE __after_morecore_hook) (void); 311void (*__MALLOC_HOOK_VOLATILE __after_morecore_hook) (void);
327void *(*__morecore) (ptrdiff_t); 312void *(*__morecore) (ptrdiff_t);
328 313
329#ifndef HYBRID_MALLOC
330
331/* Pointer to the base of the first block. */ 314/* Pointer to the base of the first block. */
332char *_heapbase; 315char *_heapbase;
333 316
@@ -349,11 +332,9 @@ size_t _bytes_free;
349/* Are you experienced? */ 332/* Are you experienced? */
350int __malloc_initialized; 333int __malloc_initialized;
351 334
352#endif /* HYBRID_MALLOC */
353
354/* Number of extra blocks to get each time we ask for more core. 335/* Number of extra blocks to get each time we ask for more core.
355 This reduces the frequency of calling `(*__morecore)'. */ 336 This reduces the frequency of calling `(*__morecore)'. */
356#if defined DOUG_LEA_MALLOC || defined HYBRID_MALLOC || defined SYSTEM_MALLOC 337#if defined DOUG_LEA_MALLOC || defined SYSTEM_MALLOC
357static 338static
358#endif 339#endif
359size_t __malloc_extra_blocks; 340size_t __malloc_extra_blocks;
@@ -916,7 +897,7 @@ malloc (size_t size)
916 return (hook ? hook : _malloc_internal) (size); 897 return (hook ? hook : _malloc_internal) (size);
917} 898}
918 899
919#if !(defined (_LIBC) || defined (HYBRID_MALLOC)) 900#if !(defined (_LIBC))
920 901
921/* On some ANSI C systems, some libc functions call _malloc, _free 902/* On some ANSI C systems, some libc functions call _malloc, _free
922 and _realloc. Make them use the GNU functions. */ 903 and _realloc. Make them use the GNU functions. */
@@ -967,11 +948,8 @@ License along with this library. If not, see <https://www.gnu.org/licenses/>.
967/* Debugging hook for free. */ 948/* Debugging hook for free. */
968static void (*__MALLOC_HOOK_VOLATILE gfree_hook) (void *); 949static void (*__MALLOC_HOOK_VOLATILE gfree_hook) (void *);
969 950
970#ifndef HYBRID_MALLOC
971
972/* List of blocks allocated by aligned_alloc. */ 951/* List of blocks allocated by aligned_alloc. */
973struct alignlist *_aligned_blocks = NULL; 952struct alignlist *_aligned_blocks = NULL;
974#endif
975 953
976/* Return memory to the heap. 954/* Return memory to the heap.
977 Like `_free_internal' but don't lock mutex. */ 955 Like `_free_internal' but don't lock mutex. */
@@ -1242,7 +1220,6 @@ free (void *ptr)
1242 _free_internal (ptr); 1220 _free_internal (ptr);
1243} 1221}
1244 1222
1245#ifndef HYBRID_MALLOC
1246/* Define the `cfree' alias for `free'. */ 1223/* Define the `cfree' alias for `free'. */
1247#ifdef weak_alias 1224#ifdef weak_alias
1248weak_alias (free, cfree) 1225weak_alias (free, cfree)
@@ -1253,7 +1230,6 @@ cfree (void *ptr)
1253 free (ptr); 1230 free (ptr);
1254} 1231}
1255#endif 1232#endif
1256#endif
1257/* Change the size of a block allocated by `malloc'. 1233/* Change the size of a block allocated by `malloc'.
1258 Copyright 1990, 1991, 1992, 1993, 1994, 1995 Free Software Foundation, Inc. 1234 Copyright 1990, 1991, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
1259 Written May 1989 by Mike Haertel. 1235 Written May 1989 by Mike Haertel.
@@ -1496,12 +1472,6 @@ extern void *__sbrk (ptrdiff_t increment);
1496static void * 1472static void *
1497gdefault_morecore (ptrdiff_t increment) 1473gdefault_morecore (ptrdiff_t increment)
1498{ 1474{
1499#ifdef HYBRID_MALLOC
1500 if (!definitely_will_not_unexec_p ())
1501 {
1502 return bss_sbrk (increment);
1503 }
1504#endif
1505#ifdef HAVE_SBRK 1475#ifdef HAVE_SBRK
1506 void *result = (void *) __sbrk (increment); 1476 void *result = (void *) __sbrk (increment);
1507 if (result != (void *) -1) 1477 if (result != (void *) -1)
@@ -1611,7 +1581,6 @@ aligned_alloc (size_t alignment, size_t size)
1611} 1581}
1612 1582
1613/* Note that memalign and posix_memalign are not used in Emacs. */ 1583/* Note that memalign and posix_memalign are not used in Emacs. */
1614#ifndef HYBRID_MALLOC
1615/* An obsolete alias for aligned_alloc, for any old libraries that use 1584/* An obsolete alias for aligned_alloc, for any old libraries that use
1616 this alias. */ 1585 this alias. */
1617 1586
@@ -1621,8 +1590,6 @@ memalign (size_t alignment, size_t size)
1621 return aligned_alloc (alignment, size); 1590 return aligned_alloc (alignment, size);
1622} 1591}
1623 1592
1624/* If HYBRID_MALLOC is defined, we may want to use the system
1625 posix_memalign below. */
1626int 1593int
1627posix_memalign (void **memptr, size_t alignment, size_t size) 1594posix_memalign (void **memptr, size_t alignment, size_t size)
1628{ 1595{
@@ -1641,7 +1608,6 @@ posix_memalign (void **memptr, size_t alignment, size_t size)
1641 1608
1642 return 0; 1609 return 0;
1643} 1610}
1644#endif
1645 1611
1646/* Allocate memory on a page boundary. 1612/* Allocate memory on a page boundary.
1647 Copyright (C) 1991, 92, 93, 94, 96 Free Software Foundation, Inc. 1613 Copyright (C) 1991, 92, 93, 94, 96 Free Software Foundation, Inc.
@@ -1662,18 +1628,16 @@ License along with this library. If not, see <https://www.gnu.org/licenses/>.
1662 The author may be reached (Email) at the address mike@ai.mit.edu, 1628 The author may be reached (Email) at the address mike@ai.mit.edu,
1663 or (US mail) as Mike Haertel c/o Free Software Foundation. */ 1629 or (US mail) as Mike Haertel c/o Free Software Foundation. */
1664 1630
1665#ifndef HYBRID_MALLOC 1631#ifndef HAVE_MALLOC_H
1666
1667# ifndef HAVE_MALLOC_H
1668/* Allocate SIZE bytes on a page boundary. */ 1632/* Allocate SIZE bytes on a page boundary. */
1669extern void *valloc (size_t); 1633extern void *valloc (size_t);
1670# endif 1634#endif
1671 1635
1672# if defined _SC_PAGESIZE || !defined HAVE_GETPAGESIZE 1636#if defined _SC_PAGESIZE || !defined HAVE_GETPAGESIZE
1673# include "getpagesize.h" 1637# include "getpagesize.h"
1674# elif !defined getpagesize 1638#elif !defined getpagesize
1675extern int getpagesize (void); 1639extern int getpagesize (void);
1676# endif 1640#endif
1677 1641
1678static size_t pagesize; 1642static size_t pagesize;
1679 1643
@@ -1685,7 +1649,6 @@ valloc (size_t size)
1685 1649
1686 return aligned_alloc (pagesize, size); 1650 return aligned_alloc (pagesize, size);
1687} 1651}
1688#endif /* HYBRID_MALLOC */
1689 1652
1690#undef malloc 1653#undef malloc
1691#undef realloc 1654#undef realloc
@@ -1693,116 +1656,6 @@ valloc (size_t size)
1693#undef aligned_alloc 1656#undef aligned_alloc
1694#undef free 1657#undef free
1695 1658
1696#ifdef HYBRID_MALLOC
1697
1698/* Assuming PTR was allocated via the hybrid malloc, return true if
1699 PTR was allocated via gmalloc, not the system malloc. Also, return
1700 true if _heaplimit is zero; this can happen temporarily when
1701 gmalloc calls itself for internal use, and in that case PTR is
1702 already known to be allocated via gmalloc. */
1703
1704static bool
1705allocated_via_gmalloc (void *ptr)
1706{
1707 if (!__malloc_initialized)
1708 return false;
1709 size_t block = BLOCK (ptr);
1710 size_t blockmax = _heaplimit - 1;
1711 return block <= blockmax && _heapinfo[block].busy.type != 0;
1712}
1713
1714/* See the comments near the beginning of this file for explanations
1715 of the following functions. */
1716
1717void *
1718hybrid_malloc (size_t size)
1719{
1720 if (definitely_will_not_unexec_p ())
1721 return malloc (size);
1722 return gmalloc (size);
1723}
1724
1725void *
1726hybrid_calloc (size_t nmemb, size_t size)
1727{
1728 if (definitely_will_not_unexec_p ())
1729 return calloc (nmemb, size);
1730 return gcalloc (nmemb, size);
1731}
1732
1733static void
1734hybrid_free_1 (void *ptr)
1735{
1736 if (allocated_via_gmalloc (ptr))
1737 gfree (ptr);
1738 else
1739 free (ptr);
1740}
1741
1742void
1743hybrid_free (void *ptr)
1744{
1745 /* Stolen from Gnulib, to make sure we preserve errno. */
1746#if defined __GNUC__ && !defined __clang__
1747 int err[2];
1748 err[0] = errno;
1749 err[1] = errno;
1750 errno = 0;
1751 hybrid_free_1 (ptr);
1752 errno = err[errno == 0];
1753#else
1754 int err = errno;
1755 hybrid_free_1 (ptr);
1756 errno = err;
1757#endif
1758}
1759
1760#if defined HAVE_ALIGNED_ALLOC || defined HAVE_POSIX_MEMALIGN
1761void *
1762hybrid_aligned_alloc (size_t alignment, size_t size)
1763{
1764 if (!definitely_will_not_unexec_p ())
1765 return galigned_alloc (alignment, size);
1766 /* The following is copied from alloc.c */
1767#ifdef HAVE_ALIGNED_ALLOC
1768 return aligned_alloc (alignment, size);
1769#else /* HAVE_POSIX_MEMALIGN */
1770 void *p;
1771 return posix_memalign (&p, alignment, size) == 0 ? p : 0;
1772#endif
1773}
1774#endif
1775
1776void *
1777hybrid_realloc (void *ptr, size_t size)
1778{
1779 void *result;
1780 int type;
1781 size_t block, oldsize;
1782
1783 if (!ptr)
1784 return hybrid_malloc (size);
1785 if (!allocated_via_gmalloc (ptr))
1786 return realloc (ptr, size);
1787 if (!definitely_will_not_unexec_p ())
1788 return grealloc (ptr, size);
1789
1790 /* The dumped emacs is trying to realloc storage allocated before
1791 dumping via gmalloc. Allocate new space and copy the data. Do
1792 not bother with gfree (ptr), as that would just waste time. */
1793 block = BLOCK (ptr);
1794 type = _heapinfo[block].busy.type;
1795 oldsize =
1796 type < 0 ? _heapinfo[block].busy.info.size * BLOCKSIZE
1797 : (size_t) 1 << type;
1798 result = malloc (size);
1799 if (result)
1800 return memcpy (result, ptr, min (oldsize, size));
1801 return result;
1802}
1803
1804#else /* ! HYBRID_MALLOC */
1805
1806void * 1659void *
1807malloc (size_t size) 1660malloc (size_t size)
1808{ 1661{
@@ -1833,8 +1686,6 @@ realloc (void *ptr, size_t size)
1833 return grealloc (ptr, size); 1686 return grealloc (ptr, size);
1834} 1687}
1835 1688
1836#endif /* HYBRID_MALLOC */
1837
1838#ifdef GC_MCHECK 1689#ifdef GC_MCHECK
1839 1690
1840/* Standard debugging hooks for `malloc'. 1691/* Standard debugging hooks for `malloc'.
diff --git a/src/lastfile.c b/src/lastfile.c
index c6baad4ac01..9f2b2a04958 100644
--- a/src/lastfile.c
+++ b/src/lastfile.c
@@ -38,7 +38,7 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
38 38
39#include "lisp.h" 39#include "lisp.h"
40 40
41#if ((!defined SYSTEM_MALLOC && !defined HYBRID_MALLOC) \ 41#if (!defined SYSTEM_MALLOC \
42 || defined WINDOWSNT || defined CYGWIN || defined DARWIN_OS) 42 || defined WINDOWSNT || defined CYGWIN || defined DARWIN_OS)
43char my_edata[] = "End of Emacs initialized data"; 43char my_edata[] = "End of Emacs initialized data";
44#endif 44#endif
diff --git a/src/lisp.h b/src/lisp.h
index a7b84b25b81..f795cf72da2 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -4444,7 +4444,7 @@ extern AVOID buffer_memory_full (ptrdiff_t);
4444extern bool survives_gc_p (Lisp_Object); 4444extern bool survives_gc_p (Lisp_Object);
4445extern void mark_object (Lisp_Object); 4445extern void mark_object (Lisp_Object);
4446extern void mark_objects (Lisp_Object *, ptrdiff_t); 4446extern void mark_objects (Lisp_Object *, ptrdiff_t);
4447#if defined REL_ALLOC && !defined SYSTEM_MALLOC && !defined HYBRID_MALLOC 4447#if defined REL_ALLOC && !defined SYSTEM_MALLOC
4448extern void refill_memory_reserve (void); 4448extern void refill_memory_reserve (void);
4449#endif 4449#endif
4450extern void mark_c_stack (char const *, char const *); 4450extern void mark_c_stack (char const *, char const *);
@@ -4687,7 +4687,7 @@ void *hash_table_alloc_bytes (ptrdiff_t nbytes) ATTRIBUTE_MALLOC_SIZE ((1));
4687void hash_table_free_bytes (void *p, ptrdiff_t nbytes); 4687void hash_table_free_bytes (void *p, ptrdiff_t nbytes);
4688 4688
4689/* Defined in gmalloc.c. */ 4689/* Defined in gmalloc.c. */
4690#if !defined DOUG_LEA_MALLOC && !defined HYBRID_MALLOC && !defined SYSTEM_MALLOC 4690#if !defined DOUG_LEA_MALLOC && !defined SYSTEM_MALLOC
4691extern size_t __malloc_extra_blocks; 4691extern size_t __malloc_extra_blocks;
4692#endif 4692#endif
4693#if !HAVE_DECL_ALIGNED_ALLOC 4693#if !HAVE_DECL_ALIGNED_ALLOC
diff --git a/src/ralloc.c b/src/ralloc.c
index 5724ae65d33..f7688561662 100644
--- a/src/ralloc.c
+++ b/src/ralloc.c
@@ -1162,7 +1162,7 @@ r_alloc_init (void)
1162 r_alloc_initialized = 1; 1162 r_alloc_initialized = 1;
1163 1163
1164 page_size = PAGE; 1164 page_size = PAGE;
1165#if !defined SYSTEM_MALLOC && !defined HYBRID_MALLOC 1165#if !defined SYSTEM_MALLOC
1166 real_morecore = __morecore; 1166 real_morecore = __morecore;
1167 __morecore = r_alloc_sbrk; 1167 __morecore = r_alloc_sbrk;
1168 1168
@@ -1181,7 +1181,7 @@ r_alloc_init (void)
1181 mallopt (M_TOP_PAD, 64 * 4096); 1181 mallopt (M_TOP_PAD, 64 * 4096);
1182 unblock_input (); 1182 unblock_input ();
1183#else 1183#else
1184#if !defined SYSTEM_MALLOC && !defined HYBRID_MALLOC 1184#if !defined SYSTEM_MALLOC
1185 /* Give GNU malloc's morecore some hysteresis so that we move all 1185 /* Give GNU malloc's morecore some hysteresis so that we move all
1186 the relocatable blocks much less often. The number used to be 1186 the relocatable blocks much less often. The number used to be
1187 64, but alloc.c would override that with 32 in code that was 1187 64, but alloc.c would override that with 32 in code that was
@@ -1194,7 +1194,7 @@ r_alloc_init (void)
1194#endif 1194#endif
1195#endif 1195#endif
1196 1196
1197#if !defined SYSTEM_MALLOC && !defined HYBRID_MALLOC 1197#if !defined SYSTEM_MALLOC
1198 first_heap->end = (void *) PAGE_ROUNDUP (first_heap->start); 1198 first_heap->end = (void *) PAGE_ROUNDUP (first_heap->start);
1199 1199
1200 /* The extra call to real_morecore guarantees that the end of the 1200 /* The extra call to real_morecore guarantees that the end of the
diff --git a/src/sysdep.c b/src/sysdep.c
index e0ec74d8364..93e3e1bd5bf 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -287,11 +287,7 @@ get_current_dir_name_or_unreachable (void)
287#endif 287#endif
288 288
289# if HAVE_GET_CURRENT_DIR_NAME && !BROKEN_GET_CURRENT_DIR_NAME 289# if HAVE_GET_CURRENT_DIR_NAME && !BROKEN_GET_CURRENT_DIR_NAME
290# ifdef HYBRID_MALLOC
291 bool use_libc = will_dump_with_unexec_p ();
292# else
293 bool use_libc = true; 290 bool use_libc = true;
294# endif
295 if (use_libc) 291 if (use_libc)
296 { 292 {
297 /* For an unreachable directory, this returns a string that starts 293 /* For an unreachable directory, this returns a string that starts
diff --git a/src/xdisp.c b/src/xdisp.c
index 7b0e2644078..d5ec3e404d0 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -28751,7 +28751,7 @@ decode_mode_spec (struct window *w, register int c, int field_width,
28751 } 28751 }
28752 28752
28753 case 'e': 28753 case 'e':
28754#if !defined SYSTEM_MALLOC && !defined HYBRID_MALLOC 28754#if !defined SYSTEM_MALLOC
28755 { 28755 {
28756 if (NILP (Vmemory_full)) 28756 if (NILP (Vmemory_full))
28757 return ""; 28757 return "";