-
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
Use libc::sigaction()
instead of sys::signal()
to prevent a deadlock
#88828
Conversation
r? @dtolnay (rust-highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
a6c525d
to
f1c8acc
Compare
I've tested the fix on Android Emulator x86-64 (Android 10), and on real devices (Android from 6.0.1 to 11). It works!
|
Happy to hear that! And thanks a lot for testing this @d3fl4t3! |
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.
Thanks! This looks good.
The reference automatically coerces to a pointer. Writing an explicit cast here is slightly misleading because that's most commonly used when a pointer needs to be converted from one pointer type to another, e.g. `*const c_void` to `*const sigaction` or vice versa.
7fb9162
to
e3e5ae9
Compare
@bors r+ |
📌 Commit e3e5ae9 has been approved by |
Use `libc::sigaction()` instead of `sys::signal()` to prevent a deadlock Fixes rust-lang#88585. POSIX [specifies](https://man7.org/linux/man-pages/man3/fork.3p.html) that after forking, > to avoid errors, the child process may only execute async-signal-safe operations until such time as one of the exec functions is called. Rust's standard library does not currently adhere to this, as evidenced by rust-lang#88585. The child process calls [`sys::signal()`](https://github.com/rust-lang/rust/blob/7bf0736e130e2203c58654f7353dbf9575e49d5c/library/std/src/sys/unix/android.rs#L76), which on Android calls [`libc::dlsym()`](https://github.com/rust-lang/rust/blob/7bf0736e130e2203c58654f7353dbf9575e49d5c/library/std/src/sys/unix/weak.rs#L101), which is [**not**](https://man7.org/linux/man-pages/man7/signal-safety.7.html) async-signal-safe, and in fact causes a deadlock in the example in rust-lang#88585. I think the easiest solution here would be to just call `libc::sigaction()` instead, which [is](https://man7.org/linux/man-pages/man7/signal-safety.7.html) async-signal-safe, provides the functionality we need, and is apparently available on all Android versions because it is also used e.g. [here](https://github.com/rust-lang/rust/blob/7bf0736e130e2203c58654f7353dbf9575e49d5c/library/std/src/sys/unix/stack_overflow.rs#L112-L114).
@bors r-
|
@bors r+ |
📌 Commit 65ef265 has been approved by |
Use `libc::sigaction()` instead of `sys::signal()` to prevent a deadlock Fixes rust-lang#88585. POSIX [specifies](https://man7.org/linux/man-pages/man3/fork.3p.html) that after forking, > to avoid errors, the child process may only execute async-signal-safe operations until such time as one of the exec functions is called. Rust's standard library does not currently adhere to this, as evidenced by rust-lang#88585. The child process calls [`sys::signal()`](https://github.com/rust-lang/rust/blob/7bf0736e130e2203c58654f7353dbf9575e49d5c/library/std/src/sys/unix/android.rs#L76), which on Android calls [`libc::dlsym()`](https://github.com/rust-lang/rust/blob/7bf0736e130e2203c58654f7353dbf9575e49d5c/library/std/src/sys/unix/weak.rs#L101), which is [**not**](https://man7.org/linux/man-pages/man7/signal-safety.7.html) async-signal-safe, and in fact causes a deadlock in the example in rust-lang#88585. I think the easiest solution here would be to just call `libc::sigaction()` instead, which [is](https://man7.org/linux/man-pages/man7/signal-safety.7.html) async-signal-safe, provides the functionality we need, and is apparently available on all Android versions because it is also used e.g. [here](https://github.com/rust-lang/rust/blob/7bf0736e130e2203c58654f7353dbf9575e49d5c/library/std/src/sys/unix/stack_overflow.rs#L112-L114).
…arth Rollup of 10 pull requests Successful merges: - rust-lang#88706 (Normalize associated type projections when checking return type of main) - rust-lang#88828 (Use `libc::sigaction()` instead of `sys::signal()` to prevent a deadlock) - rust-lang#88871 (Fix suggestion for nested struct patterns) - rust-lang#89317 (Move generic error message to separate branches) - rust-lang#89351 (for signed wrapping remainder, do not compare lhs with MIN) - rust-lang#89442 (Add check for duplicated doc aliases) - rust-lang#89502 (Fix Lower/UpperExp formatting for integers and precision zero) - rust-lang#89523 (Make `proc_macro_derive_resolution_fallback` a future-breakage lint) - rust-lang#89532 (Document behavior of `MaybeLiveLocals` regarding enums and field-senstivity) - rust-lang#89546 (Make an initial guess for metadata size to reduce buffer resizes) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Fixes #88585. POSIX specifies that after forking,
Rust's standard library does not currently adhere to this, as evidenced by #88585. The child process calls
sys::signal()
, which on Android callslibc::dlsym()
, which is not async-signal-safe, and in fact causes a deadlock in the example in #88585.I think the easiest solution here would be to just call
libc::sigaction()
instead, which is async-signal-safe, provides the functionality we need, and is apparently available on all Android versions because it is also used e.g. here.