428
|
1 /* Static Heap management routines for XEmacs.
|
|
2 Copyright (C) 1994, 1998 Free Software Foundation, Inc.
|
|
3
|
|
4 This file is part of XEmacs.
|
|
5
|
|
6 XEmacs is free software; you can redistribute it and/or modify it
|
|
7 under the terms of the GNU General Public License as published by the
|
|
8 Free Software Foundation; either version 2, or (at your option) any
|
|
9 later version.
|
|
10
|
|
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 for more details.
|
|
15
|
|
16 You should have received a copy of the GNU General Public License
|
|
17 along with XEmacs; see the file COPYING. If not, write to the Free
|
|
18 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
19 02111-1307, USA.*/
|
|
20
|
|
21 #include <config.h>
|
|
22 #include "lisp.h"
|
442
|
23
|
428
|
24 #include <unistd.h>
|
|
25 #include <sheap-adjust.h>
|
|
26
|
|
27 #define STATIC_HEAP_BASE 0x800000
|
|
28 #define STATIC_HEAP_SLOP 0x40000
|
|
29 #define STATIC_HEAP_SIZE \
|
|
30 (STATIC_HEAP_BASE + SHEAP_ADJUSTMENT + STATIC_HEAP_SLOP)
|
|
31 #define BLOCKSIZE (1<<12)
|
|
32 #define ALLOC_UNIT (BLOCKSIZE-1)
|
|
33 #define ALLOC_MASK ~((unsigned long)(ALLOC_UNIT))
|
|
34 #define ALIGN_ALLOC(addr) ((((unsigned long)addr) + ALLOC_UNIT) & ALLOC_MASK)
|
|
35
|
|
36 char static_heap_buffer[STATIC_HEAP_SIZE]={0};
|
|
37 char* static_heap_base=static_heap_buffer;
|
|
38 char* static_heap_ptr=static_heap_buffer;
|
|
39 unsigned long static_heap_size=STATIC_HEAP_SIZE;
|
|
40 int static_heap_initialized=0;
|
|
41 int static_heap_dumped=0;
|
|
42
|
442
|
43 void* more_static_core ( ptrdiff_t increment );
|
428
|
44 void* more_static_core ( ptrdiff_t increment )
|
|
45 {
|
|
46 int size = (int) increment;
|
|
47 void *result;
|
|
48
|
|
49 if (!static_heap_initialized)
|
|
50 {
|
|
51 #ifdef VALMASK
|
|
52 if (((unsigned long) static_heap_base & ~VALMASK) != 0)
|
|
53 {
|
|
54 printf ("error: The heap was allocated in upper memory.\n");
|
|
55 exit (-1);
|
|
56 }
|
|
57 #endif
|
|
58 static_heap_base=(char*)ALIGN_ALLOC(static_heap_buffer);
|
|
59 static_heap_ptr=static_heap_base;
|
|
60 static_heap_size=STATIC_HEAP_SIZE -
|
|
61 (static_heap_base-static_heap_buffer);
|
442
|
62 #ifdef CYGWIN
|
428
|
63 sbrk(BLOCKSIZE); /* force space for fork to work */
|
|
64 #endif
|
|
65 static_heap_initialized=1;
|
|
66 }
|
|
67
|
|
68 result = static_heap_ptr;
|
|
69
|
|
70 /* we don't need to align - handled by gmalloc. */
|
|
71
|
|
72 if (size < 0)
|
|
73 {
|
|
74 if (static_heap_ptr + size < static_heap_base)
|
|
75 {
|
|
76 return 0;
|
|
77 }
|
|
78 }
|
|
79 else
|
|
80 {
|
|
81 if (static_heap_ptr + size >= static_heap_base + static_heap_size)
|
|
82 {
|
|
83 printf(
|
|
84
|
|
85 "\nRequested %d bytes, static heap exhausted! base is %p, current ptr
|
|
86 is %p. You have exhausted the static heap.
|
|
87
|
|
88 If you are simply trying to compile, remove sheap-adjust.h
|
|
89 and recompile from the top level. If this doesn't
|
|
90 work then STATIC_HEAP_SLOP (defined in this file) is too small.
|
|
91
|
|
92 If you want to run temacs, change SHEAP_ADJUSTMENT in sheap-adjust.h
|
|
93 to 0 or a +ve number. Generally you should *not* try to run temacs
|
|
94 with a static heap, you should dump first.\n", size,
|
|
95 static_heap_base, static_heap_ptr);
|
|
96
|
|
97 exit(-1);
|
|
98 return 0;
|
|
99 }
|
|
100 }
|
|
101 static_heap_ptr += size;
|
|
102
|
|
103 return result;
|
|
104 }
|
|
105
|
|
106 static void
|
|
107 sheap_adjust_h ()
|
|
108 {
|
|
109 FILE *stream = fopen ("sheap-adjust.h", "w");
|
|
110
|
|
111 if (stream == NULL)
|
|
112 report_file_error ("Opening sheap adjustment file",
|
563
|
113 build_string ("sheap-adjust.h"));
|
428
|
114
|
|
115 fprintf (stream,
|
|
116 "/*\tDo not edit this file!\n"
|
|
117 "\tAutomatically generated by XEmacs */\n"
|
|
118 "# define SHEAP_ADJUSTMENT (%d)\n",
|
|
119 ((static_heap_ptr - static_heap_buffer) - STATIC_HEAP_BASE));
|
|
120 fclose (stream);
|
|
121 }
|
|
122
|
442
|
123 void report_sheap_usage (int die_if_pure_storage_exceeded);
|
428
|
124 void
|
|
125 report_sheap_usage (int die_if_pure_storage_exceeded)
|
|
126 {
|
|
127 int rc = 0;
|
|
128
|
647
|
129 Memory_Count lost = (STATIC_HEAP_BASE + STATIC_HEAP_SLOP + SHEAP_ADJUSTMENT)
|
428
|
130 - (static_heap_ptr - static_heap_buffer);
|
|
131 char buf[200];
|
|
132 sprintf (buf, "Static heap usage: %ld of %ld",
|
|
133 (long) (static_heap_ptr - static_heap_buffer),
|
|
134 (long) (STATIC_HEAP_BASE + STATIC_HEAP_SLOP + SHEAP_ADJUSTMENT));
|
|
135
|
|
136 if (lost > STATIC_HEAP_SLOP) {
|
|
137 sprintf (buf + strlen (buf), " -- %ldk wasted", (long)(lost/1024));
|
|
138 if (die_if_pure_storage_exceeded) {
|
|
139 sheap_adjust_h();
|
|
140 rc = -1;
|
|
141 }
|
|
142 message ("%s", buf);
|
|
143 }
|
|
144
|
|
145 if (rc < 0) {
|
|
146 unlink("SATISFIED");
|
|
147 fatal ("Static heap size adjusted, Don't Panic! I will restart the `make'");
|
|
148 }
|
|
149 }
|
|
150
|
|
151
|