aboutsummaryrefslogtreecommitdiffstats
path: root/src/gmalloc.c
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/gmalloc.c
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/gmalloc.c')
-rw-r--r--src/gmalloc.c167
1 files changed, 9 insertions, 158 deletions
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'.