Skip to content

Commit

Permalink
treat hermit like wasm32
Browse files Browse the repository at this point in the history
  • Loading branch information
m-mueller678 committed Dec 11, 2024
1 parent cf52a70 commit 9cff7c6
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ psm_stack_manipulation! {
}

impl StackRestoreGuard {
#[cfg(target_arch = "wasm32")]
#[cfg(any(target_arch = "wasm32",target_os = "hermit"))]
unsafe fn new(stack_bytes: usize, _page_size: usize) -> StackRestoreGuard {
let layout = std::alloc::Layout::from_size_align(stack_bytes, 16).unwrap();
let ptr = std::alloc::alloc(layout);
Expand All @@ -152,7 +152,7 @@ psm_stack_manipulation! {
}
}

#[cfg(not(target_arch = "wasm32"))]
#[cfg(not(any(target_arch = "wasm32",target_os = "hermit")))]
unsafe fn new(stack_bytes: usize, page_size: usize) -> StackRestoreGuard {
let new_stack = libc::mmap(
std::ptr::null_mut(),
Expand Down Expand Up @@ -202,14 +202,14 @@ psm_stack_manipulation! {

impl Drop for StackRestoreGuard {
fn drop(&mut self) {
#[cfg(target_arch = "wasm32")]
#[cfg(any(target_arch = "wasm32",target_os = "hermit"))]
unsafe {
std::alloc::dealloc(
self.new_stack as *mut u8,
std::alloc::Layout::from_size_align_unchecked(self.stack_bytes, 16),
);
}
#[cfg(not(target_arch = "wasm32"))]
#[cfg(not(any(target_arch = "wasm32",target_os = "hermit")))]
unsafe {
// FIXME: check the error code and decide what to do with it.
// Perhaps a debug_assertion?
Expand Down Expand Up @@ -258,9 +258,9 @@ psm_stack_manipulation! {

fn page_size() -> usize {
// FIXME: consider caching the page size.
#[cfg(not(target_arch = "wasm32"))]
#[cfg(not(any(target_arch = "wasm32",target_os = "hermit")))]
unsafe { libc::sysconf(libc::_SC_PAGE_SIZE) as usize }
#[cfg(target_arch = "wasm32")]
#[cfg(any(target_arch = "wasm32",target_os = "hermit"))]
{ 65536 }
}
}
Expand Down

0 comments on commit 9cff7c6

Please sign in to comment.