Haiku: work around the lack of setrlimit

By default, Haiku has the desired 16 MB stack, therefore in general
we do not have to spawn a new thread. The code has been written in
such a way that any changes in Haiku or in Rust will be adapted to.
This commit is contained in:
Niels Sascha Reedijk 2018-07-05 07:12:24 +02:00
parent a8403e1cda
commit 90e32e2ac6

View File

@ -1493,7 +1493,7 @@ pub fn in_rustc_thread<F, R>(f: F) -> Result<R, Box<Any + Send>>
// Temporarily have stack size set to 16MB to deal with nom-using crates failing
const STACK_SIZE: usize = 16 * 1024 * 1024; // 16MB
#[cfg(unix)]
#[cfg(all(unix,not(target_os = "haiku")))]
let spawn_thread = unsafe {
// Fetch the current resource limits
let mut rlim = libc::rlimit {
@ -1525,6 +1525,26 @@ pub fn in_rustc_thread<F, R>(f: F) -> Result<R, Box<Any + Send>>
#[cfg(windows)]
let spawn_thread = false;
#[cfg(target_os = "haiku")]
let spawn_thread = unsafe {
// Haiku does not have setrlimit implemented for the stack size.
// By default it does have the 16 MB stack limit, but we check this in
// case the minimum STACK_SIZE changes or Haiku's defaults change.
let mut rlim = libc::rlimit {
rlim_cur: 0,
rlim_max: 0,
};
if libc::getrlimit(libc::RLIMIT_STACK, &mut rlim) != 0 {
let err = io::Error::last_os_error();
error!("in_rustc_thread: error calling getrlimit: {}", err);
true
} else if rlim.rlim_cur >= STACK_SIZE {
false
} else {
true
}
};
#[cfg(not(any(windows,unix)))]
let spawn_thread = true;