diff options
| author | Yoh Deadfall <yoh.deadfall@hotmail.com> | 2024-10-11 18:31:34 +0300 |
|---|---|---|
| committer | Yoh Deadfall <yoh.deadfall@hotmail.com> | 2024-10-12 21:39:30 +0300 |
| commit | a495a79db95c15071eb787359feaf71424321dd0 (patch) | |
| tree | b95285ff84a32e580aca79662a2a716ebc488eeb | |
| parent | 56c0612003f6a86614fe910e504f81fdb23b0994 (diff) | |
| download | rust-a495a79db95c15071eb787359feaf71424321dd0.tar.gz rust-a495a79db95c15071eb787359feaf71424321dd0.zip | |
Fixed get thread name behavior for FreeBSD
| -rw-r--r-- | src/tools/miri/src/shims/unix/freebsd/foreign_items.rs | 7 | ||||
| -rw-r--r-- | src/tools/miri/tests/pass-dep/libc/pthread-threadname.rs | 11 |
2 files changed, 10 insertions, 8 deletions
diff --git a/src/tools/miri/src/shims/unix/freebsd/foreign_items.rs b/src/tools/miri/src/shims/unix/freebsd/foreign_items.rs index 4789e2ed3bb..5204e57705a 100644 --- a/src/tools/miri/src/shims/unix/freebsd/foreign_items.rs +++ b/src/tools/miri/src/shims/unix/freebsd/foreign_items.rs @@ -34,12 +34,15 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { "pthread_get_name_np" => { let [thread, name, len] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; - // FreeBSD's pthread_get_name_np does not return anything. + // FreeBSD's pthread_get_name_np does not return anything + // and uses strlcpy, which truncates the resulting value, + // but always adds a null terminator (except for zero-sized buffers). + // https://github.com/freebsd/freebsd-src/blob/c2d93a803acef634bd0eede6673aeea59e90c277/lib/libthr/thread/thr_info.c#L119-L144 this.pthread_getname_np( this.read_scalar(thread)?, this.read_scalar(name)?, this.read_scalar(len)?, - false, + /* truncate */ true, )?; } diff --git a/src/tools/miri/tests/pass-dep/libc/pthread-threadname.rs b/src/tools/miri/tests/pass-dep/libc/pthread-threadname.rs index d0cd6e8d385..74b15466202 100644 --- a/src/tools/miri/tests/pass-dep/libc/pthread-threadname.rs +++ b/src/tools/miri/tests/pass-dep/libc/pthread-threadname.rs @@ -79,10 +79,9 @@ fn main() { // if the buffer is shorter than the thread name. #[cfg(any(target_os = "illumos", target_os = "solaris"))] assert_eq!(get_thread_name(&mut buf[..4]), libc::ERANGE); - - // For libc implementation for macOS it's not an error - // for a buffer being too short for the thread name. - #[cfg(target_os = "macos")] + // On macOS and FreeBSD it's not an error for the buffer to be + // too short for the thread name -- they truncate instead. + #[cfg(any(target_os = "freebsd", target_os = "macos"))] { // Ensure that a zero sized buffer returns no error. assert_eq!(get_thread_name(&mut buf[..0]), 0); @@ -123,8 +122,8 @@ fn main() { // Also test directly calling pthread_setname to check its return value. assert_eq!(set_thread_name(&cstr), 0); - // But with a too long name it should fail (except on FreeBSD where the - // function has no return, hence cannot indicate failure). + // But with a too long name it should fail (except on FreeBSD where + // names of arbitrary size seem to be supported). // On macOS, the error code is different. #[cfg(not(any(target_os = "freebsd", target_os = "macos")))] assert_eq!(set_thread_name(&CString::new(long_name).unwrap()), libc::ERANGE); |
