Skip to content

Commit a5b0f72

Browse files
authored
Rollup merge of #100287 - cuviper:no-linux-prctl, r=Mark-Simulacrum
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).
2 parents 1c43cab + 013986b commit a5b0f72

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

library/std/src/sys/unix/thread.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,9 @@ impl Thread {
116116
debug_assert_eq!(ret, 0);
117117
}
118118

119-
#[cfg(any(target_os = "linux", target_os = "android"))]
119+
#[cfg(target_os = "android")]
120120
pub fn set_name(name: &CStr) {
121121
const PR_SET_NAME: libc::c_int = 15;
122-
// pthread wrapper only appeared in glibc 2.12, so we use syscall
123-
// directly.
124122
unsafe {
125123
libc::prctl(
126124
PR_SET_NAME,
@@ -132,6 +130,14 @@ impl Thread {
132130
}
133131
}
134132

133+
#[cfg(target_os = "linux")]
134+
pub fn set_name(name: &CStr) {
135+
unsafe {
136+
// Available since glibc 2.12, musl 1.1.16, and uClibc 1.0.20.
137+
libc::pthread_setname_np(libc::pthread_self(), name.as_ptr());
138+
}
139+
}
140+
135141
#[cfg(any(target_os = "freebsd", target_os = "dragonfly", target_os = "openbsd"))]
136142
pub fn set_name(name: &CStr) {
137143
unsafe {

0 commit comments

Comments
 (0)