251
|
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
|
267
|
21 #include <config.h>
|
251
|
22 #include <stdio.h>
|
267
|
23 #include "lisp.h"
|
251
|
24 #include <stddef.h>
|
278
|
25 #include <unistd.h>
|
272
|
26 #include <sheap-adjust.h>
|
251
|
27
|
263
|
28 #define STATIC_HEAP_BASE 0x600000
|
265
|
29 #define STATIC_HEAP_SLOP 0x40000
|
251
|
30 #define STATIC_HEAP_SIZE \
|
|
31 (STATIC_HEAP_BASE + SHEAP_ADJUSTMENT + STATIC_HEAP_SLOP)
|
|
32 #define BLOCKSIZE (1<<12)
|
|
33 #define ALLOC_UNIT (BLOCKSIZE-1)
|
|
34 #define ALLOC_MASK ~((unsigned long)(ALLOC_UNIT))
|
|
35 #define ALIGN_ALLOC(addr) ((((unsigned long)addr) + ALLOC_UNIT) & ALLOC_MASK)
|
|
36
|
|
37 char static_heap_buffer[STATIC_HEAP_SIZE]={0};
|
|
38 char* static_heap_base=static_heap_buffer;
|
|
39 char* static_heap_ptr=static_heap_buffer;
|
|
40 unsigned long static_heap_size=STATIC_HEAP_SIZE;
|
|
41 int static_heap_initialized=0;
|
|
42 int static_heap_dumped=0;
|
|
43
|
|
44 void* more_static_core ( ptrdiff_t increment )
|
|
45 {
|
|
46 int size = (int) increment;
|
|
47 void *result;
|
272
|
48
|
251
|
49 if (!static_heap_initialized)
|
|
50 {
|
|
51 if (((unsigned long) static_heap_base & ~VALMASK) != 0)
|
|
52 {
|
|
53 printf ("error: The heap was allocated in upper memory.\n");
|
|
54 exit (-1);
|
|
55 }
|
|
56 static_heap_base=(char*)ALIGN_ALLOC(static_heap_buffer);
|
|
57 static_heap_ptr=static_heap_base;
|
272
|
58 static_heap_size=STATIC_HEAP_SIZE -
|
251
|
59 (static_heap_base-static_heap_buffer);
|
|
60 #ifdef __CYGWIN32__
|
|
61 sbrk(BLOCKSIZE); /* force space for fork to work */
|
|
62 #endif
|
|
63 static_heap_initialized=1;
|
|
64 }
|
272
|
65
|
251
|
66 result = static_heap_ptr;
|
|
67
|
|
68 /* we don't need to align - handled by gmalloc. */
|
|
69
|
272
|
70 if (size < 0)
|
251
|
71 {
|
|
72 if (static_heap_ptr + size < static_heap_base)
|
|
73 {
|
|
74 return 0;
|
|
75 }
|
|
76 }
|
272
|
77 else
|
251
|
78 {
|
|
79 if (static_heap_ptr + size >= static_heap_base + static_heap_size)
|
|
80 {
|
|
81 printf(
|
|
82
|
259
|
83 "\nRequested %d bytes, static heap exhausted! base is %p, current ptr
|
|
84 is %p. You have exhausted the static heap, if you want to run temacs,
|
|
85 adjust sheap-adjust.h to 0 or a +ve number. If you are dumping then
|
|
86 STATIC_HEAP_SLOP is too small. Generally you should *not* try to run
|
|
87 temacs with a static heap, you should dump first.\n", size,
|
251
|
88 static_heap_base, static_heap_ptr);
|
|
89
|
|
90 exit(-1);
|
|
91 return 0;
|
|
92 }
|
|
93 }
|
|
94 static_heap_ptr += size;
|
272
|
95
|
251
|
96 return result;
|
|
97 }
|
|
98
|
|
99 void
|
|
100 sheap_adjust_h ()
|
|
101 {
|
|
102 FILE *stream = fopen ("sheap-adjust.h", "w");
|
|
103
|
|
104 if (stream == NULL)
|
|
105 report_file_error ("Opening sheap adjustment file",
|
|
106 Fcons (build_string ("sheap-adjust.h"), Qnil));
|
|
107
|
|
108 fprintf (stream,
|
|
109 "/*\tDo not edit this file!\n"
|
|
110 "\tAutomatically generated by XEmacs */\n"
|
|
111 "# define SHEAP_ADJUSTMENT (%d)\n",
|
|
112 ((static_heap_ptr - static_heap_buffer) - STATIC_HEAP_BASE));
|
|
113 fclose (stream);
|
|
114 }
|
259
|
115
|