Replace %CODE-ENTRY-POINTS with an array, remove %SIMPLE-FUN-NEXT.
[sbcl.git] / src / runtime / validate.c
blob6fa7900028dff12bf31763cea36c1df76bab7207
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"
25 #include "interr.h" /* for declaration of lose */
28 static void
29 ensure_space(lispobj *start, uword_t size)
31 if (os_validate((os_vm_address_t)start,(os_vm_size_t)size)==NULL) {
32 fprintf(stderr,
33 "ensure_space: failed to validate %lu bytes at 0x%08lx\n",
34 size,
35 (uword_t)start);
36 fprintf(stderr,
37 "(hint: Try \"ulimit -a\"; maybe you should increase memory limits.)\n");
38 exit(1);
42 os_vm_address_t undefined_alien_address = 0;
44 static void
45 ensure_undefined_alien(void) {
46 os_vm_address_t start = os_validate(NULL, os_vm_page_size);
47 if (start) {
48 os_protect(start, os_vm_page_size, OS_VM_PROT_NONE);
49 undefined_alien_address = start;
50 } else {
51 lose("could not allocate guard page for undefined alien\n");
55 void
56 allocate_spaces(void)
58 #ifdef PRINTNOISE
59 printf("validating memory ...");
60 fflush(stdout);
61 #endif
63 ensure_space( (lispobj *)READ_ONLY_SPACE_START, READ_ONLY_SPACE_SIZE);
64 ensure_space( (lispobj *)STATIC_SPACE_START , STATIC_SPACE_SIZE);
65 #ifdef IMMOBILE_SPACE_START
66 ensure_space( (lispobj *)IMMOBILE_SPACE_START , IMMOBILE_SPACE_SIZE);
67 #endif
68 #ifdef LISP_FEATURE_GENCGC
69 ensure_space( (lispobj *)DYNAMIC_SPACE_START , dynamic_space_size);
70 #else
71 ensure_space( (lispobj *)DYNAMIC_0_SPACE_START, dynamic_space_size);
72 ensure_space( (lispobj *)DYNAMIC_1_SPACE_START, dynamic_space_size);
73 #endif
75 #ifdef LISP_FEATURE_LINKAGE_TABLE
76 ensure_space( (lispobj *)LINKAGE_TABLE_SPACE_START,
77 LINKAGE_TABLE_SPACE_SIZE);
78 #endif
80 #ifdef LISP_FEATURE_OS_PROVIDES_DLOPEN
81 ensure_undefined_alien();
82 #endif
84 #ifdef PRINTNOISE
85 printf(" done.\n");
86 #endif
89 static inline void
90 protect_page(void *page, int protect_p, os_vm_prot_t flags) {
91 os_protect(page, os_vm_page_size, protect_p ?
92 flags : OS_VM_PROT_ALL);
95 #define DEF_PROTECT_PAGE(name,page_name,flags) \
96 void \
97 protect_##name(int protect_p, struct thread *thread) { \
98 if (!thread) \
99 thread = arch_os_get_current_thread(); \
100 protect_page(page_name(thread), protect_p, flags); \
103 DEF_PROTECT_PAGE(control_stack_hard_guard_page,
104 CONTROL_STACK_HARD_GUARD_PAGE,
105 OS_VM_PROT_NONE)
106 DEF_PROTECT_PAGE(control_stack_guard_page,
107 CONTROL_STACK_GUARD_PAGE,
108 OS_VM_PROT_READ|OS_VM_PROT_EXECUTE)
109 DEF_PROTECT_PAGE(control_stack_return_guard_page,
110 CONTROL_STACK_RETURN_GUARD_PAGE,
111 OS_VM_PROT_READ|OS_VM_PROT_EXECUTE)
113 DEF_PROTECT_PAGE(binding_stack_hard_guard_page,
114 BINDING_STACK_HARD_GUARD_PAGE,
115 OS_VM_PROT_NONE)
116 DEF_PROTECT_PAGE(binding_stack_guard_page,
117 BINDING_STACK_GUARD_PAGE,
118 OS_VM_PROT_NONE)
119 DEF_PROTECT_PAGE(binding_stack_return_guard_page,
120 BINDING_STACK_RETURN_GUARD_PAGE,
121 OS_VM_PROT_NONE)
123 DEF_PROTECT_PAGE(alien_stack_hard_guard_page,
124 ALIEN_STACK_HARD_GUARD_PAGE,
125 OS_VM_PROT_NONE)
126 DEF_PROTECT_PAGE(alien_stack_guard_page,
127 ALIEN_STACK_GUARD_PAGE,
128 OS_VM_PROT_NONE)
129 DEF_PROTECT_PAGE(alien_stack_return_guard_page,
130 ALIEN_STACK_RETURN_GUARD_PAGE,
131 OS_VM_PROT_NONE)