Clean up RCS ids
[projects/cmucl/cmucl.git] / src / lisp / validate.c
1 /*
2  * Memory Validation
3  */
4
5 #include <stdio.h>
6 #include <unistd.h>
7 #include <string.h>
8 #include <stdlib.h>
9 #ifdef sparc
10 #include <alloca.h>
11 #endif
12
13 #include "lisp.h"
14 #include "os.h"
15 #include "globals.h"
16 #include "validate.h"
17 #include "internals.h"
18
19 #ifdef sparc
20 extern void make_holes(void);
21 #endif
22
23 static void
24 ensure_space(lispobj * start, size_t size)
25 {
26     if (os_validate((os_vm_address_t) start, size) == NULL) {
27         fprintf(stderr,
28                 "ensure_space: Failed to validate %ld bytes at 0x%08lx\n",
29                 (unsigned long) size, (unsigned long) start);
30         exit(1);
31     }
32 }
33
34
35 /* builtin_image_flag is used as a flag indicating that the lisp image is
36    built into the executable.  The other variables are set to actual values
37    in elf.c when the core section is mapped. FMG
38 */
39 extern int builtin_image_flag;
40 long image_dynamic_space_size = 0;
41 long image_read_only_space_size = 0;
42 long image_static_space_size = 0;
43
44 void
45 validate(void)
46 {
47     /* void *dynamic_space_data = NULL; */
48
49     /* Read-Only Space */
50     read_only_space = (lispobj *) READ_ONLY_SPACE_START;
51     /* Note that if the lisp core is not built into the image,
52        the below expression will be equal to this:
53        ensure_space(read_only_space, READ_ONLY_SPACE_SIZE);
54        FMG
55     */
56     ensure_space((lispobj *)((int)read_only_space + image_read_only_space_size),
57                  read_only_space_size - image_read_only_space_size);
58
59     /* Static Space */
60     static_space = (lispobj *) STATIC_SPACE_START;
61     /* Note that if the lisp core is not built into the image,
62        the below expression will be equal to this:
63        ensure_space(static_space, STATIC_SPACE_SIZE);
64        FMG
65     */
66     ensure_space((lispobj *)((int)static_space + image_static_space_size),
67                  static_space_size - image_static_space_size);
68
69     /* Dynamic-0 Space */
70     dynamic_0_space = (lispobj *) DYNAMIC_0_SPACE_START;
71     /* Note that if the lisp core is not built into the image,
72        the below expression will be equal to this:
73        ensure_space(dynamic_0_space, dynamic_space_size);
74        FMG
75     */
76     ensure_space((lispobj *)((int)dynamic_0_space + image_dynamic_space_size),
77                  dynamic_space_size - image_dynamic_space_size);
78
79     current_dynamic_space = dynamic_0_space;
80
81 #ifndef GENCGC
82     /* Dynamic-1 Space */
83     dynamic_1_space = (lispobj *) DYNAMIC_1_SPACE_START;
84     ensure_space(dynamic_1_space, dynamic_space_size);
85     /* I'm not sure about the following, or if the lisp executable
86        stuff will work with a garbage collector other than gencgc.
87        FMG
88     */
89     /*
90       if (builtin_image_flag != 0)
91       dynamic_space_data = alloca((int) (&image_dynamic_space_size));
92     */
93 #endif
94
95     /* Control Stack */
96     control_stack = (lispobj *) CONTROL_STACK_START;
97 #if (defined(i386) || defined(__x86_64))
98     control_stack_end = (lispobj *) (CONTROL_STACK_START + control_stack_size);
99 #endif
100     ensure_space(control_stack, control_stack_size);
101
102 #ifdef SIGNAL_STACK_START
103     ensure_space((lispobj *) SIGNAL_STACK_START, SIGNAL_STACK_SIZE);
104 #endif
105
106     /* Binding Stack */
107     binding_stack = (lispobj *) BINDING_STACK_START;
108     ensure_space(binding_stack, binding_stack_size);
109 #ifdef LINKAGE_TABLE
110     ensure_space((lispobj *) FOREIGN_LINKAGE_SPACE_START,
111                  FOREIGN_LINKAGE_SPACE_SIZE);
112 #endif
113 #ifdef sparc
114     make_holes();
115 #endif
116
117 #ifdef PRINTNOISE
118     printf(" done.\n");
119 #endif
120
121 #ifdef RED_ZONE_HIT
122     os_guard_control_stack(0, 1);
123 #endif
124 }