Skip to content

Commit f53e40b

Browse files
committed
[WIP] solaris/illumos support.
1 parent f856ddd commit f53e40b

File tree

6 files changed

+79
-2
lines changed

6 files changed

+79
-2
lines changed

src/shims/unix/foreign_items.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use shims::unix::thread::EvalContextExt as _;
1616
use shims::unix::freebsd::foreign_items as freebsd;
1717
use shims::unix::linux::foreign_items as linux;
1818
use shims::unix::macos::foreign_items as macos;
19+
use shims::unix::solarish::foreign_items as solarish;
1920

2021
fn is_dyn_sym(name: &str, target_os: &str) -> bool {
2122
match name {
@@ -32,6 +33,7 @@ fn is_dyn_sym(name: &str, target_os: &str) -> bool {
3233
"freebsd" => freebsd::is_dyn_sym(name),
3334
"linux" => linux::is_dyn_sym(name),
3435
"macos" => macos::is_dyn_sym(name),
36+
"solaris" | "illumos" => solarish::is_dyn_sym(name),
3537
_ => false,
3638
},
3739
}
@@ -579,7 +581,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
579581
"getentropy" => {
580582
// This function is non-standard but exists with the same signature and behavior on
581583
// Linux, macOS, and FreeBSD.
582-
if !matches!(&*this.tcx.sess.target.os, "linux" | "macos" | "freebsd") {
584+
if !matches!(&*this.tcx.sess.target.os, "linux" | "macos" | "freebsd" | "illumos" | "solaris") {
583585
throw_unsup_format!(
584586
"`getentropy` is not supported on {}",
585587
this.tcx.sess.target.os
@@ -736,6 +738,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
736738
"freebsd" => freebsd::EvalContextExt::emulate_foreign_item_inner(this, link_name, abi, args, dest),
737739
"linux" => linux::EvalContextExt::emulate_foreign_item_inner(this, link_name, abi, args, dest),
738740
"macos" => macos::EvalContextExt::emulate_foreign_item_inner(this, link_name, abi, args, dest),
741+
"solaris" | "illumos" => solarish::EvalContextExt::emulate_foreign_item_inner(this, link_name, abi, args, dest),
739742
_ => Ok(EmulateForeignItemResult::NotSupported),
740743
};
741744
}

src/shims/unix/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ mod thread;
88
mod freebsd;
99
mod linux;
1010
mod macos;
11+
mod solarish;
1112

1213
pub use fs::{DirHandler, FileHandler};
1314

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
use rustc_span::Symbol;
2+
use rustc_target::spec::abi::Abi;
3+
4+
use crate::*;
5+
use shims::foreign_items::EmulateForeignItemResult;
6+
use shims::unix::thread::EvalContextExt as _;
7+
8+
pub fn is_dyn_sym(_name: &str) -> bool {
9+
false
10+
}
11+
12+
impl<'mir, 'tcx: 'mir> EvalContextExt<'mir, 'tcx> for crate::MiriInterpCx<'mir, 'tcx> {}
13+
pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
14+
fn emulate_foreign_item_inner(
15+
&mut self,
16+
link_name: Symbol,
17+
abi: Abi,
18+
args: &[OpTy<'tcx, Provenance>],
19+
dest: &PlaceTy<'tcx, Provenance>,
20+
) -> InterpResult<'tcx, EmulateForeignItemResult> {
21+
let this = self.eval_context_mut();
22+
match link_name.as_str() {
23+
// errno
24+
"__errno" => {
25+
let [] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
26+
let errno_place = this.last_error_place()?;
27+
this.write_scalar(errno_place.to_ref(this).to_scalar(), dest)?;
28+
}
29+
30+
// Threading
31+
"pthread_setname_np" => {
32+
let [thread, name] =
33+
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
34+
// The thread name can have a size up to PTHREAD_MAX_NAMELEN_NP(32)
35+
// https://illumos.org/man/3C/pthread_getname_np
36+
let max_len = 32;
37+
let res = this.pthread_setname_np(
38+
this.read_scalar(thread)?,
39+
this.read_scalar(name)?,
40+
max_len,
41+
)?;
42+
this.write_scalar(res, dest)?;
43+
}
44+
"pthread_getname_np" => {
45+
let [thread, name, len] =
46+
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
47+
let res = this.pthread_getname_np(
48+
this.read_scalar(thread)?,
49+
this.read_scalar(name)?,
50+
this.read_scalar(len)?,
51+
)?;
52+
this.write_scalar(res, dest)?;
53+
}
54+
"getrandom" => {
55+
let [ptr, len, flags] =
56+
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
57+
let ptr = this.read_pointer(ptr)?;
58+
let len = this.read_target_usize(len)?;
59+
let _flags = this.read_scalar(flags)?.to_i32()?;
60+
// GRND_RANDOM, nor GRND_NONBLOCK have any effect on the PRNG.
61+
// https://smartos.org/man/2/getrandom
62+
this.gen_random(ptr, len)?;
63+
this.write_scalar(Scalar::from_target_usize(len, this), dest)?;
64+
}
65+
66+
_ => return Ok(EmulateForeignItemResult::NotSupported),
67+
}
68+
Ok(EmulateForeignItemResult::NeedsJumping)
69+
}
70+
}

src/shims/unix/solarish/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub mod foreign_items;

tests/pass-dep/shims/libc-misc.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ fn test_thread_local_errno() {
157157
use libc::__errno_location;
158158
#[cfg(any(target_os = "macos", target_os = "freebsd"))]
159159
use libc::__error as __errno_location;
160+
#[cfg(any(target_os = "solaris", target_os = "illumos"))]
161+
use libc::__errno as __errno_location;
160162

161163
unsafe {
162164
*__errno_location() = 0xBEEF;

tests/pass-dep/shims/pthread-threadname.rs

Lines changed: 1 addition & 1 deletion
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 = "solaris", target_os = "illumos"))]
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)