Skip to content

Commit

Permalink
Auto merge of #114967 - japaric:ja-gh114966, r=Mark-Simulacrum
Browse files Browse the repository at this point in the history
QNX: pass a truncated thread name to the OS

The maximum length the thread name can have is `_NTO_THREAD_NAME_MAX`

fixes #114966
  • Loading branch information
bors committed Sep 10, 2023
2 parents 030e4d3 + f58b254 commit 9d311f9
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions library/std/src/sys/unix/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ impl Thread {
}

if let Some(f) = pthread_setname_np.get() {
#[cfg(target_os = "nto")]
let name = truncate_cstr::<{ libc::_NTO_THREAD_NAME_MAX as usize }>(name);

let res = unsafe { f(libc::pthread_self(), name.as_ptr()) };
debug_assert_eq!(res, 0);
}
Expand Down Expand Up @@ -290,6 +293,7 @@ impl Drop for Thread {
target_os = "ios",
target_os = "tvos",
target_os = "watchos",
target_os = "nto",
))]
fn truncate_cstr<const MAX_WITH_NUL: usize>(cstr: &CStr) -> [libc::c_char; MAX_WITH_NUL] {
let mut result = [0; MAX_WITH_NUL];
Expand Down

0 comments on commit 9d311f9

Please sign in to comment.