Skip to content

Commit

Permalink
further illumos/solaris support.
Browse files Browse the repository at this point in the history
fixing part of `miri test alloc/hashmap`.
  • Loading branch information
devnexen committed May 12, 2024
1 parent 55859d4 commit 84d965c
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 3 deletions.
4 changes: 2 additions & 2 deletions ci/ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ case $HOST_TARGET in
BASIC="$VERY_BASIC hello hashmap alloc align" # ensures we have the shims for stdout and basic data structures
TEST_TARGET=x86_64-unknown-freebsd run_tests_minimal $BASIC panic/panic concurrency/simple atomic threadname libc-mem libc-misc libc-random libc-time fs env num_cpus
TEST_TARGET=i686-unknown-freebsd run_tests_minimal $BASIC panic/panic concurrency/simple atomic threadname libc-mem libc-misc libc-random libc-time fs env num_cpus
TEST_TARGET=x86_64-unknown-illumos run_tests_minimal $VERY_BASIC hello panic/panic concurrency/simple pthread-sync libc-mem libc-misc libc-random
TEST_TARGET=x86_64-pc-solaris run_tests_minimal $VERY_BASIC hello panic/panic concurrency/simple pthread-sync libc-mem libc-misc libc-random
TEST_TARGET=x86_64-unknown-illumos run_tests_minimal $VERY_BASIC hello panic/panic concurrency/simple pthread-sync libc-mem libc-misc libc-random alloc hashmap
TEST_TARGET=x86_64-pc-solaris run_tests_minimal $VERY_BASIC hello panic/panic concurrency/simple pthread-sync libc-mem libc-misc libc-random alloc hashmap
TEST_TARGET=aarch64-linux-android run_tests_minimal $VERY_BASIC hello panic/panic
TEST_TARGET=wasm32-wasi run_tests_minimal $VERY_BASIC wasm
TEST_TARGET=wasm32-unknown-unknown run_tests_minimal $VERY_BASIC wasm
Expand Down
4 changes: 4 additions & 0 deletions src/shims/extern_static.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ impl<'mir, 'tcx> MiriMachine<'mir, 'tcx> {
Self::null_ptr_extern_statics(this, &["bsd_signal"])?;
Self::weak_symbol_extern_statics(this, &["signal"])?;
}
"solaris" | "illumos" => {
let environ = this.machine.env_vars.unix().environ();
Self::add_extern_static(this, "environ", environ);
}
"windows" => {
// "_tls_used"
// This is some obscure hack that is part of the Windows TLS story. It's a `u8`.
Expand Down
25 changes: 25 additions & 0 deletions src/shims/unix/solarish/foreign_items.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use rustc_span::Symbol;
use rustc_target::abi::{Align, Size};
use rustc_target::spec::abi::Abi;

use crate::*;
Expand All @@ -18,6 +19,30 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
) -> InterpResult<'tcx, EmulateItemResult> {
let this = self.eval_context_mut();
match link_name.as_str() {
// Allocation
"memalign" => {
let [align, size] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
let align = this.read_target_usize(align)?;
let size = this.read_target_usize(size)?;

// memalign requires the size to be greater than 0, the alignment to be a power of 2
// to be, at least, of word size in which EINVAL is emitted
// and a null pointer is returned.
// https://docs.oracle.com/cd/E88353_01/html/E37843/memalign-3c.html
if !align.is_power_of_two() || align < this.pointer_size().bytes() || size == 0 {
this.set_last_error(this.eval_libc("EINVAL"))?;
this.write_null(dest)?;
} else {
let ptr = this.allocate_ptr(
Size::from_bytes(size),
Align::from_bytes(align).unwrap(),
MiriMemoryKind::C.into(),
)?;
this.write_pointer(ptr, dest)?;
}
}

// Miscellaneous
"___errno" => {
let [] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
Expand Down
7 changes: 6 additions & 1 deletion tests/fail/environ-gets-deallocated.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
//@ignore-target-windows: Windows does not have a global environ list that the program can access directly

#[cfg(any(target_os = "linux", target_os = "freebsd"))]
#[cfg(any(
target_os = "linux",
target_os = "freebsd",
target_os = "solaris",
target_os = "illumos"
))]
fn get_environ() -> *const *const u8 {
extern "C" {
static mut environ: *const *const u8;
Expand Down

0 comments on commit 84d965c

Please sign in to comment.