annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
251
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
1 /* Static Heap management routines for XEmacs.
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
2 Copyright (C) 1994, 1998 Free Software Foundation, Inc.
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
3
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
4 This file is part of XEmacs.
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
5
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
6 XEmacs is free software; you can redistribute it and/or modify it
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
7 under the terms of the GNU General Public License as published by the
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
8 Free Software Foundation; either version 2, or (at your option) any
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
9 later version.
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
10
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
14 for more details.
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
15
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
17 along with XEmacs; see the file COPYING. If not, write to the Free
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
18 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
19 02111-1307, USA.*/
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
20
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
21 #include "config.h"
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
22 #include <stdio.h>
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
23 #include <lisp.h>
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
24 #include <stddef.h>
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
25 #include "sheap-adjust.h"
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
26
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
27 #ifdef MULE
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
28 #define STATIC_HEAP_BASE 0x500000
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
29 #define STATIC_HEAP_SLOP 0x30000
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
30 #else
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
31 #define STATIC_HEAP_BASE 0x400000
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
32 #define STATIC_HEAP_SLOP 0x20000
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
33 #endif
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
34 #define STATIC_HEAP_SIZE \
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
35 (STATIC_HEAP_BASE + SHEAP_ADJUSTMENT + STATIC_HEAP_SLOP)
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
36 #define BLOCKSIZE (1<<12)
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
37 #define ALLOC_UNIT (BLOCKSIZE-1)
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
38 #define ALLOC_MASK ~((unsigned long)(ALLOC_UNIT))
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
39 #define ALIGN_ALLOC(addr) ((((unsigned long)addr) + ALLOC_UNIT) & ALLOC_MASK)
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
40
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
41 char static_heap_buffer[STATIC_HEAP_SIZE]={0};
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
42 char* static_heap_base=static_heap_buffer;
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
43 char* static_heap_ptr=static_heap_buffer;
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
44 unsigned long static_heap_size=STATIC_HEAP_SIZE;
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
45 int static_heap_initialized=0;
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
46 int static_heap_dumped=0;
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
47
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
48 void* more_static_core ( ptrdiff_t increment )
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
49 {
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
50 int size = (int) increment;
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
51 void *result;
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
52
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
53 if (!static_heap_initialized)
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
54 {
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
55 if (((unsigned long) static_heap_base & ~VALMASK) != 0)
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
56 {
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
57 printf ("error: The heap was allocated in upper memory.\n");
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
58 exit (-1);
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
59 }
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
60 static_heap_base=(char*)ALIGN_ALLOC(static_heap_buffer);
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
61 static_heap_ptr=static_heap_base;
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
62 static_heap_size=STATIC_HEAP_SIZE -
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
63 (static_heap_base-static_heap_buffer);
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
64 #ifdef __CYGWIN32__
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
65 sbrk(BLOCKSIZE); /* force space for fork to work */
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
66 #endif
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
67 static_heap_initialized=1;
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
68 }
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
69
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
70 result = static_heap_ptr;
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
71
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
72 /* we don't need to align - handled by gmalloc. */
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
73
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
74 if (size < 0)
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
75 {
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
76 if (static_heap_ptr + size < static_heap_base)
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
77 {
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
78 return 0;
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
79 }
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
80 }
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
81 else
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
82 {
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
83 if (static_heap_ptr + size >= static_heap_base + static_heap_size)
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
84 {
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
85 printf(
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
86
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
87 "\nRequested %d bytes, static heap exhausted! base is %p,\n
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
88 current ptr is %p. You have exhausted the static heap, if\n
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
89 you want to run temacs, adjust sheap-adjust.h to 0 or a +ve\n
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
90 number. If you are dumping then STATIC_HEAP_SLOP is too\n
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
91 small. Generally you should *not* try to run temacs with a\n
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
92 static heap, you should dump first.", size,
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
93 static_heap_base, static_heap_ptr);
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
94
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
95 exit(-1);
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
96 return 0;
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
97 }
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
98 }
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
99 static_heap_ptr += size;
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
100
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
101 return result;
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
102 }
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
103
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
104 void
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
105 sheap_adjust_h ()
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
106 {
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
107 FILE *stream = fopen ("sheap-adjust.h", "w");
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
108
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
109 if (stream == NULL)
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
110 report_file_error ("Opening sheap adjustment file",
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
111 Fcons (build_string ("sheap-adjust.h"), Qnil));
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
112
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
113 fprintf (stream,
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
114 "/*\tDo not edit this file!\n"
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
115 "\tAutomatically generated by XEmacs */\n"
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
116 "# define SHEAP_ADJUSTMENT (%d)\n",
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
117 ((static_heap_ptr - static_heap_buffer) - STATIC_HEAP_BASE));
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
118 fclose (stream);
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
119 }