Stream: git-wasmtime

Topic: wasmtime / PR #7834 wasmtime-runtime: avoid references to...


view this post on Zulip Wasmtime GitHub notifications bot (Jan 27 2024 at 20:12):

Mrmaxmeier opened PR #7834 from Mrmaxmeier:runtime-signals-avoid-ref-mut-static to bytecodealliance:main:

Hi,
recent nightly versions warn about the use of references to mutable statics in signals.rs:

<details><summary><code>warning: {shared,mutable} reference of mutable static is discouraged</code></summary>

warning: mutable reference of mutable static is discouraged
  --> crates/runtime/src/sys/unix/signals.rs:66:14
   |
66 |     register(&mut PREV_SIGSEGV, libc::SIGSEGV);
   |              ^^^^^^^^^^^^^^^^^ mutable reference of mutable static
   |
   = note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
   = note: reference of mutable static is a hard error from 2024 edition
   = note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior
   = note: `#[warn(static_mut_ref)]` on by default
help: mutable references are dangerous since if there's any other pointer or reference used for that static while the reference lives, that's UB; use `addr_of_mut!` instead to create a raw pointer
   |
66 |     register(addr_of_mut!(PREV_SIGSEGV), libc::SIGSEGV);
   |              ~~~~~~~~~~~~~~~~~~~~~~~~~~

[...]

warning: shared reference of mutable static is discouraged
  --> crates/runtime/src/sys/unix/signals.rs:92:26
   |
92 |         libc::SIGSEGV => &PREV_SIGSEGV,
   |                          ^^^^^^^^^^^^^ shared reference of mutable static
   |
   = note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
   = note: reference of mutable static is a hard error from 2024 edition
   = note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior
help: shared references are dangerous since if there's any kind of mutation of that static while the reference lives, that's UB; use `addr_of!` instead to create a raw pointer
   |
92 |         libc::SIGSEGV => addr_of!(PREV_SIGSEGV),
   |                          ~~~~~~~~~~~~~~~~~~~~~~

[...]

</details>

This PR avoids references to these mutable statics and the safety concerns should now be entirely in the sigaction FFI calls. As far as I can tell, my changes do not affect the semantics of the code. :upside_down_face:

view this post on Zulip Wasmtime GitHub notifications bot (Jan 27 2024 at 20:12):

Mrmaxmeier requested fitzgen for a review on PR #7834.

view this post on Zulip Wasmtime GitHub notifications bot (Jan 27 2024 at 20:12):

Mrmaxmeier requested wasmtime-core-reviewers for a review on PR #7834.

view this post on Zulip Wasmtime GitHub notifications bot (Jan 27 2024 at 20:18):

Mrmaxmeier edited PR #7834:

Hi,
recent nightly versions warn about the use of references to mutable statics in signals.rs:

<details><summary><code>warning: {shared,mutable} reference of mutable static is discouraged</code></summary>

warning: mutable reference of mutable static is discouraged
  --> crates/runtime/src/sys/unix/signals.rs:66:14
   |
66 |     register(&mut PREV_SIGSEGV, libc::SIGSEGV);
   |              ^^^^^^^^^^^^^^^^^ mutable reference of mutable static
   |
   = note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
   = note: reference of mutable static is a hard error from 2024 edition
   = note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior
   = note: `#[warn(static_mut_ref)]` on by default
help: mutable references are dangerous since if there's any other pointer or reference used for that static while the reference lives, that's UB; use `addr_of_mut!` instead to create a raw pointer
   |
66 |     register(addr_of_mut!(PREV_SIGSEGV), libc::SIGSEGV);
   |              ~~~~~~~~~~~~~~~~~~~~~~~~~~

[...]

warning: shared reference of mutable static is discouraged
  --> crates/runtime/src/sys/unix/signals.rs:92:26
   |
92 |         libc::SIGSEGV => &PREV_SIGSEGV,
   |                          ^^^^^^^^^^^^^ shared reference of mutable static
   |
   = note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
   = note: reference of mutable static is a hard error from 2024 edition
   = note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior
help: shared references are dangerous since if there's any kind of mutation of that static while the reference lives, that's UB; use `addr_of!` instead to create a raw pointer
   |
92 |         libc::SIGSEGV => addr_of!(PREV_SIGSEGV),
   |                          ~~~~~~~~~~~~~~~~~~~~~~

[...]

</details>

This PR avoids references to these mutable statics and the safety concerns should now be entirely in the sigaction FFI calls. As far as I can tell my changes do not affect the semantics of the code. :upside_down_face:

view this post on Zulip Wasmtime GitHub notifications bot (Jan 27 2024 at 21:05):

alexcrichton submitted PR review:

Thanks!

view this post on Zulip Wasmtime GitHub notifications bot (Jan 27 2024 at 21:31):

alexcrichton merged PR #7834.


Last updated: Dec 23 2024 at 13:07 UTC