Skip to content

Commit 528adda

Browse files
committed
Auto merge of #3606 - RalfJung:rustup, r=RalfJung
Rustup Pulls in rust-lang/rust#125003 so allocation tests should now work on wasm.
2 parents 35cbdf8 + bd21ce0 commit 528adda

File tree

9 files changed

+88
-36
lines changed

9 files changed

+88
-36
lines changed

Diff for: ci/ci.sh

+4-4
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,12 @@ case $HOST_TARGET in
148148
BASIC="$VERY_BASIC hello hashmap alloc align" # ensures we have the shims for stdout and basic data structures
149149
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
150150
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
151-
TEST_TARGET=x86_64-unknown-illumos run_tests_minimal $BASIC hello panic/panic concurrency/simple pthread-sync libc-mem libc-misc libc-random env
152-
TEST_TARGET=x86_64-pc-solaris run_tests_minimal $BASIC hello panic/panic concurrency/simple pthread-sync libc-mem libc-misc libc-random env
151+
TEST_TARGET=x86_64-unknown-illumos run_tests_minimal $BASIC panic/panic concurrency/simple pthread-sync libc-mem libc-misc libc-random env
152+
TEST_TARGET=x86_64-pc-solaris run_tests_minimal $BASIC panic/panic concurrency/simple pthread-sync libc-mem libc-misc libc-random env
153153
TEST_TARGET=aarch64-linux-android run_tests_minimal $VERY_BASIC hello panic/panic
154-
TEST_TARGET=wasm32-wasi run_tests_minimal $VERY_BASIC wasm
154+
TEST_TARGET=wasm32-wasi run_tests_minimal $VERY_BASIC heap_alloc wasm
155155
TEST_TARGET=wasm32-unknown-unknown run_tests_minimal $VERY_BASIC wasm
156-
TEST_TARGET=thumbv7em-none-eabihf run_tests_minimal no_std
156+
TEST_TARGET=thumbv7em-none-eabihf run_tests_minimal no_std
157157
# Custom target JSON file
158158
TEST_TARGET=tests/avr.json MIRI_NO_STD=1 run_tests_minimal no_std
159159
;;

Diff for: rust-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
b71fa82d786ae1b5866510f1b3a7e5b7e1890e4c
1+
b71e8cbaf2c7cae4d36898fff1d0ba19d9233082

Diff for: src/machine.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,13 @@ use rustc_target::abi::{Align, Size};
3030
use rustc_target::spec::abi::Abi;
3131

3232
use crate::{
33-
concurrency::{data_race, weak_memory},
34-
shims::unix,
33+
concurrency::{
34+
data_race::{self, NaReadType, NaWriteType},
35+
weak_memory,
36+
},
3537
*,
3638
};
3739

38-
use self::concurrency::data_race::NaReadType;
39-
use self::concurrency::data_race::NaWriteType;
40-
4140
/// First real-time signal.
4241
/// `signal(7)` says this must be between 32 and 64 and specifies 34 or 35
4342
/// as typical values.
@@ -464,9 +463,9 @@ pub struct MiriMachine<'mir, 'tcx> {
464463
pub(crate) validate: bool,
465464

466465
/// The table of file descriptors.
467-
pub(crate) fds: unix::FdTable,
466+
pub(crate) fds: shims::FdTable,
468467
/// The table of directory descriptors.
469-
pub(crate) dirs: unix::DirTable,
468+
pub(crate) dirs: shims::DirTable,
470469

471470
/// This machine's monotone clock.
472471
pub(crate) clock: Clock,
@@ -641,7 +640,7 @@ impl<'mir, 'tcx> MiriMachine<'mir, 'tcx> {
641640
tls: TlsData::default(),
642641
isolated_op: config.isolated_op,
643642
validate: config.validate,
644-
fds: unix::FdTable::new(config.mute_stdout_stderr),
643+
fds: shims::FdTable::new(config.mute_stdout_stderr),
645644
dirs: Default::default(),
646645
layouts,
647646
threads: ThreadManager::default(),

Diff for: src/shims/alloc.rs

+26
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,32 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
111111
Ok(ptr.into())
112112
}
113113

114+
fn posix_memalign(
115+
&mut self,
116+
memptr: &OpTy<'tcx, Provenance>,
117+
align: &OpTy<'tcx, Provenance>,
118+
size: &OpTy<'tcx, Provenance>,
119+
) -> InterpResult<'tcx, Scalar<Provenance>> {
120+
let this = self.eval_context_mut();
121+
let memptr = this.deref_pointer(memptr)?;
122+
let align = this.read_target_usize(align)?;
123+
let size = this.read_target_usize(size)?;
124+
125+
// Align must be power of 2, and also at least ptr-sized (POSIX rules).
126+
// But failure to adhere to this is not UB, it's an error condition.
127+
if !align.is_power_of_two() || align < this.pointer_size().bytes() {
128+
Ok(this.eval_libc("EINVAL"))
129+
} else {
130+
let ptr = this.allocate_ptr(
131+
Size::from_bytes(size),
132+
Align::from_bytes(align).unwrap(),
133+
MiriMemoryKind::C.into(),
134+
)?;
135+
this.write_pointer(ptr, &memptr)?;
136+
Ok(Scalar::from_i32(0))
137+
}
138+
}
139+
114140
fn free(&mut self, ptr: Pointer<Option<Provenance>>) -> InterpResult<'tcx> {
115141
let this = self.eval_context_mut();
116142
if !this.ptr_is_null(ptr)? {

Diff for: src/shims/foreign_items.rs

+5
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
108108
let this = self.eval_context_ref();
109109
match this.tcx.sess.target.os.as_ref() {
110110
os if this.target_os_is_unix() => shims::unix::foreign_items::is_dyn_sym(name, os),
111+
"wasi" => shims::wasi::foreign_items::is_dyn_sym(name),
111112
"windows" => shims::windows::foreign_items::is_dyn_sym(name),
112113
_ => false,
113114
}
@@ -947,6 +948,10 @@ trait EvalContextExtPriv<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
947948
shims::unix::foreign_items::EvalContextExt::emulate_foreign_item_inner(
948949
this, link_name, abi, args, dest,
949950
),
951+
"wasi" =>
952+
shims::wasi::foreign_items::EvalContextExt::emulate_foreign_item_inner(
953+
this, link_name, abi, args, dest,
954+
),
950955
"windows" =>
951956
shims::windows::foreign_items::EvalContextExt::emulate_foreign_item_inner(
952957
this, link_name, abi, args, dest,

Diff for: src/shims/mod.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,23 @@
22

33
mod alloc;
44
mod backtrace;
5-
pub mod foreign_items;
65
#[cfg(target_os = "linux")]
7-
pub mod native_lib;
8-
pub mod unix;
9-
pub mod windows;
6+
mod native_lib;
7+
mod unix;
8+
mod wasi;
9+
mod windows;
1010
mod x86;
1111

1212
pub mod env;
1313
pub mod extern_static;
14+
pub mod foreign_items;
1415
pub mod os_str;
1516
pub mod panic;
1617
pub mod time;
1718
pub mod tls;
1819

20+
pub use unix::{DirTable, FdTable};
21+
1922
/// What needs to be done after emulating an item (a shim or an intrinsic) is done.
2023
pub enum EmulateItemResult {
2124
/// The caller is expected to jump to the return block.

Diff for: src/shims/unix/foreign_items.rs

+3-19
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use std::str;
33

44
use rustc_middle::ty::layout::LayoutOf;
55
use rustc_span::Symbol;
6-
use rustc_target::abi::{Align, Size};
76
use rustc_target::spec::abi::Abi;
87

98
use crate::shims::alloc::EvalContextExt as _;
@@ -249,24 +248,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
249248

250249
// Allocation
251250
"posix_memalign" => {
252-
let [ret, align, size] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
253-
let ret = this.deref_pointer(ret)?;
254-
let align = this.read_target_usize(align)?;
255-
let size = this.read_target_usize(size)?;
256-
// Align must be power of 2, and also at least ptr-sized (POSIX rules).
257-
// But failure to adhere to this is not UB, it's an error condition.
258-
if !align.is_power_of_two() || align < this.pointer_size().bytes() {
259-
let einval = this.eval_libc_i32("EINVAL");
260-
this.write_int(einval, dest)?;
261-
} else {
262-
let ptr = this.allocate_ptr(
263-
Size::from_bytes(size),
264-
Align::from_bytes(align).unwrap(),
265-
MiriMemoryKind::C.into(),
266-
)?;
267-
this.write_pointer(ptr, &ret)?;
268-
this.write_null(dest)?;
269-
}
251+
let [memptr, align, size] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
252+
let result = this.posix_memalign(memptr, align, size)?;
253+
this.write_scalar(result, dest)?;
270254
}
271255

272256
"mmap" => {

Diff for: src/shims/wasi/foreign_items.rs

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
use rustc_span::Symbol;
2+
use rustc_target::spec::abi::Abi;
3+
4+
use crate::shims::alloc::EvalContextExt as _;
5+
use crate::*;
6+
7+
pub fn is_dyn_sym(_name: &str) -> bool {
8+
false
9+
}
10+
11+
impl<'mir, 'tcx: 'mir> EvalContextExt<'mir, 'tcx> for crate::MiriInterpCx<'mir, 'tcx> {}
12+
pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
13+
fn emulate_foreign_item_inner(
14+
&mut self,
15+
link_name: Symbol,
16+
abi: Abi,
17+
args: &[OpTy<'tcx, Provenance>],
18+
dest: &MPlaceTy<'tcx, Provenance>,
19+
) -> InterpResult<'tcx, EmulateItemResult> {
20+
let this = self.eval_context_mut();
21+
match link_name.as_str() {
22+
// Allocation
23+
"posix_memalign" => {
24+
let [memptr, align, size] =
25+
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
26+
let result = this.posix_memalign(memptr, align, size)?;
27+
this.write_scalar(result, dest)?;
28+
}
29+
30+
_ => return Ok(EmulateItemResult::NotSupported),
31+
}
32+
Ok(EmulateItemResult::NeedsJumping)
33+
}
34+
}

Diff for: src/shims/wasi/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub mod foreign_items;

0 commit comments

Comments
 (0)