+
+static inline void
+protect_page(void *page, int protect_p, os_vm_prot_t flags) {
+ os_protect(page, os_vm_page_size, protect_p ?
+ flags : OS_VM_PROT_ALL);
+}
+
+#define DEF_PROTECT_PAGE(name,page_name,flags) \
+ void \
+ protect_##name(int protect_p, struct thread *thread) { \
+ if (!thread) \
+ thread = arch_os_get_current_thread(); \
+ protect_page(page_name(thread), protect_p, flags); \
+ }
+
+DEF_PROTECT_PAGE(control_stack_hard_guard_page,
+ CONTROL_STACK_HARD_GUARD_PAGE,
+ OS_VM_PROT_NONE)
+DEF_PROTECT_PAGE(control_stack_guard_page,
+ CONTROL_STACK_GUARD_PAGE,
+ OS_VM_PROT_READ|OS_VM_PROT_EXECUTE)
+DEF_PROTECT_PAGE(control_stack_return_guard_page,
+ CONTROL_STACK_RETURN_GUARD_PAGE,
+ OS_VM_PROT_READ|OS_VM_PROT_EXECUTE)
+
+DEF_PROTECT_PAGE(binding_stack_hard_guard_page,
+ BINDING_STACK_HARD_GUARD_PAGE,
+ OS_VM_PROT_NONE)
+DEF_PROTECT_PAGE(binding_stack_guard_page,
+ BINDING_STACK_GUARD_PAGE,
+ OS_VM_PROT_NONE)
+DEF_PROTECT_PAGE(binding_stack_return_guard_page,
+ BINDING_STACK_RETURN_GUARD_PAGE,
+ OS_VM_PROT_NONE)
+
+DEF_PROTECT_PAGE(alien_stack_hard_guard_page,
+ ALIEN_STACK_HARD_GUARD_PAGE,
+ OS_VM_PROT_NONE)
+DEF_PROTECT_PAGE(alien_stack_guard_page,
+ ALIEN_STACK_GUARD_PAGE,
+ OS_VM_PROT_NONE)
+DEF_PROTECT_PAGE(alien_stack_return_guard_page,
+ ALIEN_STACK_RETURN_GUARD_PAGE,
+ OS_VM_PROT_NONE)