-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dynamically size sigaltstk in rustc #113528
Dynamically size sigaltstk in rustc #113528
Conversation
(rustbot has picked a reviewer for you, use r? to override) |
This is more-or-less a twin of #113525 but since the code winds up moduled-off from the rest of the world in either case and the two have different contexts, I figured I'd submit it separately. |
9577722
to
1e8d24d
Compare
unsafe { | ||
const ALT_STACK_SIZE: usize = libc::MINSIGSTKSZ + 64 * 1024; | ||
let alt_stack_size: usize = min_sigstack_size() + 64 * 1024; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might seem like 64KiB is greater than the largest number I mentioned, 16KiB.
...but it's up to 16KiB per vector register, and it has way more than one. 🫠
@@ -1469,6 +1470,23 @@ mod signal_handler { | |||
libc::sigaction(libc::SIGSEGV, &sa, std::ptr::null_mut()); | |||
} | |||
} | |||
|
|||
/// Modern kernels on modern hardware can have dynamic signal stack sizes. | |||
#[cfg(any(target_os = "linux", target_os = "android"))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I have spoken to people who run rustc on Android.
#[cfg(any(target_os = "linux", target_os = "android"))] | ||
fn min_sigstack_size() -> usize { | ||
const AT_MINSIGSTKSZ: core::ffi::c_ulong = 51; | ||
let dynamic_sigstksz = unsafe { libc::getauxval(AT_MINSIGSTKSZ) }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doesn't need to block this PR, but does it make sense to upstream AT_MINSIGSTKSZ to the libc crate so we don't need to hardcode it here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you mean would it be good for rust-lang/libc#3125 to be reviewed and accepted? yes, I think so.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
r=me, preferably with the nit
rustc installs a signal stack that assumes that MINSIGSTKSZ is a constant, unchanging value. Newer hardware undermines that assumption greatly, with register files larger than MINSIGSTKZ. Properly handle this so that it is correct on all supported Linux versions with all CPUs.
1e8d24d
to
094cb1a
Compare
@bors r=WaffleLapkin |
…in-rustc-signal-handler, r=WaffleLapkin Dynamically size sigaltstk in rustc rustc installs a signal stack that assumes that MINSIGSTKSZ is a constant, unchanging value. Newer hardware undermines that assumption greatly, with register files larger than glibc's traditional static MINSIGSTKZ. Properly handle this so that it is correct on all supported Linux versions with all CPUs.
…in-rustc-signal-handler, r=WaffleLapkin Dynamically size sigaltstk in rustc rustc installs a signal stack that assumes that MINSIGSTKSZ is a constant, unchanging value. Newer hardware undermines that assumption greatly, with register files larger than glibc's traditional static MINSIGSTKZ. Properly handle this so that it is correct on all supported Linux versions with all CPUs.
…iaskrgr Rollup of 7 pull requests Successful merges: - rust-lang#113386 (style-guide: Expand example of combinable expressions to include arrays) - rust-lang#113523 (Reuse LLVMConstInBoundsGEP2) - rust-lang#113528 (Dynamically size sigaltstk in rustc) - rust-lang#113543 (Remove `rustc_llvm` from llvm-stamp nags) - rust-lang#113548 (Update books) - rust-lang#113551 (bootstrap: Don't print "Skipping" twice) - rust-lang#113556 (Don't use serde-derive in the rls shim) r? `@ghost` `@rustbot` modify labels: rollup
rustc installs a signal stack that assumes that MINSIGSTKSZ is a constant, unchanging value. Newer hardware undermines that assumption greatly, with register files larger than glibc's traditional static MINSIGSTKZ. Properly handle this so that it is correct on all supported Linux versions with all CPUs.