Skip to content

Commit

Permalink
let freebsd truncates itself the id name
Browse files Browse the repository at this point in the history
  • Loading branch information
devnexen committed Oct 27, 2023
1 parent 2117ef5 commit 809057d
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 59 deletions.
118 changes: 65 additions & 53 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions src/shims/unix/freebsd/foreign_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
"pthread_set_name_np" => {
let [thread, name] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
// freebsd silently truncates to MAXCOMLEN (+ 1).
//
// ref. https://github.com/freebsd/freebsd-src/blob/314542de6d0a044640d349d68b2d1a1fe5f427ff/sys/sys/param.h#L127
// ref. https://github.com/freebsd/freebsd-src/blob/314542de6d0a044640d349d68b2d1a1fe5f427ff/lib/libc/sys/thr_set_name.2#L47
let max_len = usize::MAX; //20;
let max_len = usize::MAX;
this.pthread_setname_np(
this.read_scalar(thread)?,
this.read_scalar(name)?,
Expand Down
5 changes: 4 additions & 1 deletion tests/pass-dep/shims/pthreads.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//@ignore-target-windows: No libc on Windows
use std::ffi::{CStr, CString};
use std::ffi::CStr;
#[cfg(not(target_os = "freebsd"))]
use std::ffi::CString;
use std::thread;

fn main() {
Expand Down Expand Up @@ -176,6 +178,7 @@ fn test_named_thread_truncation() {
// 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.
#[cfg(not(target_os = "freebsd"))]
assert_ne!(set_thread_name(&CString::new(long_name).unwrap()), 0);
});
result.unwrap().join().unwrap();
Expand Down

0 comments on commit 809057d

Please sign in to comment.