annotate src/sheap.c @ 353:3b3709405255 r21-1-6

Import from CVS: tag r21-1-6
author cvs
date Mon, 13 Aug 2007 10:55:33 +0200
parents 57709be46d1b
children 74fd4e045ea6
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 {
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
51 #ifdef VALMASK
251
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
52 if (((unsigned long) static_heap_base & ~VALMASK) != 0)
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
53 {
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
54 printf ("error: The heap was allocated in upper memory.\n");
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
55 exit (-1);
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
56 }
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
57 #endif
251
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
58 static_heap_base=(char*)ALIGN_ALLOC(static_heap_buffer);
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
59 static_heap_ptr=static_heap_base;
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 269
diff changeset
60 static_heap_size=STATIC_HEAP_SIZE -
251
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
61 (static_heap_base-static_heap_buffer);
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
62 #ifdef __CYGWIN32__
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
63 sbrk(BLOCKSIZE); /* force space for fork to work */
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
64 #endif
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
65 static_heap_initialized=1;
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
66 }
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 269
diff changeset
67
251
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
68 result = static_heap_ptr;
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
69
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
70 /* we don't need to align - handled by gmalloc. */
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
71
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 269
diff changeset
72 if (size < 0)
251
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 (static_heap_ptr + size < static_heap_base)
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
75 {
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
76 return 0;
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
77 }
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
78 }
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 269
diff changeset
79 else
251
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
80 {
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
81 if (static_heap_ptr + size >= static_heap_base + static_heap_size)
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
82 {
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
83 printf(
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
84
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents: 251
diff changeset
85 "\nRequested %d bytes, static heap exhausted! base is %p, current ptr
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 280
diff changeset
86 is %p. You have exhausted the static heap.
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 280
diff changeset
87
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 280
diff changeset
88 If you are simply trying to compile, remove sheap-adjust.h and
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 280
diff changeset
89 puresize-adjust.h and recompile from the top level. If this doesn't
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 280
diff changeset
90 work then STATIC_HEAP_SLOP (defined in this file) is too small.
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 280
diff changeset
91
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 280
diff changeset
92 If you want to run temacs, change SHEAP_ADJUSTMENT in sheap-adjust.h
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 280
diff changeset
93 to 0 or a +ve number. Generally you should *not* try to run temacs
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 280
diff changeset
94 with a static heap, you should dump first.\n", size,
251
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
95 static_heap_base, static_heap_ptr);
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
96
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
97 exit(-1);
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
98 return 0;
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
99 }
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
100 }
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
101 static_heap_ptr += size;
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 269
diff changeset
102
251
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
103 return result;
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
104 }
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
105
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
106 void
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
107 sheap_adjust_h ()
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
108 {
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
109 FILE *stream = fopen ("sheap-adjust.h", "w");
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
110
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
111 if (stream == NULL)
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
112 report_file_error ("Opening sheap adjustment file",
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
113 Fcons (build_string ("sheap-adjust.h"), Qnil));
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
114
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
115 fprintf (stream,
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
116 "/*\tDo not edit this file!\n"
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
117 "\tAutomatically generated by XEmacs */\n"
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
118 "# define SHEAP_ADJUSTMENT (%d)\n",
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
119 ((static_heap_ptr - static_heap_buffer) - STATIC_HEAP_BASE));
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
120 fclose (stream);
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents:
diff changeset
121 }
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents: 251
diff changeset
122