0.7.6.1:
[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 #include <stdio.h>
17 #include <stdlib.h>
18
19 #include "runtime.h"
20 #include "os.h"
21 #include "globals.h"
22 #include "sbcl.h"
23 #include "validate.h"
24
25 static void
26 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%08lx\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
42 make_holes(void)
43 {
44     int i;
45
46     for (i = 0; i < sizeof(holes)/sizeof(holes[0]); i++) {
47         if (os_validate(holes[i], HOLE_SIZE) == NULL) {
48             fprintf(stderr,
49                     "make_holes: failed to validate %ld bytes at 0x%08X\n",
50                     HOLE_SIZE,
51                     (unsigned long)holes[i]);
52             exit(1);
53         }
54         os_protect(holes[i], HOLE_SIZE, 0);
55     }
56 }
57 #endif
58
59 void
60 validate(void)
61 {
62 #ifdef PRINTNOISE
63     printf("validating memory ...");
64     fflush(stdout);
65 #endif
66     
67     ensure_space( (lispobj *)READ_ONLY_SPACE_START, READ_ONLY_SPACE_SIZE);
68     ensure_space( (lispobj *)STATIC_SPACE_START   , STATIC_SPACE_SIZE);
69 #ifdef GENCGC
70     ensure_space( (lispobj *)DYNAMIC_SPACE_START  , DYNAMIC_SPACE_SIZE);
71 #else
72     ensure_space( (lispobj *)DYNAMIC_0_SPACE_START  , DYNAMIC_SPACE_SIZE);
73     ensure_space( (lispobj *)DYNAMIC_1_SPACE_START  , DYNAMIC_SPACE_SIZE);
74 #endif
75     ensure_space( (lispobj *)CONTROL_STACK_START  , CONTROL_STACK_SIZE);
76     ensure_space( (lispobj *)BINDING_STACK_START  , BINDING_STACK_SIZE);
77 #ifdef LISP_FEATURE_C_STACK_IS_CONTROL_STACK
78     ensure_space( (lispobj *) ALTERNATE_SIGNAL_STACK_START, SIGSTKSZ);
79 #endif
80
81 #ifdef HOLES
82     make_holes();
83 #endif
84 #ifndef GENCGC
85     current_dynamic_space = DYNAMIC_0_SPACE_START;
86 #endif
87     
88 #ifdef PRINTNOISE
89     printf(" done.\n");
90 #endif
91     protect_control_stack_guard_page(1);
92 }
93
94 void protect_control_stack_guard_page(int protect_p) {
95     os_protect(CONTROL_STACK_GUARD_PAGE,
96                os_vm_page_size,protect_p ?
97                (OS_VM_PROT_READ|OS_VM_PROT_EXECUTE) : OS_VM_PROT_ALL);
98 }
99