Skip to content

Commit 4554b65

Browse files
committed
use abort for all invalid handles
1 parent ecc5f88 commit 4554b65

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

src/shims/windows/dlsym.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_target::spec::abi::Abi;
55
use log::trace;
66

77
use crate::helpers::check_arg_count;
8-
use crate::shims::windows::handle::Handle;
8+
use crate::shims::windows::handle::{EvalContextExt as _, Handle};
99
use crate::*;
1010

1111
#[derive(Debug, Copy, Clone)]
@@ -118,7 +118,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
118118
match Handle::from_scalar(this.read_scalar(handle)?.check_init()?, this)? {
119119
Some(Handle::Thread(thread)) => thread,
120120
Some(Handle::CurrentThread) => this.get_active_thread(),
121-
_ => throw_ub_format!("invalid handle"),
121+
_ => this.invalid_handle("SetThreadDescription")?,
122122
};
123123

124124
this.set_thread_name_wide(thread, name);

src/shims/windows/handle.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,16 +146,19 @@ impl<'mir, 'tcx> EvalContextExt<'mir, 'tcx> for crate::MiriEvalContext<'mir, 'tc
146146

147147
#[allow(non_snake_case)]
148148
pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx> {
149+
fn invalid_handle(&mut self, function_name: &str) -> InterpResult<'tcx, !> {
150+
throw_machine_stop!(TerminationInfo::Abort(format!(
151+
"invalid handle passed to `{function_name}`"
152+
)))
153+
}
154+
149155
fn CloseHandle(&mut self, handle_op: &OpTy<'tcx, Provenance>) -> InterpResult<'tcx> {
150156
let this = self.eval_context_mut();
151157

152158
match Handle::from_scalar(this.read_scalar(handle_op)?.check_init()?, this)? {
153159
Some(Handle::Thread(thread)) => this.detach_thread(thread, true)?,
154-
_ =>
155-
throw_machine_stop!(TerminationInfo::Abort(
156-
"invalid handle passed to `CloseHandle`".into()
157-
)),
158-
};
160+
_ => this.invalid_handle("CloseHandle")?,
161+
}
159162

160163
Ok(())
161164
}

src/shims/windows/thread.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
use std::time::{Duration, Instant};
2-
31
use rustc_middle::ty::layout::LayoutOf;
42
use rustc_target::spec::abi::Abi;
53

6-
use crate::thread::Time;
74
use crate::*;
8-
use shims::windows::handle::Handle;
5+
use shims::windows::handle::{EvalContextExt as _, Handle};
96

107
impl<'mir, 'tcx: 'mir> EvalContextExt<'mir, 'tcx> for crate::MiriEvalContext<'mir, 'tcx> {}
118

@@ -62,7 +59,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
6259
// Unlike on posix, joining the current thread is not UB on windows.
6360
// It will just deadlock.
6461
Some(Handle::CurrentThread) => this.get_active_thread(),
65-
_ => throw_ub_format!("invalid handle"),
62+
_ => this.invalid_handle("WaitForSingleObject")?,
6663
};
6764

6865
if this.read_scalar(timeout)?.to_u32()? != this.eval_windows("c", "INFINITE")?.to_u32()? {

0 commit comments

Comments
 (0)