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).
This commit is contained in:
Dylan DPC 2022-08-11 22:47:02 +05:30 committed by GitHub
commit a5b0f72e71
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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 {