annotate src/sheap.c @ 278:90d73dddcdc4 r21-0b37

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