inline cell align_page(cell a) { return align(a, getpagesize()); }
-/* segments set up guard pages to check for under/overflow.
-size must be a multiple of the page size */
+bool set_memory_locked(cell base, cell size, bool locked);
+
+// segments set up guard pages to check for under/overflow.
+// size must be a multiple of the page size
struct segment {
cell start;
cell size;
return addr >= start && addr < end;
}
- void set_border_locked(bool locked);
+ void set_border_locked(bool locked) {
+ int pagesize = getpagesize();
+ cell lo = start - pagesize;
+ if (!set_memory_locked(lo, pagesize, locked)) {
+ fatal_error("Cannot (un)protect low guard page", lo);
+ }
+
+ cell hi = end;
+ if (!set_memory_locked(hi, pagesize, locked)) {
+ fatal_error("Cannot (un)protect high guard page", hi);
+ }
+ }
};
}