File tree Expand file tree Collapse file tree 2 files changed +16
-0
lines changed
Expand file tree Collapse file tree 2 files changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -269,6 +269,16 @@ pub const unsafe fn assert_unchecked(cond: bool) {
269269#[ stable( feature = "renamed_spin_loop" , since = "1.49.0" ) ]
270270pub fn spin_loop ( ) {
271271 crate :: cfg_select! {
272+ miri => {
273+ unsafe extern "Rust" {
274+ safe fn miri_spin_loop( ) ;
275+ }
276+
277+ // Miri does support some of the intrinsics that are called below, but to guarantee
278+ // consistent behavior across targets, this custom function is used. To maximize the
279+ // likelyhood of finding actual issues, it will attempt to find another thread to run.
280+ miri_spin_loop( ) ;
281+ }
272282 target_arch = "x86" => {
273283 // SAFETY: the `cfg` attr ensures that we only execute this on x86 targets.
274284 crate :: arch:: x86:: _mm_pause( )
Original file line number Diff line number Diff line change @@ -435,6 +435,12 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
435435 // Return value: 0 on success, otherwise the size it would have needed.
436436 this. write_int ( if success { 0 } else { needed_size } , dest) ?;
437437 }
438+ // Hint that a loop is spinning indefinitely.
439+ "miri_spin_loop" => {
440+ // To maximize the chance of finding actual bugs, try to find another thread to
441+ // run.
442+ this. yield_active_thread ( ) ;
443+ }
438444 // Obtains the size of a Miri backtrace. See the README for details.
439445 "miri_backtrace_size" => {
440446 this. handle_miri_backtrace_size ( abi, link_name, args, dest) ?;
You can’t perform that action at this time.
0 commit comments