about summary refs log tree commit diff
path: root/library/std/src
diff options
context:
space:
mode:
authorJosh Stone <jistone@redhat.com>2022-08-08 13:27:09 -0700
committerJosh Stone <jistone@redhat.com>2022-08-08 13:27:09 -0700
commit013986be1bcfbfd9cedddf22dfd9584ccdb7ee6e (patch)
treeced27d6dd5f49b2816d508c7bea52c468d87cdd4 /library/std/src
parentf03ce30962cf1b2a5158667eabae8bf6e8d1cb03 (diff)
downloadrust-013986be1bcfbfd9cedddf22dfd9584ccdb7ee6e.tar.gz
rust-013986be1bcfbfd9cedddf22dfd9584ccdb7ee6e.zip
linux: Use `pthread_setname_np` instead of `prctl`
This function is available on Linux since glibc 2.12, musl 1.1.16, and
uClibc 1.0.20. The main advantage over `prctl` is that it properly
represents the pointer argument, rather than a multi-purpose `long`,
so we're better representing strict provenance (#95496).
Diffstat (limited to 'library/std/src')
-rw-r--r--library/std/src/sys/unix/thread.rs12
1 files changed, 9 insertions, 3 deletions
diff --git a/library/std/src/sys/unix/thread.rs b/library/std/src/sys/unix/thread.rs
index 36a3fa6023b..7db3065dee0 100644
--- a/library/std/src/sys/unix/thread.rs
+++ b/library/std/src/sys/unix/thread.rs
@@ -116,11 +116,9 @@ impl Thread {
         debug_assert_eq!(ret, 0);
     }
 
-    #[cfg(any(target_os = "linux", target_os = "android"))]
+    #[cfg(target_os = "android")]
     pub fn set_name(name: &CStr) {
         const PR_SET_NAME: libc::c_int = 15;
-        // pthread wrapper only appeared in glibc 2.12, so we use syscall
-        // directly.
         unsafe {
             libc::prctl(
                 PR_SET_NAME,
@@ -132,6 +130,14 @@ impl Thread {
         }
     }
 
+    #[cfg(target_os = "linux")]
+    pub fn set_name(name: &CStr) {
+        unsafe {
+            // Available since glibc 2.12, musl 1.1.16, and uClibc 1.0.20.
+            libc::pthread_setname_np(libc::pthread_self(), name.as_ptr());
+        }
+    }
+
     #[cfg(any(target_os = "freebsd", target_os = "dragonfly", target_os = "openbsd"))]
     pub fn set_name(name: &CStr) {
         unsafe {