Skip to content

Commit 295858e

Browse files
committed
Auto merge of #52100 - nielx:fix/rust_driver-stacklimit, r=cramertj
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.
2 parents 5b52591 + 90e32e2 commit 295858e

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/librustc_driver/lib.rs

+21-1
Original file line numberDiff line numberDiff line change
@@ -1493,7 +1493,7 @@ pub fn in_rustc_thread<F, R>(f: F) -> Result<R, Box<Any + Send>>
14931493
// Temporarily have stack size set to 16MB to deal with nom-using crates failing
14941494
const STACK_SIZE: usize = 16 * 1024 * 1024; // 16MB
14951495

1496-
#[cfg(unix)]
1496+
#[cfg(all(unix,not(target_os = "haiku")))]
14971497
let spawn_thread = unsafe {
14981498
// Fetch the current resource limits
14991499
let mut rlim = libc::rlimit {
@@ -1525,6 +1525,26 @@ pub fn in_rustc_thread<F, R>(f: F) -> Result<R, Box<Any + Send>>
15251525
#[cfg(windows)]
15261526
let spawn_thread = false;
15271527

1528+
#[cfg(target_os = "haiku")]
1529+
let spawn_thread = unsafe {
1530+
// Haiku does not have setrlimit implemented for the stack size.
1531+
// By default it does have the 16 MB stack limit, but we check this in
1532+
// case the minimum STACK_SIZE changes or Haiku's defaults change.
1533+
let mut rlim = libc::rlimit {
1534+
rlim_cur: 0,
1535+
rlim_max: 0,
1536+
};
1537+
if libc::getrlimit(libc::RLIMIT_STACK, &mut rlim) != 0 {
1538+
let err = io::Error::last_os_error();
1539+
error!("in_rustc_thread: error calling getrlimit: {}", err);
1540+
true
1541+
} else if rlim.rlim_cur >= STACK_SIZE {
1542+
false
1543+
} else {
1544+
true
1545+
}
1546+
};
1547+
15281548
#[cfg(not(any(windows,unix)))]
15291549
let spawn_thread = true;
15301550

0 commit comments

Comments
 (0)