1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2026-02-20 07:00:31 -08:00
emacs/src/sheap.c
Paul Eggert e1a9f2099c Pacify --enable-gcc-warnings when HYBRID_MALLOC
* src/buffer.c (init_buffer):
* src/emacs.c (main):
* src/xsmfns.c (smc_save_yourself_CB, x_session_initialize):
Use emacs_get_current_dir_name, not get_current_dir_name.
* src/conf_post.h (aligned_alloc) [HYBRID_MALLOC && emacs]: New macro.
(HYBRID_GET_CURRENT_DIR_NAME, get_current_dir_name): Remove.
* src/emacs.c: Include "sheap.h".
(report_sheap_usage): Remove decl.
(Fdump_emacs) [HYBRID_MALLOC]: Report usage directly.
Don't assume ptrdiff_t can be printed as int.
* src/gmalloc.c [HYBRID_MALLOC]:
Include "sheap.h" rather than declaring its contents by hand.
(get_current_dir_name, gget_current_dir_name)
(hybrid_get_current_dir_name): Remove.
(emacs_abort): Remove duplicate decl.
(aligned_alloc): Undef, like malloc etc.
(ALLOCATED_BEFORE_DUMPING): Now a static function, not a macro.
Make it a bit more efficient.
(malloc_find_object_address): Remove unused decl.
(enum mcheck_status, mcheck, mprobe, mtrace, muntrace, struct mstats)
(mstats, memory_warnings): Declare only if GC_MCHECK.
* src/lisp.h (emacs_get_current_dir_name):
New decl, replacing get_current_dir_name.
* src/sheap.c: Include sheap.h first.
(STATIC_HEAP_SIZE): Remove; now in sheap.h.
(debug_sheap): Now static.
(bss_sbrk_buffer_end): Remove; no longer used.
(bss_sbrk_ptr): Now static and private.
(bss_sbrk_did_unexec): Now bool.
(BLOCKSIZE): Remove, to avoid GCC warning about its not being used.
(bss_sbrk): Don't treat request_size 0 as special, since the code
works without this being a special case.
Avoid overflow if request size exceeds INT_MAX.
(report_sheap_usage): Remove; now done in emacs.c.
* src/sheap.h: New file.
* src/sysdep.c (get_current_dir_name): Remove macro.
Include "sheap.h".
(emacs_get_current_dir_name): Rename function from
get_current_dir_name.  Handle HYBRID_MALLOC here;
this is simpler.
(Bug#22086)
2016-01-30 15:26:07 -08:00

80 lines
2.1 KiB
C

/* simulate `sbrk' with an array in .bss, for `unexec' support for Cygwin;
complete rewrite of xemacs Cygwin `unexec' code
Copyright (C) 2004-2016 Free Software Foundation, Inc.
This file is part of GNU Emacs.
GNU Emacs is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
GNU Emacs is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
#include <config.h>
#include "sheap.h"
#include <stdio.h>
#include "lisp.h"
#include <unistd.h>
#include <stdlib.h> /* for exit */
static int debug_sheap;
char bss_sbrk_buffer[STATIC_HEAP_SIZE];
char *max_bss_sbrk_ptr;
bool bss_sbrk_did_unexec;
void *
bss_sbrk (ptrdiff_t request_size)
{
static char *bss_sbrk_ptr;
if (!bss_sbrk_ptr)
{
max_bss_sbrk_ptr = bss_sbrk_ptr = bss_sbrk_buffer;
#ifdef CYGWIN
/* Force space for fork to work. */
sbrk (4096);
#endif
}
int used = bss_sbrk_ptr - bss_sbrk_buffer;
if (request_size < -used)
{
printf (("attempt to free too much: "
"avail %d used %d failed request %"pD"d\n"),
STATIC_HEAP_SIZE, used, request_size);
exit (-1);
return 0;
}
else if (STATIC_HEAP_SIZE - used < request_size)
{
printf ("static heap exhausted: avail %d used %d failed request %"pD"d\n",
STATIC_HEAP_SIZE, used, request_size);
exit (-1);
return 0;
}
void *ret = bss_sbrk_ptr;
bss_sbrk_ptr += request_size;
if (max_bss_sbrk_ptr < bss_sbrk_ptr)
max_bss_sbrk_ptr = bss_sbrk_ptr;
if (debug_sheap)
{
if (request_size < 0)
printf ("freed size %"pD"d\n", request_size);
else
printf ("allocated %p size %"pD"d\n", ret, request_size);
}
return ret;
}