0.9.6.52:
[sbcl/eslaughter.git] / src / runtime / validate.c
blob11b970f453755107b997815823a50ff51fa25e3c
1 /*
2 * memory validation
3 */
5 /*
6 * This software is part of the SBCL system. See the README file for
7 * more information.
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.
16 #include <stdio.h>
17 #include <stdlib.h>
19 #include "sbcl.h"
20 #include "runtime.h"
21 #include "os.h"
22 #include "globals.h"
23 #include "interr.h"
24 #include "validate.h"
26 static void
27 ensure_space(lispobj *start, unsigned long size)
29 if (os_validate((os_vm_address_t)start,(os_vm_size_t)size)==NULL) {
30 fprintf(stderr,
31 "ensure_space: failed to validate %ld bytes at 0x%08lx\n",
32 size,
33 (unsigned long)start);
34 fprintf(stderr,
35 "(hint: Try \"ulimit -a\"; maybe you should increase memory limits.)\n");
36 exit(1);
40 os_vm_address_t undefined_alien_address = 0;
42 static void
43 ensure_undefined_alien(void) {
44 os_vm_address_t start = os_validate(NULL, os_vm_page_size);
45 if (start) {
46 os_protect(start, os_vm_page_size, OS_VM_PROT_NONE);
47 undefined_alien_address = start;
48 } else {
49 lose("could not allocate guard page for undefined alien");
53 void
54 validate(void)
56 #ifdef PRINTNOISE
57 printf("validating memory ...");
58 fflush(stdout);
59 #endif
61 ensure_space( (lispobj *)READ_ONLY_SPACE_START, READ_ONLY_SPACE_SIZE);
62 ensure_space( (lispobj *)STATIC_SPACE_START , STATIC_SPACE_SIZE);
63 #ifdef LISP_FEATURE_GENCGC
64 ensure_space( (lispobj *)DYNAMIC_SPACE_START , DYNAMIC_SPACE_SIZE);
65 #else
66 ensure_space( (lispobj *)DYNAMIC_0_SPACE_START , DYNAMIC_SPACE_SIZE);
67 ensure_space( (lispobj *)DYNAMIC_1_SPACE_START , DYNAMIC_SPACE_SIZE);
68 #endif
70 #ifdef LISP_FEATURE_LINKAGE_TABLE
71 ensure_space( (lispobj *)LINKAGE_TABLE_SPACE_START, LINKAGE_TABLE_SPACE_SIZE);
72 #endif
74 #ifdef LISP_FEATURE_OS_PROVIDES_DLOPEN
75 ensure_undefined_alien();
76 #endif
78 #ifdef PRINTNOISE
79 printf(" done.\n");
80 #endif
83 void
84 protect_control_stack_guard_page(int protect_p) {
85 struct thread *th = arch_os_get_current_thread();
86 os_protect(CONTROL_STACK_GUARD_PAGE(th),
87 os_vm_page_size,protect_p ?
88 (OS_VM_PROT_READ|OS_VM_PROT_EXECUTE) : OS_VM_PROT_ALL);
91 void
92 protect_control_stack_return_guard_page(int protect_p) {
93 struct thread *th = arch_os_get_current_thread();
94 os_protect(CONTROL_STACK_RETURN_GUARD_PAGE(th),
95 os_vm_page_size,protect_p ?
96 (OS_VM_PROT_READ|OS_VM_PROT_EXECUTE) : OS_VM_PROT_ALL);