-
Notifications
You must be signed in to change notification settings - Fork 388
Switched FreeBSD to pthread_setname_np #4132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,29 +21,38 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { | |
let this = self.eval_context_mut(); | ||
match link_name.as_str() { | ||
// Threading | ||
"pthread_set_name_np" => { | ||
"pthread_setname_np" => { | ||
let [thread, name] = this.check_shim(abi, Conv::C, link_name, args)?; | ||
let max_len = usize::MAX; // FreeBSD does not seem to have a limit. | ||
// FreeBSD's pthread_set_name_np does not return anything. | ||
this.pthread_setname_np( | ||
let res = match this.pthread_setname_np( | ||
this.read_scalar(thread)?, | ||
this.read_scalar(name)?, | ||
max_len, | ||
/* truncate */ false, | ||
)?; | ||
)? { | ||
ThreadNameResult::Ok => Scalar::from_u32(0), | ||
ThreadNameResult::NameTooLong => unreachable!(), | ||
ThreadNameResult::ThreadNotFound => this.eval_libc("ESRCH"), | ||
}; | ||
this.write_scalar(res, dest)?; | ||
} | ||
"pthread_get_name_np" => { | ||
"pthread_getname_np" => { | ||
let [thread, name, len] = this.check_shim(abi, Conv::C, link_name, args)?; | ||
// FreeBSD's pthread_get_name_np does not return anything | ||
// and uses strlcpy, which truncates the resulting value, | ||
// FreeBSD's pthread_getname_np 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( | ||
let res = match this.pthread_getname_np( | ||
this.read_scalar(thread)?, | ||
this.read_scalar(name)?, | ||
this.read_scalar(len)?, | ||
/* truncate */ true, | ||
)?; | ||
)? { | ||
ThreadNameResult::Ok => Scalar::from_u32(0), | ||
// `NameTooLong` is possible when the buffer is zero sized, | ||
ThreadNameResult::NameTooLong => Scalar::from_u32(0), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we have a test for the zero-sized buffer case? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it was originally done for macOS. Line 130 in the tests. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great, thanks :) |
||
ThreadNameResult::ThreadNotFound => this.eval_libc("ESRCH"), | ||
}; | ||
this.write_scalar(res, dest)?; | ||
} | ||
|
||
// File related shims | ||
|
Uh oh!
There was an error while loading. Please reload this page.