-
Notifications
You must be signed in to change notification settings - Fork 414
Fixed get/set thread name implementations for macOS and FreeBSD #3957
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
Conversation
|
Thanks!
Given how non-consistent the behavior is, I am not sure it is worth having the ERANGE in the shared code. Let's just return a bool, and every call site handles it in the way they see fit.
|
RalfJung
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you also add a link to some source documenting that a truncated thread name does not lead to an error being returned? That seems like odd behavior...
In my first message you can see that
Therefore, the only possible outcome for |
Mhm, let's keep |
I asked for this to be included in the source, so that it's not lost to history. :)
No, let's not. I think it's nicer to require every caller to handle this explicitly. |
Oh, you can make Miri ICE with this? That's clearly a bug, please file an issue. |
Should it be a ling then to the source? |
|
A link to the source, and a summary of what one sees there.
|
|
@rustbot author |
|
@rustbot review |
|
@rustbot author |
|
@rustbot review |
|
Thanks for gathering all the intel for all the targets. :) I guess we should have been more careful when adding these, the "np" should have been a warning that the behavior is really quite non-portable... @rustbot author |
|
|
||
| // For libc implementation for macOS it's not an error | ||
| // for a buffer being too short for the thread name. | ||
| #[cfg(any(target_os = "freebsd", target_os = "macos"))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basically what I think we should have is a test for #[cfg(not(any(target_os = "freebsd", target_os = "macos")))] where we call get_thread_name(&mut buf[..4]) and assert that we get back ERANGE.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't add a test right now, because I haven't verified other platforms still. So, it would be misleading even if it looks correct according to the current interpreter logic. I also have some questions regarding FreeBSD, because it supports GNU extension method to get and set thread names, but they are not used by std at the moment while being present in libc, and they might have slightly different return codes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, had a quick look at Illumos which should be compatible with Solaris, and there's ERANGE too. Will do a test and write a comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added just for Solaris like OSes because Linux has it's own already.
|
Yes please squash the commits. :) (use |
|
@rustbot author |
ecec7b2 to
00ae882
Compare
Squashed into two logical commits, so there's one for macOS and another for FreeBSD. @rustbot review |
|
Thanks! I have tweaked the test a little to have a more consistent shape. @bors r+ |
|
☀️ Test successful - checks-actions |
So, the story of fixing
pthread_getname_npandpthread_setname_npcontinues, but this time I fixed the macOS implementation.pthread_getname_npThe function never fails except for an invalid thread. Miri never verifies thread identifiers and uses them as indices when accessing a vector of threads. Therefore, the only possible result is
0and a possibly trimmed output.strcpypthread_setname_npWhere
5isPROC_INFO_CALL_SETCONTROL, and2isPROC_INFO_CALL_SETCONTROL. And__proc_infois a syscall handled by the XNU kernel byproc_info_internal:And the actual logic from
proc_setcontrol:Unrelated to the current pull request, but perhaps, there's a very ugly thing in the kernel/libc because the last thing happening in
PROC_SELFSET_THREADNAMEisbsd_setthreadnamewhich sets the name in the user space. But we just saw thatpthread_setname_npsets the name in the user space too. Guess, I need to open a ticket in one of Apple's repositories at least to clarify that :D