-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Linux: ucontext_t definition is only correct for glibc 2.28 and above #1410
Comments
How is code compiled for glibc < 2.28 ABI compatible with >= 2.28 ? |
Sorry, I must not be understanding your question. I'm on a < 2.28 distro, compiling and running against < 2.28; I currently don't use any >= 2.28 distros. |
Includes some other fixes: - pinned libc crate to 0.2.54 until the resolution of rust-lang/libc#1410 - updated C API types for the removal of tags from trapcodes
If you compile a binary against glibc < 2.28 headers, ucontext_t has a smaller size than if one uses glibc >= 2.28. AFAIK, you can compile against glibc < 2.28 and then use that binary in a system where glibc >= 2.28 is dynamically linked. I was wondering how does this work here? E.g., Maybe there are new different symbols for newer |
Relevant commit: bminor/glibc@25123a1 So apparently that's allowed, see: bminor/glibc@25123a1 glibc checks whether the ucontext_t being used has the new field, and if not, does something else. Older glibc's can, AFAICT, just ignore the field. If you write: let mut ucontext = MaybeUninit::<ucontext_t>::zeroed().into_inner();
getcontext(&mut ucontext); that should work fine, because Layout wise, the new field does not lower the alignment requirements, so that shouldn't be an issue either. |
Do you have a minimal working example showing the issue ? |
(This issue might be related: nix-rust/nix#1092) |
So, this is coming up in a case where a Rust program is writing a Here is a quick and dirty example using a stack-allocated On my system,
|
Gotcha. AFAICT the easiest way to fix this is to revert that change, skipping ucontext in libc-test/build.rs for linux, at least until less users are using glibc < 2.28. |
Per discussion in rust-lang#1410, this is necessary to avoid struct size mismatches between Rust and C on systems with glibc < 2.28.
Closed by #1411. Thanks! |
This commit introduced a shadow stack
__ssp
field to the definition ofucontext_t
: 4497a78However, that field is only present in glibc 2.28 and above, so this struct doesn't work correctly on distros with earlier versions, including Ubuntu 18.04 where I encountered memory corruption after updating from 0.2.47 to 0.2.58.
The text was updated successfully, but these errors were encountered: