Skip to content

[compiler-rt] Reland "SetThreadName implementation for Fuchsia" #105179

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

Merged
merged 2 commits into from
Aug 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion compiler-rt/lib/fuzzer/FuzzerUtilFuchsia.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,11 @@ size_t PageSize() {
}

void SetThreadName(std::thread &thread, const std::string &name) {
// TODO ?
if (zx_status_t s = zx_object_set_property(
thread.native_handle(), ZX_PROP_NAME, name.data(), name.size());
s != ZX_OK)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I talked to the kernel folks. The ZX_PROP_NAME doesn't need the string to be a NULL-terminated and it doesn't need to be size capped. The kernel will copy the string, NULL-terminate it and cap the size for you. In this case, you can just do

zx_status_t s = zx_object_set_property(thread.native_handle(), ZX_PROP_NAME, name.data(), name.size())

And remove the local tmp variable to avoid a new string allocation.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah good to know !

Printf("SetThreadName for name %s failed: %s", name.c_str(),
zx_status_get_string(s));
}

} // namespace fuzzer
Expand Down
Loading