Skip to content

Commit

Permalink
Auto merge of #52100 - nielx:fix/rust_driver-stacklimit, r=cramertj
Browse files Browse the repository at this point in the history
Haiku: work around the lack of setrlimit

The default Unix codepath fails, because Haiku does not implement
setrlimit for stack size. Thus we create an additional path.

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.
  • Loading branch information
bors committed Jul 10, 2018
2 parents 5b52591 + 90e32e2 commit 295858e
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/librustc_driver/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit 295858e

Please sign in to comment.