Skip to content

Commit c7debbd

Browse files
committed
various small nits
- share implementation with miri_starting_unwind - make test use a custom unwinding class - extend comments - use NeedsUnwind more consistently
1 parent 7d74ebe commit c7debbd

26 files changed

+72
-69
lines changed

ci/ci.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ case $HOST_TARGET in
145145
TEST_TARGET=s390x-unknown-linux-gnu run_tests # big-endian architecture of choice
146146
# Partially supported targets (tier 2)
147147
BASIC="empty_main integer vec string btreemap hello hashmap heap_alloc align" # ensures we have the basics: stdout/stderr, system allocator, randomness (for HashMap initialization)
148-
UNIX="panic/panic concurrency/simple atomic libc-mem libc-misc libc-random env num_cpus" # the things that are very similar across all Unixes, and hence easily supported there
148+
UNIX="panic/panic panic/unwind concurrency/simple atomic libc-mem libc-misc libc-random env num_cpus" # the things that are very similar across all Unixes, and hence easily supported there
149149
TEST_TARGET=x86_64-unknown-freebsd run_tests_minimal $BASIC $UNIX threadname libc-time fs
150150
TEST_TARGET=i686-unknown-freebsd run_tests_minimal $BASIC $UNIX threadname libc-time fs
151151
TEST_TARGET=x86_64-unknown-illumos run_tests_minimal $BASIC $UNIX pthread-sync

src/intrinsics/atomic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
116116

117117
_ => return Ok(EmulateItemResult::NotSupported),
118118
}
119-
Ok(EmulateItemResult::NeedsJumping)
119+
Ok(EmulateItemResult::NeedsReturn)
120120
}
121121
}
122122

src/intrinsics/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
6262
args: instance.args,
6363
}))
6464
}
65-
EmulateItemResult::NeedsJumping => {
65+
EmulateItemResult::NeedsReturn => {
6666
trace!("{:?}", this.dump_place(&dest.clone().into()));
6767
this.return_to_block(ret)?;
6868
Ok(None)
@@ -446,6 +446,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
446446
_ => return Ok(EmulateItemResult::NotSupported),
447447
}
448448

449-
Ok(EmulateItemResult::NeedsJumping)
449+
Ok(EmulateItemResult::NeedsReturn)
450450
}
451451
}

src/intrinsics/simd.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
746746

747747
_ => return Ok(EmulateItemResult::NotSupported),
748748
}
749-
Ok(EmulateItemResult::NeedsJumping)
749+
Ok(EmulateItemResult::NeedsReturn)
750750
}
751751

752752
fn fminmax_op(

src/shims/alloc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
8787
}
8888
AllocatorKind::Default => {
8989
default(this)?;
90-
Ok(EmulateItemResult::NeedsJumping)
90+
Ok(EmulateItemResult::NeedsReturn)
9191
}
9292
}
9393
}

src/shims/foreign_items.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
8282
}
8383

8484
// The rest either implements the logic, or falls back to `lookup_exported_symbol`.
85-
match this.emulate_foreign_item_inner(link_name, abi, args, dest, unwind)? {
86-
EmulateItemResult::NeedsJumping => {
85+
match this.emulate_foreign_item_inner(link_name, abi, args, dest)? {
86+
EmulateItemResult::NeedsReturn => {
8787
trace!("{:?}", this.dump_place(&dest.clone().into()));
8888
this.return_to_block(ret)?;
8989
}
@@ -210,7 +210,6 @@ trait EvalContextExtPriv<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
210210
abi: Abi,
211211
args: &[OpTy<'tcx, Provenance>],
212212
dest: &MPlaceTy<'tcx, Provenance>,
213-
unwind: mir::UnwindAction,
214213
) -> InterpResult<'tcx, EmulateItemResult> {
215214
let this = self.eval_context_mut();
216215

@@ -222,7 +221,7 @@ trait EvalContextExtPriv<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
222221
// by the specified `.so` file; we should continue and check if it corresponds to
223222
// a provided shim.
224223
if this.call_native_fn(link_name, dest, args)? {
225-
return Ok(EmulateItemResult::NeedsJumping);
224+
return Ok(EmulateItemResult::NeedsReturn);
226225
}
227226
}
228227

@@ -267,9 +266,9 @@ trait EvalContextExtPriv<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
267266
match link_name.as_str() {
268267
// Miri-specific extern functions
269268
"miri_start_unwind" => {
270-
// `check_shim` happens inside `handle_miri_start_unwind`.
271-
this.handle_miri_start_unwind(abi, link_name, args, unwind)?;
272-
return Ok(EmulateItemResult::AlreadyJumped);
269+
let [payload] = this.check_shim(abi, Abi::Rust, link_name, args)?;
270+
this.handle_miri_start_unwind(payload)?;
271+
return Ok(EmulateItemResult::NeedsUnwind);
273272
}
274273
"miri_run_provenance_gc" => {
275274
let [] = this.check_shim(abi, Abi::Rust, link_name, args)?;
@@ -484,7 +483,7 @@ trait EvalContextExtPriv<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
484483
"__rust_alloc" => return this.emulate_allocator(default),
485484
"miri_alloc" => {
486485
default(this)?;
487-
return Ok(EmulateItemResult::NeedsJumping);
486+
return Ok(EmulateItemResult::NeedsReturn);
488487
}
489488
_ => unreachable!(),
490489
}
@@ -544,7 +543,7 @@ trait EvalContextExtPriv<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
544543
}
545544
"miri_dealloc" => {
546545
default(this)?;
547-
return Ok(EmulateItemResult::NeedsJumping);
546+
return Ok(EmulateItemResult::NeedsReturn);
548547
}
549548
_ => unreachable!(),
550549
}
@@ -965,6 +964,6 @@ trait EvalContextExtPriv<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
965964
};
966965
// We only fall through to here if we did *not* hit the `_` arm above,
967966
// i.e., if we actually emulated the function with one of the shims.
968-
Ok(EmulateItemResult::NeedsJumping)
967+
Ok(EmulateItemResult::NeedsReturn)
969968
}
970969
}

src/shims/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ pub use unix::{DirTable, FdTable};
2222
/// What needs to be done after emulating an item (a shim or an intrinsic) is done.
2323
pub enum EmulateItemResult {
2424
/// The caller is expected to jump to the return block.
25-
NeedsJumping,
25+
NeedsReturn,
2626
/// The caller is expected to jump to the unwind block.
2727
NeedsUnwind,
28-
/// Jumping has already been taken care of.
28+
/// Jumping to the next block has already been taken care of.
2929
AlreadyJumped,
3030
/// The item is not supported.
3131
NotSupported,

src/shims/panic.rs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
1414
use rustc_ast::Mutability;
1515
use rustc_middle::{mir, ty};
16-
use rustc_span::Symbol;
1716
use rustc_target::spec::abi::Abi;
1817
use rustc_target::spec::PanicStrategy;
1918

@@ -46,25 +45,15 @@ impl<'mir, 'tcx: 'mir> EvalContextExt<'mir, 'tcx> for crate::MiriInterpCx<'mir,
4645
pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
4746
/// Handles the special `miri_start_unwind` intrinsic, which is called
4847
/// by libpanic_unwind to delegate the actual unwinding process to Miri.
49-
fn handle_miri_start_unwind(
50-
&mut self,
51-
abi: Abi,
52-
link_name: Symbol,
53-
args: &[OpTy<'tcx, Provenance>],
54-
unwind: mir::UnwindAction,
55-
) -> InterpResult<'tcx> {
48+
fn handle_miri_start_unwind(&mut self, payload: &OpTy<'tcx, Provenance>) -> InterpResult<'tcx> {
5649
let this = self.eval_context_mut();
5750

5851
trace!("miri_start_unwind: {:?}", this.frame().instance);
5952

60-
// Get the raw pointer stored in arg[0] (the panic payload).
61-
let [payload] = this.check_shim(abi, Abi::Rust, link_name, args)?;
6253
let payload = this.read_scalar(payload)?;
6354
let thread = this.active_thread_mut();
6455
thread.panic_payloads.push(payload);
6556

66-
// Jump to the unwind block to begin unwinding.
67-
this.unwind_to_block(unwind)?;
6857
Ok(())
6958
}
7059

src/shims/unix/android/foreign_items.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
2727

2828
_ => return Ok(EmulateItemResult::NotSupported),
2929
}
30-
Ok(EmulateItemResult::NeedsJumping)
30+
Ok(EmulateItemResult::NeedsReturn)
3131
}
3232
}

src/shims/unix/foreign_items.rs

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -640,14 +640,28 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
640640
this.write_scalar(Scalar::from_target_usize(len, this), dest)?;
641641
}
642642
"_Unwind_RaiseException" => {
643-
trace!("_Unwind_RaiseException: {:?}", this.frame().instance);
644-
645-
// Get the raw pointer stored in arg[0] (the panic payload).
643+
// This is not formally part of POSIX, but it is very wide-spread on POSIX systems.
644+
// It was originally specified as part of the Itanium C++ ABI:
645+
// https://itanium-cxx-abi.github.io/cxx-abi/abi-eh.html#base-throw.
646+
// On Linux it is
647+
// documented as part of the LSB:
648+
// https://refspecs.linuxfoundation.org/LSB_5.0.0/LSB-Core-generic/LSB-Core-generic/baselib--unwind-raiseexception.html
649+
// Basically every other UNIX uses the exact same api though. Arm also references
650+
// back to the Itanium C++ ABI for the definition of `_Unwind_RaiseException` for
651+
// arm64:
652+
// https://github.com/ARM-software/abi-aa/blob/main/cppabi64/cppabi64.rst#toc-entry-35
653+
// For arm32 they did something custom, but similar enough that the same
654+
// `_Unwind_RaiseException` impl in miri should work:
655+
// https://github.com/ARM-software/abi-aa/blob/main/ehabi32/ehabi32.rst
656+
if !matches!(&*this.tcx.sess.target.os, "linux" | "freebsd" | "illumos" | "solaris" | "android" | "macos") {
657+
throw_unsup_format!(
658+
"`_Unwind_RaiseException` is not supported on {}",
659+
this.tcx.sess.target.os
660+
);
661+
}
662+
// This function looks and behaves excatly like miri_start_unwind.
646663
let [payload] = this.check_shim(abi, Abi::C { unwind: true }, link_name, args)?;
647-
let payload = this.read_scalar(payload)?;
648-
let thread = this.active_thread_mut();
649-
thread.panic_payloads.push(payload);
650-
664+
this.handle_miri_start_unwind(payload)?;
651665
return Ok(EmulateItemResult::NeedsUnwind);
652666
}
653667

@@ -771,6 +785,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
771785
}
772786
};
773787

774-
Ok(EmulateItemResult::NeedsJumping)
788+
Ok(EmulateItemResult::NeedsReturn)
775789
}
776790
}

src/shims/unix/freebsd/foreign_items.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
8686

8787
_ => return Ok(EmulateItemResult::NotSupported),
8888
}
89-
Ok(EmulateItemResult::NeedsJumping)
89+
Ok(EmulateItemResult::NeedsReturn)
9090
}
9191
}

src/shims/unix/linux/foreign_items.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
203203
_ => return Ok(EmulateItemResult::NotSupported),
204204
};
205205

206-
Ok(EmulateItemResult::NeedsJumping)
206+
Ok(EmulateItemResult::NeedsReturn)
207207
}
208208
}

src/shims/unix/macos/foreign_items.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
177177
_ => return Ok(EmulateItemResult::NotSupported),
178178
};
179179

180-
Ok(EmulateItemResult::NeedsJumping)
180+
Ok(EmulateItemResult::NeedsReturn)
181181
}
182182
}

src/shims/unix/solarish/foreign_items.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
4545

4646
_ => return Ok(EmulateItemResult::NotSupported),
4747
}
48-
Ok(EmulateItemResult::NeedsJumping)
48+
Ok(EmulateItemResult::NeedsReturn)
4949
}
5050
}

src/shims/wasi/foreign_items.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
3535

3636
_ => return Ok(EmulateItemResult::NotSupported),
3737
}
38-
Ok(EmulateItemResult::NeedsJumping)
38+
Ok(EmulateItemResult::NeedsReturn)
3939
}
4040
}

src/shims/windows/foreign_items.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
762762
_ => return Ok(EmulateItemResult::NotSupported),
763763
}
764764

765-
Ok(EmulateItemResult::NeedsJumping)
765+
Ok(EmulateItemResult::NeedsReturn)
766766
}
767767
}

src/shims/x86/aesni.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ pub(super) trait EvalContextExt<'mir, 'tcx: 'mir>:
127127
// with an external crate.
128128
_ => return Ok(EmulateItemResult::NotSupported),
129129
}
130-
Ok(EmulateItemResult::NeedsJumping)
130+
Ok(EmulateItemResult::NeedsReturn)
131131
}
132132
}
133133

src/shims/x86/avx.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,6 @@ pub(super) trait EvalContextExt<'mir, 'tcx: 'mir>:
344344
}
345345
_ => return Ok(EmulateItemResult::NotSupported),
346346
}
347-
Ok(EmulateItemResult::NeedsJumping)
347+
Ok(EmulateItemResult::NeedsReturn)
348348
}
349349
}

src/shims/x86/avx2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,6 @@ pub(super) trait EvalContextExt<'mir, 'tcx: 'mir>:
440440
}
441441
_ => return Ok(EmulateItemResult::NotSupported),
442442
}
443-
Ok(EmulateItemResult::NeedsJumping)
443+
Ok(EmulateItemResult::NeedsReturn)
444444
}
445445
}

src/shims/x86/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ pub(super) trait EvalContextExt<'mir, 'tcx: 'mir>:
144144

145145
_ => return Ok(EmulateItemResult::NotSupported),
146146
}
147-
Ok(EmulateItemResult::NeedsJumping)
147+
Ok(EmulateItemResult::NeedsReturn)
148148
}
149149
}
150150

src/shims/x86/sse.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,6 @@ pub(super) trait EvalContextExt<'mir, 'tcx: 'mir>:
212212
}
213213
_ => return Ok(EmulateItemResult::NotSupported),
214214
}
215-
Ok(EmulateItemResult::NeedsJumping)
215+
Ok(EmulateItemResult::NeedsReturn)
216216
}
217217
}

src/shims/x86/sse2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,6 @@ pub(super) trait EvalContextExt<'mir, 'tcx: 'mir>:
388388
}
389389
_ => return Ok(EmulateItemResult::NotSupported),
390390
}
391-
Ok(EmulateItemResult::NeedsJumping)
391+
Ok(EmulateItemResult::NeedsReturn)
392392
}
393393
}

src/shims/x86/sse3.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,6 @@ pub(super) trait EvalContextExt<'mir, 'tcx: 'mir>:
5151
}
5252
_ => return Ok(EmulateItemResult::NotSupported),
5353
}
54-
Ok(EmulateItemResult::NeedsJumping)
54+
Ok(EmulateItemResult::NeedsReturn)
5555
}
5656
}

src/shims/x86/sse41.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,6 @@ pub(super) trait EvalContextExt<'mir, 'tcx: 'mir>:
176176
}
177177
_ => return Ok(EmulateItemResult::NotSupported),
178178
}
179-
Ok(EmulateItemResult::NeedsJumping)
179+
Ok(EmulateItemResult::NeedsReturn)
180180
}
181181
}

src/shims/x86/ssse3.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,6 @@ pub(super) trait EvalContextExt<'mir, 'tcx: 'mir>:
137137
}
138138
_ => return Ok(EmulateItemResult::NotSupported),
139139
}
140-
Ok(EmulateItemResult::NeedsJumping)
140+
Ok(EmulateItemResult::NeedsReturn)
141141
}
142142
}

0 commit comments

Comments
 (0)