0.8.8.14:
[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 "sbcl.h"
20 #include "runtime.h"
21 #include "os.h"
22 #include "globals.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 void
38 validate(void)
39 {
40 #ifdef PRINTNOISE
41     printf("validating memory ...");
42     fflush(stdout);
43 #endif
44     
45     ensure_space( (lispobj *)READ_ONLY_SPACE_START, READ_ONLY_SPACE_SIZE);
46     ensure_space( (lispobj *)STATIC_SPACE_START   , STATIC_SPACE_SIZE);
47 #ifdef LISP_FEATURE_GENCGC
48     ensure_space( (lispobj *)DYNAMIC_SPACE_START  , DYNAMIC_SPACE_SIZE);
49 #else
50     ensure_space( (lispobj *)DYNAMIC_0_SPACE_START  , DYNAMIC_SPACE_SIZE);
51     ensure_space( (lispobj *)DYNAMIC_1_SPACE_START  , DYNAMIC_SPACE_SIZE);
52 #endif
53
54 #ifdef PRINTNOISE
55     printf(" done.\n");
56 #endif
57 }
58
59 void protect_control_stack_guard_page(pid_t t_id, int protect_p) {
60     struct thread *th = find_thread_by_pid(t_id);
61     os_protect(CONTROL_STACK_GUARD_PAGE(th),
62                os_vm_page_size,protect_p ?
63                (OS_VM_PROT_READ|OS_VM_PROT_EXECUTE) : OS_VM_PROT_ALL);
64 }
65