-
Notifications
You must be signed in to change notification settings - Fork 353
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
Setting a thread name on Linux doesn't work with tracked raw pointers #1717
Comments
That wouldn't help... as stated in the README, raw-ptr tracking does not support ptr-int-casts. When The only hack I can imagine here is, under |
# Objective Fixes #1529 Run bevy_ecs in miri ## Solution - Don't set thread names when running in miri rust-lang/miri/issues/1717 - Update `event-listener` to `2.5.2` as previous versions have UB that is detected by miri: [event-listener commit](smol-rs/event-listener@1fa31c5) - Ignore memory leaks when running in miri as they are impossible to track down rust-lang/miri/issues/1481 - Make `table_add_remove_many` test less "many" because miri is really quite slow :) - Make CI run `RUSTFLAGS="-Zrandomize-layout" MIRIFLAGS="-Zmiri-ignore-leaks -Zmiri-tag-raw-pointers -Zmiri-disable-isolation" cargo +nightly miri test -p bevy_ecs`
The above suggestion to transmute instead of casting is no longer an option for hardmode since #2040. But we could still do this: diff --git a/library/std/src/sys/unix/thread.rs b/library/std/src/sys/unix/thread.rs
index bb4e4ee9aa7..88bfbbfe2c3 100644
--- a/library/std/src/sys/unix/thread.rs
+++ b/library/std/src/sys/unix/thread.rs
@@ -116,6 +116,7 @@ pub fn yield_now() {
debug_assert_eq!(ret, 0);
}
+ #[cfg(not(miri))]
#[cfg(any(target_os = "linux", target_os = "android"))]
pub fn set_name(name: &CStr) {
const PR_SET_NAME: libc::c_int = 15;
@@ -126,6 +127,26 @@ pub fn set_name(name: &CStr) {
}
}
+ #[cfg(miri)]
+ #[cfg(any(target_os = "linux", target_os = "android"))]
+ pub fn set_name(name: &CStr) {
+ extern "C" {
+ fn prctl(option: libc::c_int, option: *const i8, ...) -> libc::c_int;
+ }
+ const PR_SET_NAME: libc::c_int = 15;
+ // pthread wrapper only appeared in glibc 2.12, so we use syscall
+ // directly.
+ unsafe {
+ prctl(
+ PR_SET_NAME,
+ name.as_ptr(),
+ ptr::null::<i8>(),
+ ptr::null::<i8>(),
+ ptr::null::<i8>(),
+ );
+ }
+ }
+
#[cfg(any(target_os = "freebsd", target_os = "dragonfly", target_os = "openbsd"))]
pub fn set_name(name: &CStr) {
unsafe { ... or is that too silly? |
If we do |
What would that look like? If we're adding something specially for Miri it doesn't even need an implementation... Right? |
It would look like these functions. But I'm not necessarily a fan of doing that. The easiest solution is to simply do nothing at all on Miri... or to use the approach you suggested even outside Miri, relying on the fact that declaring |
I think we can just delete the cast to an integer type: rust-lang/rust#95626 |
# Objective Fixes bevyengine#1529 Run bevy_ecs in miri ## Solution - Don't set thread names when running in miri rust-lang/miri/issues/1717 - Update `event-listener` to `2.5.2` as previous versions have UB that is detected by miri: [event-listener commit](smol-rs/event-listener@1fa31c5) - Ignore memory leaks when running in miri as they are impossible to track down rust-lang/miri/issues/1481 - Make `table_add_remove_many` test less "many" because miri is really quite slow :) - Make CI run `RUSTFLAGS="-Zrandomize-layout" MIRIFLAGS="-Zmiri-ignore-leaks -Zmiri-tag-raw-pointers -Zmiri-disable-isolation" cargo +nightly miri test -p bevy_ecs`
# Objective rust-lang/miri#1717 has been fixed so we can set thread names in Miri now. ## Solution We set thread names in Miri.
# Objective rust-lang/miri#1717 has been fixed so we can set thread names in Miri now. ## Solution We set thread names in Miri.
# Objective rust-lang/miri#1717 has been fixed so we can set thread names in Miri now. ## Solution We set thread names in Miri.
# Objective rust-lang/miri#1717 has been fixed so we can set thread names in Miri now. ## Solution We set thread names in Miri.
# Objective Fixes bevyengine#1529 Run bevy_ecs in miri ## Solution - Don't set thread names when running in miri rust-lang/miri/issues/1717 - Update `event-listener` to `2.5.2` as previous versions have UB that is detected by miri: [event-listener commit](smol-rs/event-listener@1fa31c5) - Ignore memory leaks when running in miri as they are impossible to track down rust-lang/miri/issues/1481 - Make `table_add_remove_many` test less "many" because miri is really quite slow :) - Make CI run `RUSTFLAGS="-Zrandomize-layout" MIRIFLAGS="-Zmiri-ignore-leaks -Zmiri-tag-raw-pointers -Zmiri-disable-isolation" cargo +nightly miri test -p bevy_ecs`
Spawning a thread with a custom name triggers a stacked borrows violation when
-Zmiri-track-raw-pointers
is enabled. The root cause of the issue is thatprctl
only accepts integers as parameters, so Rust casts the C string pointer to an integer before passing it in but of course this doesn't work with tracked raw pointers.Minimum reproducible example:
Output:
Would it be possible to special-case that function for now?
The text was updated successfully, but these errors were encountered: