Initial revision
[sbcl.git] / src / runtime / validate.c
1 /*
2  * memory validation
3  */
4
5 /*
6  * This software is part of the SBCL system. See the README file for
7  * more information.
8  *
9  * This software is derived from the CMU CL system, which was
10  * written at Carnegie Mellon University and released into the
11  * public domain. The software is in the public domain and is
12  * provided with absolutely no warranty. See the COPYING and CREDITS
13  * files for more information.
14  */
15
16 /*
17  * $Header$
18  */
19
20 #include <stdio.h>
21 #include "runtime.h"
22 #include "os.h"
23 #include "globals.h"
24 #include "validate.h"
25
26 static void ensure_space(lispobj *start, unsigned long size)
27 {
28     if (os_validate((os_vm_address_t)start,(os_vm_size_t)size)==NULL) {
29         fprintf(stderr,
30                 "ensure_space: failed to validate %ld bytes at 0x%08X\n",
31                 size,
32                 (unsigned long)start);
33         exit(1);
34     }
35 }
36
37 #ifdef HOLES
38
39 static os_vm_address_t holes[] = HOLES;
40
41 static void make_holes(void)
42 {
43     int i;
44
45     for (i = 0; i < sizeof(holes)/sizeof(holes[0]); i++) {
46         if (os_validate(holes[i], HOLE_SIZE) == NULL) {
47             fprintf(stderr,
48                     "make_holes: failed to validate %ld bytes at 0x%08X\n",
49                     HOLE_SIZE,
50                     (unsigned long)holes[i]);
51             exit(1);
52         }
53         os_protect(holes[i], HOLE_SIZE, 0);
54     }
55 }
56 #endif
57
58 void validate(void)
59 {
60 #ifdef PRINTNOISE
61         printf("validating memory ...");
62         fflush(stdout);
63 #endif
64
65         /* Read-Only Space */
66         read_only_space = (lispobj *) READ_ONLY_SPACE_START;
67         ensure_space(read_only_space, READ_ONLY_SPACE_SIZE);
68
69         /* Static Space */
70         static_space = (lispobj *) STATIC_SPACE_START;
71         ensure_space(static_space, STATIC_SPACE_SIZE);
72
73         /* Dynamic-0 Space */
74         dynamic_0_space = (lispobj *) DYNAMIC_0_SPACE_START;
75         ensure_space(dynamic_0_space, DYNAMIC_SPACE_SIZE);
76
77         current_dynamic_space = dynamic_0_space;
78
79         /* Dynamic-1 Space */
80         dynamic_1_space = (lispobj *) DYNAMIC_1_SPACE_START;
81 #ifndef GENCGC
82         ensure_space(dynamic_1_space, DYNAMIC_SPACE_SIZE);
83 #endif
84
85         /* Control Stack */
86         control_stack = (lispobj *) CONTROL_STACK_START;
87 #ifdef __i386__
88         control_stack_end = (lispobj *) (CONTROL_STACK_START
89                                          + CONTROL_STACK_SIZE);
90 #endif
91         ensure_space(control_stack, CONTROL_STACK_SIZE);
92
93         /* Binding Stack */
94         binding_stack = (lispobj *) BINDING_STACK_START;
95         ensure_space(binding_stack, BINDING_STACK_SIZE);
96
97 #ifdef HOLES
98         make_holes();
99 #endif
100
101 #ifdef PRINTNOISE
102         printf(" done.\n");
103 #endif
104 }