|
1 | | -use std::time::{Duration, Instant}; |
2 | | - |
3 | 1 | use rustc_middle::ty::layout::LayoutOf; |
4 | 2 | use rustc_target::spec::abi::Abi; |
5 | 3 |
|
6 | | -use crate::thread::Time; |
7 | 4 | use crate::*; |
8 | | -use shims::windows::handle::Handle; |
| 5 | +use shims::windows::handle::{EvalContextExt as _, Handle}; |
9 | 6 |
|
10 | 7 | impl<'mir, 'tcx: 'mir> EvalContextExt<'mir, 'tcx> for crate::MiriEvalContext<'mir, 'tcx> {} |
11 | 8 |
|
@@ -59,25 +56,17 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx |
59 | 56 |
|
60 | 57 | let thread = match Handle::from_scalar(this.read_scalar(handle)?.check_init()?, this)? { |
61 | 58 | Some(Handle::Thread(thread)) => thread, |
62 | | - Some(Handle::CurrentThread) => throw_ub_format!("trying to wait on itself"), |
63 | | - _ => throw_ub_format!("invalid handle"), |
| 59 | + // Unlike on posix, joining the current thread is not UB on windows. |
| 60 | + // It will just deadlock. |
| 61 | + Some(Handle::CurrentThread) => this.get_active_thread(), |
| 62 | + _ => this.invalid_handle("WaitForSingleObject")?, |
64 | 63 | }; |
65 | 64 |
|
66 | 65 | if this.read_scalar(timeout)?.to_u32()? != this.eval_windows("c", "INFINITE")?.to_u32()? { |
67 | | - this.check_no_isolation("`WaitForSingleObject` with non-infinite timeout")?; |
| 66 | + throw_unsup_format!("`WaitForSingleObject` with non-infinite timeout"); |
68 | 67 | } |
69 | 68 |
|
70 | | - let timeout_ms = this.read_scalar(timeout)?.to_u32()?; |
71 | | - |
72 | | - let timeout_time = if timeout_ms == this.eval_windows("c", "INFINITE")?.to_u32()? { |
73 | | - None |
74 | | - } else { |
75 | | - let duration = Duration::from_millis(timeout_ms as u64); |
76 | | - |
77 | | - Some(Time::Monotonic(Instant::now().checked_add(duration).unwrap())) |
78 | | - }; |
79 | | - |
80 | | - this.wait_on_thread(timeout_time, thread)?; |
| 69 | + this.join_thread(thread)?; |
81 | 70 |
|
82 | 71 | Ok(()) |
83 | 72 | } |
|
0 commit comments