0.6.12.7.flaky1:
[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 "runtime.h"
18 #include "os.h"
19 #include "globals.h"
20 #include "sbcl.h"
21 #include "validate.h"
22
23 static void
24 ensure_space(lispobj *start, unsigned long size)
25 {
26     if (os_validate((os_vm_address_t)start,(os_vm_size_t)size)==NULL) {
27         fprintf(stderr,
28                 "ensure_space: failed to validate %ld bytes at 0x%08lx\n",
29                 size,
30                 (unsigned long)start);
31         exit(1);
32     }
33 }
34
35 #ifdef HOLES
36
37 static os_vm_address_t holes[] = HOLES;
38
39 static void
40 make_holes(void)
41 {
42     int i;
43
44     for (i = 0; i < sizeof(holes)/sizeof(holes[0]); i++) {
45         if (os_validate(holes[i], HOLE_SIZE) == NULL) {
46             fprintf(stderr,
47                     "make_holes: failed to validate %ld bytes at 0x%08X\n",
48                     HOLE_SIZE,
49                     (unsigned long)holes[i]);
50             exit(1);
51         }
52         os_protect(holes[i], HOLE_SIZE, 0);
53     }
54 }
55 #endif
56
57 void
58 validate(void)
59 {
60 #ifdef PRINTNOISE
61         printf("validating memory ...");
62         fflush(stdout);
63 #endif
64
65         ensure_space( (lispobj *)READ_ONLY_SPACE_START, READ_ONLY_SPACE_SIZE);
66         ensure_space( (lispobj *)STATIC_SPACE_START   , STATIC_SPACE_SIZE);
67 #ifdef GENCGC
68         ensure_space( (lispobj *)DYNAMIC_SPACE_START  , DYNAMIC_SPACE_SIZE);
69 #else
70         ensure_space( (lispobj *)DYNAMIC_0_SPACE_START  , DYNAMIC_SPACE_SIZE);
71         ensure_space( (lispobj *)DYNAMIC_1_SPACE_START  , DYNAMIC_SPACE_SIZE);
72 #endif
73         ensure_space( (lispobj *)CONTROL_STACK_START  , CONTROL_STACK_SIZE);
74         ensure_space( (lispobj *)BINDING_STACK_START  , BINDING_STACK_SIZE);
75
76 #ifdef HOLES
77         make_holes();
78 #endif
79
80 #ifdef PRINTNOISE
81         printf(" done.\n");
82 #endif
83 }