annotate src/sheap.c @ 269:b2472a1930f2 r20-5b33

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