0.8.14.24: En Garde!
[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         fprintf(stderr,
34                 "(hint: Try \"ulimit -a\"; maybe you should increase memory limits.)\n");
35         exit(1);
36     }
37 }
38
39 void
40 validate(void)
41 {
42 #ifdef PRINTNOISE
43     printf("validating memory ...");
44     fflush(stdout);
45 #endif
46     
47     ensure_space( (lispobj *)READ_ONLY_SPACE_START, READ_ONLY_SPACE_SIZE);
48     ensure_space( (lispobj *)STATIC_SPACE_START   , STATIC_SPACE_SIZE);
49 #ifdef LISP_FEATURE_GENCGC
50     ensure_space( (lispobj *)DYNAMIC_SPACE_START  , DYNAMIC_SPACE_SIZE);
51 #else
52     ensure_space( (lispobj *)DYNAMIC_0_SPACE_START  , DYNAMIC_SPACE_SIZE);
53     ensure_space( (lispobj *)DYNAMIC_1_SPACE_START  , DYNAMIC_SPACE_SIZE);
54 #endif
55
56 #ifdef LISP_FEATURE_LINKAGE_TABLE
57     ensure_space( (lispobj *)LINKAGE_TABLE_SPACE_START, LINKAGE_TABLE_SPACE_SIZE);
58 #endif
59  
60 #ifdef PRINTNOISE
61     printf(" done.\n");
62 #endif
63 }
64
65 void protect_control_stack_guard_page(pid_t t_id, int protect_p) {
66     struct thread *th = find_thread_by_pid(t_id);
67     os_protect(CONTROL_STACK_GUARD_PAGE(th),
68                os_vm_page_size,protect_p ?
69                (OS_VM_PROT_READ|OS_VM_PROT_EXECUTE) : OS_VM_PROT_ALL);
70 }
71
72 void protect_control_stack_return_guard_page(pid_t t_id, int protect_p) {
73     struct thread *th = find_thread_by_pid(t_id);
74     os_protect(CONTROL_STACK_RETURN_GUARD_PAGE(th),
75                os_vm_page_size,protect_p ?
76                (OS_VM_PROT_READ|OS_VM_PROT_EXECUTE) : OS_VM_PROT_ALL);
77 }