about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-07-24 07:40:34 +0000
committerbors <bors@rust-lang.org>2021-07-24 07:40:34 +0000
commit1c66d11a34047be1eb6c50703f8ba6689a15e716 (patch)
tree4003ff69dadc51736c452080fec79f005723d964
parent7d8e7b14a7ccfeca85f7206c0a7e27a3f144ce9e (diff)
parent2ac0b3ed54b3ddfb2f6abfd7f0c1cbd6a924fc1c (diff)
downloadrust-1c66d11a34047be1eb6c50703f8ba6689a15e716.tar.gz
rust-1c66d11a34047be1eb6c50703f8ba6689a15e716.zip
Auto merge of #84589 - In-line:zircon-thread-name, r=JohnTitor
Implement setting thread name for Fuchsia
-rw-r--r--library/std/src/sys/unix/thread.rs34
1 files changed, 30 insertions, 4 deletions
diff --git a/library/std/src/sys/unix/thread.rs b/library/std/src/sys/unix/thread.rs
index 879d7160524..1488bf94841 100644
--- a/library/std/src/sys/unix/thread.rs
+++ b/library/std/src/sys/unix/thread.rs
@@ -16,6 +16,23 @@ pub const DEFAULT_MIN_STACK_SIZE: usize = 1024 * 1024;
 #[cfg(target_os = "vxworks")]
 pub const DEFAULT_MIN_STACK_SIZE: usize = 256 * 1024;
 
+#[cfg(target_os = "fuchsia")]
+mod zircon {
+    type zx_handle_t = u32;
+    type zx_status_t = i32;
+    pub const ZX_PROP_NAME: u32 = 3;
+
+    extern "C" {
+        pub fn zx_object_set_property(
+            handle: zx_handle_t,
+            property: u32,
+            value: *const libc::c_void,
+            value_size: libc::size_t,
+        ) -> zx_status_t;
+        pub fn zx_thread_self() -> zx_handle_t;
+    }
+}
+
 pub struct Thread {
     id: libc::pthread_t,
 }
@@ -134,6 +151,19 @@ impl Thread {
         }
     }
 
+    #[cfg(target_os = "fuchsia")]
+    pub fn set_name(name: &CStr) {
+        use self::zircon::*;
+        unsafe {
+            zx_object_set_property(
+                zx_thread_self(),
+                ZX_PROP_NAME,
+                name.as_ptr() as *const libc::c_void,
+                name.to_bytes().len(),
+            );
+        }
+    }
+
     #[cfg(any(
         target_env = "newlib",
         target_os = "haiku",
@@ -145,10 +175,6 @@ impl Thread {
     pub fn set_name(_name: &CStr) {
         // Newlib, Haiku, Emscripten, and VxWorks have no way to set a thread name.
     }
-    #[cfg(target_os = "fuchsia")]
-    pub fn set_name(_name: &CStr) {
-        // FIXME: determine whether Fuchsia has a way to set a thread name.
-    }
 
     pub fn sleep(dur: Duration) {
         let mut secs = dur.as_secs();