about summary refs log tree commit diff
path: root/library/std/src
diff options
context:
space:
mode:
authorDylan DPC <99973273+Dylan-DPC@users.noreply.github.com>2022-04-07 01:59:22 +0200
committerGitHub <noreply@github.com>2022-04-07 01:59:22 +0200
commit64e7bf9faed35585e8054f968abae792b1b690ce (patch)
tree80a6c8d0bb74fe237e6896442ce41797166090df /library/std/src
parentd2f1a0b88cb540079466692f4251d9dd89c6e3c0 (diff)
parente8a6f53af82b43f79ae36de139cb6867a7bc73ee (diff)
downloadrust-64e7bf9faed35585e8054f968abae792b1b690ce.tar.gz
rust-64e7bf9faed35585e8054f968abae792b1b690ce.zip
Rollup merge of #95626 - saethlin:pass-pointer-to-prctl, r=cuviper
Don't cast thread name to an integer for prctl

`libc::prctl` and the `prctl` definitions in glibc, musl, and the kernel headers are C variadic functions. Therefore, all the arguments (except for the first) are untyped. It is only the Linux man page which says that `prctl` takes 4 `unsigned long` arguments. I have no idea why it says this.

In any case, the upshot is that we don't need to cast the pointer to an integer and confuse Miri.

But in light of this... what are we doing with those three `0`s? We're passing 3 `i32`s to `prctl`, which doesn't fill me with confidence. The man page says `unsigned long` and all the constants in the linux kernel are macros for expressions of the form `1UL << N`. I'm mostly commenting on this because looks a whole lot like some UB that was found in SQLite a few years ago: <https://youtu.be/LbzbHWdLAI0?t=1925> that was related to accidentally passing a 32-bit value from a literal `0` instead of a pointer-sized value. This happens to work on x86 due to the size of pointers and happens to work on x86_64 due to the calling convention. But also, there is no good reason for an implementation to be looking at those arguments. Some other calls to `prctl` require that other arguments be zeroed, but not `PR_SET_NAME`... so why are we even passing them?

I would prefer to end such questions by either passing 3 `libc::c_ulong`, or not passing those at all, but I'm not sure which is better.
Diffstat (limited to 'library/std/src')
-rw-r--r--library/std/src/sys/unix/thread.rs8
1 files changed, 7 insertions, 1 deletions
diff --git a/library/std/src/sys/unix/thread.rs b/library/std/src/sys/unix/thread.rs
index bb4e4ee9aa7..d191e1fe7a6 100644
--- a/library/std/src/sys/unix/thread.rs
+++ b/library/std/src/sys/unix/thread.rs
@@ -122,7 +122,13 @@ impl Thread {
         // pthread wrapper only appeared in glibc 2.12, so we use syscall
         // directly.
         unsafe {
-            libc::prctl(PR_SET_NAME, name.as_ptr() as libc::c_ulong, 0, 0, 0);
+            libc::prctl(
+                PR_SET_NAME,
+                name.as_ptr(),
+                0 as libc::c_ulong,
+                0 as libc::c_ulong,
+                0 as libc::c_ulong,
+            );
         }
     }