1 /* Static Heap management routines for SXEmacs.
2 Copyright (C) 1994, 1998 Free Software Foundation, Inc.
4 This file is part of SXEmacs
6 SXEmacs is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 SXEmacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 #include <sheap-adjust.h>
26 #define STATIC_HEAP_BASE 0x800000
27 #define STATIC_HEAP_SLOP 0x40000
28 #define STATIC_HEAP_SIZE \
29 (STATIC_HEAP_BASE + SHEAP_ADJUSTMENT + STATIC_HEAP_SLOP)
30 #define BLOCKSIZE (1<<12)
31 #define ALLOC_UNIT (BLOCKSIZE-1)
32 #define ALLOC_MASK ~((unsigned long)(ALLOC_UNIT))
33 #define ALIGN_ALLOC(addr) ((((unsigned long)addr) + ALLOC_UNIT) & ALLOC_MASK)
35 char static_heap_buffer[STATIC_HEAP_SIZE] = { 0 };
36 char *static_heap_base = static_heap_buffer;
37 char *static_heap_ptr = static_heap_buffer;
38 unsigned long static_heap_size = STATIC_HEAP_SIZE;
39 int static_heap_initialized = 0;
40 int static_heap_dumped = 0;
42 void *more_static_core(ptrdiff_t increment);
43 void *more_static_core(ptrdiff_t increment)
45 int size = (int)increment;
48 if (!static_heap_initialized) {
50 if (((unsigned long)static_heap_base & ~VALMASK) != 0) {
52 ("error: The heap was allocated in upper memory.\n");
56 static_heap_base = (char *)ALIGN_ALLOC(static_heap_buffer);
57 static_heap_ptr = static_heap_base;
58 static_heap_size = STATIC_HEAP_SIZE -
59 (static_heap_base - static_heap_buffer);
60 static_heap_initialized = 1;
63 result = static_heap_ptr;
65 /* we don't need to align - handled by gmalloc. */
68 if (static_heap_ptr + size < static_heap_base) {
72 if (static_heap_ptr + size >=
73 static_heap_base + static_heap_size) {
74 printf("\nRequested %d bytes, static heap exhausted! "
75 "base is %p, current ptr is %p. "
76 "You have exhausted the static heap.\n\n"
77 "If you are simply trying to compile, remove "
78 "sheap-adjust.h and recompile from the top "
79 "level.\nIf this doesn't work then "
80 "STATIC_HEAP_SLOP (defined in this file) is "
82 "If you want to run temacs, change "
83 "SHEAP_ADJUSTMENT in sheap-adjust.h\nto 0 or "
84 "a +ve number. Generally you should *not* try "
85 "to run temacs\nwith a static heap, you should "
86 "dump first.\n", size, static_heap_base,
93 static_heap_ptr += size;
98 static void sheap_adjust_h()
100 FILE *stream = fopen("sheap-adjust.h", "w");
103 report_file_error("Opening sheap adjustment file",
104 Fcons(build_string("sheap-adjust.h"), Qnil));
107 "/*\tDo not edit this file!\n"
108 "\tAutomatically generated by SXEmacs */\n"
109 "# define SHEAP_ADJUSTMENT (%d)\n",
110 ((static_heap_ptr - static_heap_buffer) - STATIC_HEAP_BASE));
114 void report_sheap_usage(int die_if_pure_storage_exceeded);
115 void report_sheap_usage(int die_if_pure_storage_exceeded)
119 size_t lost = (STATIC_HEAP_BASE + STATIC_HEAP_SLOP + SHEAP_ADJUSTMENT)
120 - (static_heap_ptr - static_heap_buffer);
122 int n = snprintf(buf, sizeof(buf), "Static heap usage: %ld of %ld",
123 (long)(static_heap_ptr - static_heap_buffer),
124 (long)(STATIC_HEAP_BASE + STATIC_HEAP_SLOP + SHEAP_ADJUSTMENT));
125 assert(n>=0 && n < sizeof(buf));
127 if (lost > STATIC_HEAP_SLOP) {
128 int len = strlen(buf);
129 n = snprintf(buf + len, sizeof(buf)-len, " -- %ldk wasted",
130 (long)(lost / 1024));
131 assert(n>=0 && n < (sizeof(buf)-len));
133 if (die_if_pure_storage_exceeded) {
143 ("Static heap size adjusted, Don't Panic! I will restart the `make'");