From cc6eae53d661dde499addd12e387b0eb3ef3024e Mon Sep 17 00:00:00 2001 From: Rune Tynan Date: Thu, 5 Dec 2024 20:04:38 -0800 Subject: [PATCH] Don't leak miri implementation details --- src/shims/windows/foreign_items.rs | 6 +++--- src/shims/windows/fs.rs | 2 +- src/shims/windows/handle.rs | 12 +++++------- src/shims/windows/thread.rs | 2 +- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/shims/windows/foreign_items.rs b/src/shims/windows/foreign_items.rs index 7e7cb69e8a..3af2d78bca 100644 --- a/src/shims/windows/foreign_items.rs +++ b/src/shims/windows/foreign_items.rs @@ -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 { @@ -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 { @@ -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()?; diff --git a/src/shims/windows/fs.rs b/src/shims/windows/fs.rs index 4522cde8c8..077be337cc 100644 --- a/src/shims/windows/fs.rs +++ b/src/shims/windows/fs.rs @@ -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"), diff --git a/src/shims/windows/handle.rs b/src/shims/windows/handle.rs index 836ef11872..433cb09ecf 100644 --- a/src/shims/windows/handle.rs +++ b/src/shims/windows/handle.rs @@ -1,5 +1,4 @@ use std::mem::variant_count; -use std::panic::Location; use rustc_abi::HasDataLayout; @@ -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)?, ))), } } @@ -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)?; diff --git a/src/shims/windows/thread.rs b/src/shims/windows/thread.rs index 2c4d5c2297..ff83befb88 100644 --- a/src/shims/windows/thread.rs +++ b/src/shims/windows/thread.rs @@ -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 {