diff options
author | Eli Zaretskii <eliz@gnu.org> | 2019-01-18 17:04:00 +0200 |
---|---|---|
committer | Eli Zaretskii <eliz@gnu.org> | 2019-01-18 17:04:00 +0200 |
commit | 5e3b0f5239027a413775d375f04376a3c97d0bf9 (patch) | |
tree | 7d6e6dbe03a405a2bd7e527e39a12fbf0dd1aa64 /src/w32proc.c | |
parent | f943409183559b0af0e89f52bf0a93f8431c2dcf (diff) | |
download | emacs-5e3b0f5239027a413775d375f04376a3c97d0bf9.tar.gz |
Clean up memory allocation and unexec support on MS-Windows
* src/w32heap.c (report_temacs_memory_usage): Condition on
!CANNOT_DUMP, in addition to ENABLE_CHECKING.
(init_heap): Accept an argument, which tells us what heap
allocation method to use.
(DUMPED_HEAP_SIZE) [CANNOT_DUMP]: Define to a small value, as
we don't use dumped_data[] in this case.
* src/w32heap.h (init_heap): Adjust prototype.
<using_dynamic_heap>: Remove declaration.
* src/emacs.c (main) [WINDOWSNT]: Determine heap allocation
method based on whether we are in temacs and whether unexec
will be used to dump Emacs. Pass the heap allocation method
to init_heap, which is now called after parsing the
--temacs=METHOD option.
* src/unexw32.c (unexec): Don't fiddle with using_dynamic_heap.
<using_dynamic_heap>: Remove definition.
* src/w32proc.c (malloc_before_init, realloc_before_init)
(free_before_init): New functions, to catch memory allocation
before heap allocation method is set up.
Diffstat (limited to 'src/w32proc.c')
-rw-r--r-- | src/w32proc.c | 37 |
1 files changed, 34 insertions, 3 deletions
diff --git a/src/w32proc.c b/src/w32proc.c index a5d08f60117..05e6c46b336 100644 --- a/src/w32proc.c +++ b/src/w32proc.c @@ -81,6 +81,36 @@ static sigset_t sig_mask; static CRITICAL_SECTION crit_sig; +/* Catch memory allocation before the heap allocation scheme is set + up. These functions should never be called, unless code is added + early on in 'main' that runs before init_heap is called. */ +_Noreturn void * malloc_before_init (size_t); +_Noreturn void * realloc_before_init (void *, size_t); +_Noreturn void free_before_init (void *); + +_Noreturn void * +malloc_before_init (size_t size) +{ + fprintf (stderr, + "error: 'malloc' called before setting up heap allocation; exiting.\n"); + exit (-1); +} + +_Noreturn void * +realloc_before_init (void *ptr, size_t size) +{ + fprintf (stderr, + "error: 'realloc' called before setting up heap allocation; exiting.\n"); + exit (-1); +} + +_Noreturn void +free_before_init (void *ptr) +{ + fprintf (stderr, + "error: 'free' called before setting up heap allocation; exiting.\n"); + exit (-1); +} extern BOOL ctrl_c_handler (unsigned long type); @@ -110,12 +140,13 @@ _start (void) DebugBreak (); #endif + the_malloc_fn = malloc_before_init; + the_realloc_fn = realloc_before_init; + the_free_fn = free_before_init; + /* Cache system info, e.g., the NT page size. */ cache_system_info (); - /* Grab our malloc arena space now, before CRT starts up. */ - init_heap (); - /* This prevents ctrl-c's in shells running while we're suspended from having us exit. */ SetConsoleCtrlHandler ((PHANDLER_ROUTINE) ctrl_c_handler, TRUE); |