Use os_allocate(), not os_validate(), for "anywhere" allocation
[sbcl.git] / src / runtime / validate.c
blobec02309525ec8afc2fe2cb386691234625decf78
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 %p\n",
34 (long unsigned)size, start);
35 fprintf(stderr,
36 "(hint: Try \"ulimit -a\"; maybe you should increase memory limits.)\n");
37 exit(1);
41 os_vm_address_t undefined_alien_address = 0;
43 static void
44 ensure_undefined_alien(void) {
45 os_vm_address_t start = os_allocate(os_vm_page_size);
46 if (start) {
47 os_protect(start, os_vm_page_size, OS_VM_PROT_NONE);
48 undefined_alien_address = start;
49 } else {
50 lose("could not allocate guard page for undefined alien\n");
54 void
55 allocate_spaces(void)
57 #ifdef PRINTNOISE
58 printf("validating memory ...");
59 fflush(stdout);
60 #endif
62 ensure_space( (lispobj *)READ_ONLY_SPACE_START, READ_ONLY_SPACE_SIZE);
63 ensure_space( (lispobj *)STATIC_SPACE_START , STATIC_SPACE_SIZE);
64 #ifdef IMMOBILE_SPACE_START
65 ensure_space( (lispobj *)IMMOBILE_SPACE_START , IMMOBILE_SPACE_SIZE);
66 #endif
67 #ifdef LISP_FEATURE_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
74 #ifdef LISP_FEATURE_LINKAGE_TABLE
75 ensure_space( (lispobj *)LINKAGE_TABLE_SPACE_START,
76 LINKAGE_TABLE_SPACE_SIZE);
77 #endif
79 #ifdef LISP_FEATURE_OS_PROVIDES_DLOPEN
80 ensure_undefined_alien();
81 #endif
83 #ifdef PRINTNOISE
84 printf(" done.\n");
85 #endif
88 static inline void
89 protect_page(void *page, int protect_p, os_vm_prot_t flags) {
90 os_protect(page, os_vm_page_size, protect_p ?
91 flags : OS_VM_PROT_ALL);
94 #define DEF_PROTECT_PAGE(name,page_name,flags) \
95 void \
96 protect_##name(int protect_p, struct thread *thread) { \
97 if (!thread) \
98 thread = arch_os_get_current_thread(); \
99 protect_page(page_name(thread), protect_p, flags); \
102 DEF_PROTECT_PAGE(control_stack_hard_guard_page,
103 CONTROL_STACK_HARD_GUARD_PAGE,
104 OS_VM_PROT_NONE)
105 DEF_PROTECT_PAGE(control_stack_guard_page,
106 CONTROL_STACK_GUARD_PAGE,
107 OS_VM_PROT_READ|OS_VM_PROT_EXECUTE)
108 DEF_PROTECT_PAGE(control_stack_return_guard_page,
109 CONTROL_STACK_RETURN_GUARD_PAGE,
110 OS_VM_PROT_READ|OS_VM_PROT_EXECUTE)
112 DEF_PROTECT_PAGE(binding_stack_hard_guard_page,
113 BINDING_STACK_HARD_GUARD_PAGE,
114 OS_VM_PROT_NONE)
115 DEF_PROTECT_PAGE(binding_stack_guard_page,
116 BINDING_STACK_GUARD_PAGE,
117 OS_VM_PROT_NONE)
118 DEF_PROTECT_PAGE(binding_stack_return_guard_page,
119 BINDING_STACK_RETURN_GUARD_PAGE,
120 OS_VM_PROT_NONE)
122 DEF_PROTECT_PAGE(alien_stack_hard_guard_page,
123 ALIEN_STACK_HARD_GUARD_PAGE,
124 OS_VM_PROT_NONE)
125 DEF_PROTECT_PAGE(alien_stack_guard_page,
126 ALIEN_STACK_GUARD_PAGE,
127 OS_VM_PROT_NONE)
128 DEF_PROTECT_PAGE(alien_stack_return_guard_page,
129 ALIEN_STACK_RETURN_GUARD_PAGE,
130 OS_VM_PROT_NONE)