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