Skip to content

Commit 008f6b3

Browse files
committed
Auto merge of #3626 - devnexen:pthread_name_illumos, r=oli-obk
solaris add support for threadname. from std::unix::thread::set_name, pthread_setname_np is a weak symbol (not always had been available). Other than that, similar to linux only having twice of its buffer limit.
2 parents 7fc41d1 + 7f5e0aa commit 008f6b3

File tree

4 files changed

+34
-5
lines changed

4 files changed

+34
-5
lines changed

src/tools/miri/ci/ci.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ case $HOST_TARGET in
148148
UNIX="panic/panic panic/unwind concurrency/simple atomic libc-mem libc-misc libc-random env num_cpus" # the things that are very similar across all Unixes, and hence easily supported there
149149
TEST_TARGET=x86_64-unknown-freebsd run_tests_minimal $BASIC $UNIX threadname libc-time fs
150150
TEST_TARGET=i686-unknown-freebsd run_tests_minimal $BASIC $UNIX threadname libc-time fs
151-
TEST_TARGET=x86_64-unknown-illumos run_tests_minimal $BASIC $UNIX pthread-sync libc-time
152-
TEST_TARGET=x86_64-pc-solaris run_tests_minimal $BASIC $UNIX pthread-sync libc-time
151+
TEST_TARGET=x86_64-unknown-illumos run_tests_minimal $BASIC $UNIX threadname pthread-sync libc-time
152+
TEST_TARGET=x86_64-pc-solaris run_tests_minimal $BASIC $UNIX threadname pthread-sync libc-time
153153
TEST_TARGET=aarch64-linux-android run_tests_minimal $BASIC $UNIX
154154
TEST_TARGET=wasm32-wasip2 run_tests_minimal empty_main wasm heap_alloc libc-mem
155155
TEST_TARGET=wasm32-unknown-unknown run_tests_minimal empty_main wasm

src/tools/miri/src/shims/extern_static.rs

+3
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ impl<'mir, 'tcx> MiriMachine<'mir, 'tcx> {
8282
let val = ImmTy::from_int(0, this.machine.layouts.u8);
8383
Self::alloc_extern_static(this, "_tls_used", val)?;
8484
}
85+
"illumos" | "solaris" => {
86+
Self::weak_symbol_extern_statics(this, &["pthread_setname_np"])?;
87+
}
8588
_ => {} // No "extern statics" supported on this target
8689
}
8790
Ok(())

src/tools/miri/src/shims/unix/solarish/foreign_items.rs

+28-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
use rustc_span::Symbol;
22
use rustc_target::spec::abi::Abi;
33

4+
use crate::shims::unix::*;
45
use crate::*;
56

6-
pub fn is_dyn_sym(_name: &str) -> bool {
7-
false
7+
pub fn is_dyn_sym(name: &str) -> bool {
8+
matches!(name, "pthread_setname_np")
89
}
910

1011
impl<'mir, 'tcx: 'mir> EvalContextExt<'mir, 'tcx> for crate::MiriInterpCx<'mir, 'tcx> {}
@@ -18,6 +19,31 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
1819
) -> InterpResult<'tcx, EmulateItemResult> {
1920
let this = self.eval_context_mut();
2021
match link_name.as_str() {
22+
// Threading
23+
"pthread_setname_np" => {
24+
let [thread, name] =
25+
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
26+
// THREAD_NAME_MAX allows a thread name of 31+1 length
27+
// https://github.com/illumos/illumos-gate/blob/7671517e13b8123748eda4ef1ee165c6d9dba7fe/usr/src/uts/common/sys/thread.h#L613
28+
let max_len = 32;
29+
let res = this.pthread_setname_np(
30+
this.read_scalar(thread)?,
31+
this.read_scalar(name)?,
32+
max_len,
33+
)?;
34+
this.write_scalar(res, dest)?;
35+
}
36+
"pthread_getname_np" => {
37+
let [thread, name, len] =
38+
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
39+
let res = this.pthread_getname_np(
40+
this.read_scalar(thread)?,
41+
this.read_scalar(name)?,
42+
this.read_scalar(len)?,
43+
)?;
44+
this.write_scalar(res, dest)?;
45+
}
46+
2147
// Miscellaneous
2248
"___errno" => {
2349
let [] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;

src/tools/miri/tests/pass-dep/libc/pthread-threadname.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ fn main() {
1010
.collect::<String>();
1111

1212
fn set_thread_name(name: &CStr) -> i32 {
13-
#[cfg(target_os = "linux")]
13+
#[cfg(any(target_os = "linux", target_os = "illumos", target_os = "solaris"))]
1414
return unsafe { libc::pthread_setname_np(libc::pthread_self(), name.as_ptr().cast()) };
1515
#[cfg(target_os = "freebsd")]
1616
unsafe {

0 commit comments

Comments
 (0)