Skip to content

Commit

Permalink
Don't leak miri implementation details
Browse files Browse the repository at this point in the history
  • Loading branch information
CraftSpider committed Dec 6, 2024
1 parent 9a76a85 commit cc6eae5
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 12 deletions.
6 changes: 3 additions & 3 deletions src/shims/windows/foreign_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
let [handle, name] =
this.check_shim(abi, ExternAbi::System { unwind: false }, link_name, args)?;

let handle = this.read_handle(handle)?;
let handle = this.read_handle(handle, "SetThreadDescription")?;
let name = this.read_wide_str(this.read_pointer(name)?)?;

let thread = match handle {
Expand All @@ -558,7 +558,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
let [handle, name_ptr] =
this.check_shim(abi, ExternAbi::System { unwind: false }, link_name, args)?;

let handle = this.read_handle(handle)?;
let handle = this.read_handle(handle, "GetThreadDescription")?;
let name_ptr = this.deref_pointer(name_ptr)?; // the pointer where we should store the ptr to the name

let thread = match handle {
Expand Down Expand Up @@ -674,7 +674,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
this.check_shim(abi, ExternAbi::System { unwind: false }, link_name, args)?;
this.check_no_isolation("`GetModuleFileNameW`")?;

let handle = this.read_handle(handle)?;
let handle = this.read_handle(handle, "GetModuleFileNameW")?;
let filename = this.read_pointer(filename)?;
let size = this.read_scalar(size)?.to_u32()?;

Expand Down
2 changes: 1 addition & 1 deletion src/shims/windows/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
this.assert_target_os("windows", "GetFileInformationByHandle");
this.check_no_isolation("`GetFileInformationByHandle`")?;

let file = this.read_handle(file)?;
let file = this.read_handle(file, "GetFileInformationByHandle")?;
let file_information = this.deref_pointer_as(
file_information,
this.windows_ty_layout("BY_HANDLE_FILE_INFORMATION"),
Expand Down
12 changes: 5 additions & 7 deletions src/shims/windows/handle.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::mem::variant_count;
use std::panic::Location;

use rustc_abi::HasDataLayout;

Expand Down Expand Up @@ -201,21 +200,20 @@ impl<'tcx> EvalContextExt<'tcx> for crate::MiriInterpCx<'tcx> {}
#[allow(non_snake_case)]
pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
#[track_caller]
fn read_handle(&self, handle: &OpTy<'tcx>) -> InterpResult<'tcx, Handle> {
fn read_handle(&self, handle: &OpTy<'tcx>, function_name: &str) -> InterpResult<'tcx, Handle> {
let this = self.eval_context_ref();
let handle = this.read_scalar(handle)?;
match Handle::try_from_scalar(handle, this)? {
Ok(handle) => interp_ok(handle),
Err(HandleError::InvalidHandle) =>
throw_machine_stop!(TerminationInfo::Abort(format!(
"invalid handle {} at {}",
"invalid handle {} passed to {function_name}",
handle.to_target_isize(this)?,
Location::caller(),
))),
Err(HandleError::ThreadNotFound(_)) =>
throw_machine_stop!(TerminationInfo::Abort(format!(
"invalid thread ID: {}",
Location::caller()
"invalid thread ID {} passed to {function_name}",
handle.to_target_isize(this)?,
))),
}
}
Expand All @@ -229,7 +227,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
fn CloseHandle(&mut self, handle_op: &OpTy<'tcx>) -> InterpResult<'tcx, Scalar> {
let this = self.eval_context_mut();

let handle = this.read_handle(handle_op)?;
let handle = this.read_handle(handle_op, "CloseHandle")?;
let ret = match handle {
Handle::Thread(thread) => {
this.detach_thread(thread, /*allow_terminated_joined*/ true)?;
Expand Down
2 changes: 1 addition & 1 deletion src/shims/windows/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
) -> InterpResult<'tcx, Scalar> {
let this = self.eval_context_mut();

let handle = this.read_handle(handle_op)?;
let handle = this.read_handle(handle_op, "WaitForSingleObject")?;
let timeout = this.read_scalar(timeout_op)?.to_u32()?;

let thread = match handle {
Expand Down

0 comments on commit cc6eae5

Please sign in to comment.