Skip to content

Commit 93325b4

Browse files
semarienagisa
authored andcommitted
allocate stack with MAP_STACK on OpenBSD
use mmap(2) instead of mprotect(2) to pass MAP_STACK
1 parent 772c9aa commit 93325b4

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/lib.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,24 @@ psm_stack_manipulation! {
177177
old_stack_limit: get_stack_limit(),
178178
};
179179
let above_guard_page = new_stack.add(page_size);
180+
#[cfg(not(target_os = "openbsd"))]
180181
let result = libc::mprotect(
181182
above_guard_page,
182183
stack_bytes - page_size,
183184
libc::PROT_READ | libc::PROT_WRITE
184185
);
186+
#[cfg(target_os = "openbsd")]
187+
let result = if libc::mmap(
188+
above_guard_page,
189+
stack_bytes - page_size,
190+
libc::PROT_READ | libc::PROT_WRITE,
191+
libc::MAP_FIXED | libc::MAP_PRIVATE | libc::MAP_ANON | libc::MAP_STACK,
192+
-1,
193+
0) == above_guard_page {
194+
0
195+
} else {
196+
-1
197+
};
185198
if result == -1 {
186199
drop(guard);
187200
panic!("unable to set stack permissions")

0 commit comments

Comments
 (0)