aboutsummaryrefslogtreecommitdiffstats
path: root/src/sheap.c
diff options
context:
space:
mode:
authorPaul Eggert2016-01-30 14:20:57 -0800
committerPaul Eggert2016-01-30 15:26:07 -0800
commite1a9f2099c2e683dffc4b898ce85ce935c4cb254 (patch)
tree14f8b080fb8515b81111dc269e37aa01f73b16fc /src/sheap.c
parent874c59a81b7ee12a739149c5229e6d3bbd463324 (diff)
downloademacs-e1a9f2099c2e683dffc4b898ce85ce935c4cb254.tar.gz
emacs-e1a9f2099c2e683dffc4b898ce85ce935c4cb254.zip
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)
Diffstat (limited to 'src/sheap.c')
-rw-r--r--src/sheap.c83
1 files changed, 29 insertions, 54 deletions
diff --git a/src/sheap.c b/src/sheap.c
index 1451eca8ce7..fe905ca0c02 100644
--- a/src/sheap.c
+++ b/src/sheap.c
@@ -19,87 +19,62 @@ You should have received a copy of the GNU General Public License
19along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ 19along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
20 20
21#include <config.h> 21#include <config.h>
22
23#include "sheap.h"
24
22#include <stdio.h> 25#include <stdio.h>
23#include "lisp.h" 26#include "lisp.h"
24#include <unistd.h> 27#include <unistd.h>
25#include <stdlib.h> /* for exit */ 28#include <stdlib.h> /* for exit */
26 29
27#ifdef ENABLE_CHECKING 30static int debug_sheap;
28#define STATIC_HEAP_SIZE (28 * 1024 * 1024)
29#else
30#define STATIC_HEAP_SIZE (19 * 1024 * 1024)
31#endif
32
33int debug_sheap = 0;
34
35#define BLOCKSIZE 4096
36 31
37char bss_sbrk_buffer[STATIC_HEAP_SIZE]; 32char bss_sbrk_buffer[STATIC_HEAP_SIZE];
38/* The following is needed in gmalloc.c */
39void *bss_sbrk_buffer_end = bss_sbrk_buffer + STATIC_HEAP_SIZE;
40char *bss_sbrk_ptr;
41char *max_bss_sbrk_ptr; 33char *max_bss_sbrk_ptr;
42int bss_sbrk_did_unexec; 34bool bss_sbrk_did_unexec;
43 35
44void * 36void *
45bss_sbrk (ptrdiff_t request_size) 37bss_sbrk (ptrdiff_t request_size)
46{ 38{
39 static char *bss_sbrk_ptr;
40
47 if (!bss_sbrk_ptr) 41 if (!bss_sbrk_ptr)
48 { 42 {
49 max_bss_sbrk_ptr = bss_sbrk_ptr = bss_sbrk_buffer; 43 max_bss_sbrk_ptr = bss_sbrk_ptr = bss_sbrk_buffer;
50#ifdef CYGWIN 44#ifdef CYGWIN
51 sbrk (BLOCKSIZE); /* force space for fork to work */ 45 /* Force space for fork to work. */
46 sbrk (4096);
52#endif 47#endif
53 } 48 }
54 49
55 if (!(int) request_size) 50 int used = bss_sbrk_ptr - bss_sbrk_buffer;
56 { 51
57 return (bss_sbrk_ptr); 52 if (request_size < -used)
58 }
59 else if (bss_sbrk_ptr + (int) request_size < bss_sbrk_buffer)
60 { 53 {
61 printf 54 printf (("attempt to free too much: "
62 ("attempt to free too much: avail %d used %d failed request %d\n", 55 "avail %d used %d failed request %"pD"d\n"),
63 STATIC_HEAP_SIZE, bss_sbrk_ptr - bss_sbrk_buffer, 56 STATIC_HEAP_SIZE, used, request_size);
64 (int) request_size);
65 exit (-1); 57 exit (-1);
66 return 0; 58 return 0;
67 } 59 }
68 else if (bss_sbrk_ptr + (int) request_size > 60 else if (STATIC_HEAP_SIZE - used < request_size)
69 bss_sbrk_buffer + STATIC_HEAP_SIZE)
70 { 61 {
71 printf ("static heap exhausted: avail %d used %d failed request %d\n", 62 printf ("static heap exhausted: avail %d used %d failed request %"pD"d\n",
72 STATIC_HEAP_SIZE, 63 STATIC_HEAP_SIZE, used, request_size);
73 bss_sbrk_ptr - bss_sbrk_buffer, (int) request_size);
74 exit (-1); 64 exit (-1);
75 return 0; 65 return 0;
76 } 66 }
77 else if ((int) request_size < 0) 67
78 { 68 void *ret = bss_sbrk_ptr;
79 bss_sbrk_ptr += (int) request_size; 69 bss_sbrk_ptr += request_size;
80 if (debug_sheap) 70 if (max_bss_sbrk_ptr < bss_sbrk_ptr)
81 printf ("freed size %d\n", request_size); 71 max_bss_sbrk_ptr = bss_sbrk_ptr;
82 return bss_sbrk_ptr; 72 if (debug_sheap)
83 }
84 else
85 { 73 {
86 char *ret = bss_sbrk_ptr; 74 if (request_size < 0)
87 if (debug_sheap) 75 printf ("freed size %"pD"d\n", request_size);
88 printf ("allocated 0x%08x size %d\n", ret, request_size); 76 else
89 bss_sbrk_ptr += (int) request_size; 77 printf ("allocated %p size %"pD"d\n", ret, request_size);
90 if (bss_sbrk_ptr > max_bss_sbrk_ptr)
91 max_bss_sbrk_ptr = bss_sbrk_ptr;
92 return ret;
93 } 78 }
94} 79 return ret;
95
96void
97report_sheap_usage (int die_if_pure_storage_exceeded)
98{
99 char buf[200];
100 sprintf (buf, "Maximum static heap usage: %d of %d bytes",
101 max_bss_sbrk_ptr - bss_sbrk_buffer, STATIC_HEAP_SIZE);
102 /* Don't log messages, cause at this point, we're not allowed to create
103 buffers. */
104 message1_nolog (buf);
105} 80}