-
Notifications
You must be signed in to change notification settings - Fork 13.8k
Used pthread name functions returning result for FreeBSD and DragonFly #132607
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
Used pthread name functions returning result for FreeBSD and DragonFly #132607
Conversation
r? @ibraheemdev rustbot has assigned @ibraheemdev. Use |
Is there any change here except the debug assertion? I'm not sure I see the benefit of this change, will it fail on older versions of FreeBSD/DragonFly? |
While Yes, it will fail on non-maintained versions of FreeBSD/DragonFly, but:
I would unify the code between Linux GNU, DragonFlyBSD and FreeBSD, but there's a small implementation difference. The Linux kernel requires thread names being no longer than 16 bytes including a null terminator. Otherwise, it returns an error. Other platforms just truncate the provided name. rust/library/std/src/sys/pal/unix/thread.rs Lines 137 to 141 in 9200cbc
|
I see, but the only difference between the FreeBSD/DragonFly and OpenBSD/NuttX code is the debug assertion? So the idea here is to assert that the call is valid on FreeBSD and DragonFly? |
Yes, a bit of safety in debug builds instead of having muted errors. |
I'm not sure this is worth it for a debug assertion, but I don't know our policy on support for these platforms. |
@asomers would you be able to review this?
That is just consistent with the other targets, seems reasonable here. |
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.
LGTM, from FreeBSD perspective. pthread_setname_np
supported on FreeBSD releases as old as 13.0 and 12.2.
let name = { | ||
cfg_if::cfg_if! { | ||
if #[cfg(target_os = "linux")] { | ||
const TASK_COMM_LEN: usize = 16; | ||
&truncate_cstr::<{ TASK_COMM_LEN }>(name) | ||
} else { | ||
name.to_bytes() | ||
} | ||
} | ||
}; |
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.
Minor nit to get rid of one level of nesting
let name = { | |
cfg_if::cfg_if! { | |
if #[cfg(target_os = "linux")] { | |
const TASK_COMM_LEN: usize = 16; | |
&truncate_cstr::<{ TASK_COMM_LEN }>(name) | |
} else { | |
name.to_bytes() | |
} | |
} | |
}; | |
cfg_if::cfg_if! { | |
if #[cfg(target_os = "linux")] { | |
const TASK_COMM_LEN: usize = 16; | |
let name = &truncate_cstr::<{ TASK_COMM_LEN }>(name); | |
} else { | |
let name = name.to_bytes(); | |
} | |
} |
Otherwise lgtm, could you please squash?
c0c6b81
to
ce4fd90
Compare
@bors r+ |
Sorry, I just noticed the @bors r- |
Don't remember seeing it there at all. Some other platforms like macOS or Solaris like truncate the length too, so that's why there's |
Oh, that was me that wrote the comment, was thinking it was in source at some point #132607 (comment). A comment would still be good to explain why we treat Optionally for more defensive programming, change the |
Ah, okay, then I will include the comment, but mentioning by name that the other two do not enforce any limits in a separate line. It should be a bit shorter than the defensive option and clear what the other platforms are, kinda a mix of the two options. Is it fine? |
Yeah anything reasonable is fine here - just a hint for anyone reading as to why we truncate the path on Linux but not other platforms. |
@RalfJung, should I also adjust Miri's behavior here or go with a separate PR to |
@bors retry EDIT: was hoping that might reset the status, but nope |
@bors r- |
aebc703
to
84a4d58
Compare
84a4d58
to
8795750
Compare
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.
CI is broken currently but I'll reapprove after that is back to normal.
} else { | ||
// FreeBSD and DragonFly BSD do not enforce length limits. | ||
} |
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.
You can just drop the else block
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 would like to leave it for clarity, I guess. In Miri it's a common thing to explain the behavior, so anyone can come and get why.
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.
Figured this was the reasoning but just wanted to check, fair enough 👍
CI is still closed but @bors r+ |
🌲 The tree is currently closed for pull requests below priority 1000. This pull request will be tested once the tree is reopened. |
pthread_getname_np
andpthread_setname_np
received a wider adoption in past years and was added to:2ef84b7da9a6c3e23b4a135e6e863581f16d46e1
,ab5dc9aceb34419d1c4b6006739e61acee8ee999
.There's not so much advantage except that the result can be checked in debug builds. Ideally it should be unified with Linux' implementation, but it trims the input.