Skip to content

Commit

Permalink
Auto merge of rust-lang#3570 - devnexen:solaris_build_fix, r=RalfJung
Browse files Browse the repository at this point in the history
Solaris: make pre-main code work

Fixes rust-lang#3566
  • Loading branch information
bors committed May 5, 2024
2 parents 87a114a + f47926c commit 193aafe
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ degree documented below):
- We have unofficial support (not maintained by the Miri team itself) for some further operating systems.
- `freebsd`: **maintainer wanted**. Supports `std::env` and parts of `std::{thread, fs}`, but not `std::sync`.
- `android`: **maintainer wanted**. Support very incomplete, but a basic "hello world" works.
- `illumos`: maintained by @devnexen. Support very incomplete, but a basic "hello world" works.
- `solaris` / `illumos`: maintained by @devnexen. Support very incomplete, but a basic "hello world" works.
- `wasm`: **maintainer wanted**. Support very incomplete, not even standard output works, but an empty `main` function works.
- For targets on other operating systems, Miri might fail before even reaching the `main` function.

Expand Down
3 changes: 1 addition & 2 deletions ci/ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,7 @@ case $HOST_TARGET in
MIRI_TEST_TARGET=x86_64-unknown-freebsd run_tests_minimal $BASIC panic/panic concurrency/simple atomic threadname libc-misc libc-random libc-time fs env num_cpus
MIRI_TEST_TARGET=i686-unknown-freebsd run_tests_minimal $BASIC panic/panic concurrency/simple atomic threadname libc-misc libc-random libc-time fs env num_cpus
MIRI_TEST_TARGET=x86_64-unknown-illumos run_tests_minimal $VERY_BASIC hello panic/panic concurrency/simple pthread-sync libc-misc libc-random
# TODO fix solaris stack guard
# MIRI_TEST_TARGET=x86_64-pc-solaris run_tests_minimal $VERY_BASIC hello panic/panic pthread-sync
MIRI_TEST_TARGET=x86_64-pc-solaris run_tests_minimal $VERY_BASIC hello panic/panic concurrency/simple pthread-sync libc-misc libc-random
MIRI_TEST_TARGET=aarch64-linux-android run_tests_minimal $VERY_BASIC hello panic/panic
MIRI_TEST_TARGET=wasm32-wasi run_tests_minimal $VERY_BASIC wasm
MIRI_TEST_TARGET=wasm32-unknown-unknown run_tests_minimal $VERY_BASIC wasm
Expand Down
7 changes: 5 additions & 2 deletions src/shims/unix/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,12 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
let map_shared = this.eval_libc_i32("MAP_SHARED");
let map_fixed = this.eval_libc_i32("MAP_FIXED");

// This is a horrible hack, but on MacOS the guard page mechanism uses mmap
// This is a horrible hack, but on MacOS and Solaris the guard page mechanism uses mmap
// in a way we do not support. We just give it the return value it expects.
if this.frame_in_std() && this.tcx.sess.target.os == "macos" && (flags & map_fixed) != 0 {
if this.frame_in_std()
&& matches!(&*this.tcx.sess.target.os, "macos" | "solaris")
&& (flags & map_fixed) != 0
{
return Ok(Scalar::from_maybe_pointer(Pointer::from_addr_invalid(addr), this));
}

Expand Down
19 changes: 18 additions & 1 deletion src/shims/unix/solarish/foreign_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use rustc_span::Symbol;
use rustc_target::spec::abi::Abi;

use crate::*;
use shims::EmulateItemResult;

pub fn is_dyn_sym(_name: &str) -> bool {
false
Expand All @@ -26,6 +25,24 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
this.write_scalar(errno_place.to_ref(this).to_scalar(), dest)?;
}

"stack_getbounds" => {
let [stack] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
let stack = this.deref_pointer_as(stack, this.libc_ty_layout("stack_t"))?;

this.write_int_fields_named(
&[
("ss_sp", this.machine.stack_addr.into()),
("ss_size", this.machine.stack_size.into()),
// field set to 0 means not in an alternate signal stack
// https://docs.oracle.com/cd/E86824_01/html/E54766/stack-getbounds-3c.html
("ss_flags", 0),
],
&stack,
)?;

this.write_null(dest)?;
}

_ => return Ok(EmulateItemResult::NotSupported),
}
Ok(EmulateItemResult::NeedsJumping)
Expand Down
4 changes: 2 additions & 2 deletions tests/pass-dep/shims/libc-misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ fn test_dlsym() {
assert_eq!(errno, libc::EBADF);
}

#[cfg(not(any(target_os = "macos", target_os = "illumos")))]
#[cfg(not(any(target_os = "macos", target_os = "illumos", target_os = "solaris")))]
fn test_reallocarray() {
unsafe {
let mut p = libc::reallocarray(std::ptr::null_mut(), 4096, 2);
Expand Down Expand Up @@ -234,7 +234,7 @@ fn main() {
test_strcpy();

test_memalign();
#[cfg(not(any(target_os = "macos", target_os = "illumos")))]
#[cfg(not(any(target_os = "macos", target_os = "illumos", target_os = "solaris")))]
test_reallocarray();

#[cfg(target_os = "linux")]
Expand Down

0 comments on commit 193aafe

Please sign in to comment.