Skip to content

Commit e43458c

Browse files
committed
Auto merge of rust-lang#3570 - devnexen:solaris_build_fix, r=RalfJung
Solaris: make pre-main code work Fixes rust-lang/miri#3566
2 parents a418b2d + fb84198 commit e43458c

File tree

5 files changed

+27
-8
lines changed

5 files changed

+27
-8
lines changed

src/tools/miri/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ degree documented below):
227227
- We have unofficial support (not maintained by the Miri team itself) for some further operating systems.
228228
- `freebsd`: **maintainer wanted**. Supports `std::env` and parts of `std::{thread, fs}`, but not `std::sync`.
229229
- `android`: **maintainer wanted**. Support very incomplete, but a basic "hello world" works.
230-
- `illumos`: maintained by @devnexen. Support very incomplete, but a basic "hello world" works.
230+
- `solaris` / `illumos`: maintained by @devnexen. Support very incomplete, but a basic "hello world" works.
231231
- `wasm`: **maintainer wanted**. Support very incomplete, not even standard output works, but an empty `main` function works.
232232
- For targets on other operating systems, Miri might fail before even reaching the `main` function.
233233

src/tools/miri/ci/ci.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,7 @@ case $HOST_TARGET in
146146
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
147147
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
148148
MIRI_TEST_TARGET=x86_64-unknown-illumos run_tests_minimal $VERY_BASIC hello panic/panic concurrency/simple pthread-sync libc-misc libc-random
149-
# TODO fix solaris stack guard
150-
# MIRI_TEST_TARGET=x86_64-pc-solaris run_tests_minimal $VERY_BASIC hello panic/panic pthread-sync
149+
MIRI_TEST_TARGET=x86_64-pc-solaris run_tests_minimal $VERY_BASIC hello panic/panic concurrency/simple pthread-sync libc-misc libc-random
151150
MIRI_TEST_TARGET=aarch64-linux-android run_tests_minimal $VERY_BASIC hello panic/panic
152151
MIRI_TEST_TARGET=wasm32-wasi run_tests_minimal $VERY_BASIC wasm
153152
MIRI_TEST_TARGET=wasm32-unknown-unknown run_tests_minimal $VERY_BASIC wasm

src/tools/miri/src/shims/unix/mem.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,12 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
4242
let map_shared = this.eval_libc_i32("MAP_SHARED");
4343
let map_fixed = this.eval_libc_i32("MAP_FIXED");
4444

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

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use rustc_span::Symbol;
22
use rustc_target::spec::abi::Abi;
33

44
use crate::*;
5-
use shims::EmulateItemResult;
65

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

28+
"stack_getbounds" => {
29+
let [stack] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
30+
let stack = this.deref_pointer_as(stack, this.libc_ty_layout("stack_t"))?;
31+
32+
this.write_int_fields_named(
33+
&[
34+
("ss_sp", this.machine.stack_addr.into()),
35+
("ss_size", this.machine.stack_size.into()),
36+
// field set to 0 means not in an alternate signal stack
37+
// https://docs.oracle.com/cd/E86824_01/html/E54766/stack-getbounds-3c.html
38+
("ss_flags", 0),
39+
],
40+
&stack,
41+
)?;
42+
43+
this.write_null(dest)?;
44+
}
45+
2946
_ => return Ok(EmulateItemResult::NotSupported),
3047
}
3148
Ok(EmulateItemResult::NeedsJumping)

src/tools/miri/tests/pass-dep/shims/libc-misc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ fn test_dlsym() {
136136
assert_eq!(errno, libc::EBADF);
137137
}
138138

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

236236
test_memalign();
237-
#[cfg(not(any(target_os = "macos", target_os = "illumos")))]
237+
#[cfg(not(any(target_os = "macos", target_os = "illumos", target_os = "solaris")))]
238238
test_reallocarray();
239239

240240
#[cfg(target_os = "linux")]

0 commit comments

Comments
 (0)