Skip to content

Commit 3c1b697

Browse files
committed
cleanup positioning
1 parent f480bbd commit 3c1b697

File tree

3 files changed

+28
-22
lines changed

3 files changed

+28
-22
lines changed

src/shims/windows/foreign_items.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -323,15 +323,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
323323
// FIXME: we should set last_error, but to what?
324324
this.write_null(dest)?;
325325
}
326-
// this is only callable from std because we know that std ignores the return value
327-
"SwitchToThread" if this.frame_in_std() => {
328-
let [] = this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?;
329-
330-
this.yield_active_thread();
331-
332-
// FIXME: this should return a nonzero value if this call does result in switching to another thread.
333-
this.write_null(dest)?;
334-
}
335326
"GetStdHandle" => {
336327
let [which] =
337328
this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?;
@@ -417,6 +408,15 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
417408
let result = this.GetCurrentProcessId()?;
418409
this.write_scalar(Scalar::from_u32(result), dest)?;
419410
}
411+
// this is only callable from std because we know that std ignores the return value
412+
"SwitchToThread" if this.frame_in_std() => {
413+
let [] = this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?;
414+
415+
this.yield_active_thread();
416+
417+
// FIXME: this should return a nonzero value if this call does result in switching to another thread.
418+
this.write_null(dest)?;
419+
}
420420

421421
_ => return Ok(EmulateByNameResult::NotSupported),
422422
}

src/shims/windows/handle.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ pub enum PseudoHandle {
88
CurrentThread,
99
}
1010

11+
/// Miri representation of a Windows `HANDLE`
12+
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
13+
pub enum Handle {
14+
Null,
15+
Pseudo(PseudoHandle),
16+
Thread(ThreadId),
17+
}
18+
1119
impl PseudoHandle {
1220
const CURRENT_THREAD_VALUE: u32 = 0;
1321

@@ -25,14 +33,6 @@ impl PseudoHandle {
2533
}
2634
}
2735

28-
/// Miri representation of a Windows `HANDLE`
29-
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
30-
pub enum Handle {
31-
Null,
32-
Pseudo(PseudoHandle),
33-
Thread(ThreadId),
34-
}
35-
3636
impl Handle {
3737
const NULL_DISCRIMINANT: u32 = 0;
3838
const PSEUDO_DISCRIMINANT: u32 = 1;
@@ -154,7 +154,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
154154
fn CloseHandle(&mut self, handle_op: &OpTy<'tcx, Provenance>) -> InterpResult<'tcx> {
155155
let this = self.eval_context_mut();
156156

157-
match Handle::from_scalar(this.read_scalar(handle_op)?.check_init()?, this)? {
157+
let handle = this.read_scalar(handle_op)?.check_init()?;
158+
159+
match Handle::from_scalar(handle, this)? {
158160
Some(Handle::Thread(thread)) => this.detach_thread(thread, true)?,
159161
_ => this.invalid_handle("CloseHandle")?,
160162
}

src/shims/windows/thread.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,20 +59,24 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
5959

6060
fn WaitForSingleObject(
6161
&mut self,
62-
handle: &OpTy<'tcx, Provenance>,
63-
timeout: &OpTy<'tcx, Provenance>,
62+
handle_op: &OpTy<'tcx, Provenance>,
63+
timeout_op: &OpTy<'tcx, Provenance>,
6464
) -> InterpResult<'tcx> {
6565
let this = self.eval_context_mut();
6666

67-
let thread = match Handle::from_scalar(this.read_scalar(handle)?.check_init()?, this)? {
67+
let handle = this.read_scalar(handle_op)?.check_init()?;
68+
69+
let timeout = this.read_scalar(timeout_op)?.to_u32()?;
70+
71+
let thread = match Handle::from_scalar(handle, this)? {
6872
Some(Handle::Thread(thread)) => thread,
6973
// Unlike on posix, joining the current thread is not UB on windows.
7074
// It will just deadlock.
7175
Some(Handle::Pseudo(PseudoHandle::CurrentThread)) => this.get_active_thread(),
7276
_ => this.invalid_handle("WaitForSingleObject")?,
7377
};
7478

75-
if this.read_scalar(timeout)?.to_u32()? != this.eval_windows("c", "INFINITE")?.to_u32()? {
79+
if timeout != this.eval_windows("c", "INFINITE")?.to_u32()? {
7680
throw_unsup_format!("`WaitForSingleObject` with non-infinite timeout");
7781
}
7882

0 commit comments

Comments
 (0)