Skip to content
This repository was archived by the owner on Mar 24, 2022. It is now read-only.

Commit d7c573a

Browse files
committed
[lucet-runtime-internals] use custom stack size on FreeBSD, use cfg-if
On FreeBSD/amd64, SIGSTKSZ == MINSIGSTKSZ(4 * 512) + 32768 == 34816. This is not a multiple of the 4k page size, which is required, so use the custom size. Plus, rewrite the choice using cfg_if, as manual cfgs are getting unwieldy.
1 parent 0f59f76 commit d7c573a

2 files changed

Lines changed: 18 additions & 13 deletions

File tree

lucet-runtime/lucet-runtime-internals/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ anyhow = "1.0"
1717
bitflags = "1.0"
1818
bincode = "1.1.4"
1919
byteorder = "1.3"
20+
cfg-if = "0.1"
2021
lazy_static = "1.4"
2122
libc = "0.2.65"
2223
libloading = "0.5"

lucet-runtime/lucet-runtime-internals/src/alloc/mod.rs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -451,19 +451,23 @@ pub const MINSIGSTKSZ: usize = libc::MINSIGSTKSZ;
451451
///
452452
/// [sigstksz]: https://pubs.opengroup.org/onlinepubs/009695399/basedefs/signal.h.html
453453
pub const DEFAULT_SIGNAL_STACK_SIZE: usize = {
454-
// on Linux, `SIGSTKSZ` is too small for the signal handler when compiled in debug mode
455-
#[cfg(all(debug_assertions, not(target_os = "macos")))]
456-
const SIZE: usize = 12 * 1024;
457-
458-
// on Mac, `SIGSTKSZ` is way larger than we need; it would be nice to combine these debug cases once
459-
// `std::cmp::max` is a const fn
460-
#[cfg(all(debug_assertions, target_os = "macos"))]
461-
const SIZE: usize = libc::SIGSTKSZ;
462-
463-
#[cfg(not(debug_assertions))]
464-
const SIZE: usize = libc::SIGSTKSZ;
465-
466-
SIZE
454+
cfg_if::cfg_if! {
455+
if #[cfg(target_os = "freebsd")] {
456+
// on FreeBSD/amd64, `SIGSTKSZ` is not a multiple of the page size
457+
// (34816 == MINSIGSTKSZ(2048) + 32768)
458+
12 * 1024
459+
} else if #[cfg(target_os = "macos")] {
460+
// on Mac, `SIGSTKSZ` is way larger than we need;
461+
// it would be nice to combine these debug cases once
462+
// `std::cmp::max` is a const fn
463+
libc::SIGSTKSZ
464+
} else if #[cfg(debug_assertions)] {
465+
// on Linux, `SIGSTKSZ` is too small for the signal handler when compiled in debug mode
466+
12 * 1024
467+
} else {
468+
libc::SIGSTKSZ
469+
}
470+
}
467471
};
468472

469473
impl Limits {

0 commit comments

Comments
 (0)