Skip to content

Commit 1099b54

Browse files
committed
remove try_from_ptr_sized_operand
1 parent 9f64434 commit 1099b54

File tree

2 files changed

+18
-28
lines changed

2 files changed

+18
-28
lines changed

src/helpers.rs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
use std::{mem, iter};
22
use std::ffi::OsStr;
3-
use std::convert::{ TryFrom, TryInto };
4-
use std::num::TryFromIntError;
53

64
use syntax::source_map::DUMMY_SP;
75
use rustc::hir::def_id::{DefId, CRATE_DEF_INDEX};
@@ -482,25 +480,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
482480
self.eval_context_mut().memory.write_bytes(scalar, bytes.iter().copied().chain(iter::once(0u8)))?;
483481
Ok(true)
484482
}
485-
486-
// Converts an operand with a machine `isize` into the desired integer type using `TryInto`.
487-
// This function is useful when reading syscall related operands which are delivered as pointer
488-
// sized operands.
489-
fn try_from_ptr_sized_operand<T: TryFrom<i64, Error=TryFromIntError>>(
490-
&mut self,
491-
operand: OpTy<'tcx, Tag>,
492-
) -> InterpResult<'tcx, T> {
493-
let this = self.eval_context_mut();
494-
495-
this.read_scalar(operand)?
496-
.to_machine_isize(&*this.tcx)?
497-
.try_into()
498-
.map_err(|e| err_unsup_format!(
499-
"Failed to convert pointer sized operand to integer: {}",
500-
e
501-
).into())
502-
}
503-
504483
}
505484

506485
#[cfg(target_os = "unix")]

src/shims/fs.rs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -305,16 +305,27 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
305305

306306
let path: PathBuf = this.read_os_str_from_c_str(pathname_scalar)?.into();
307307
// `flags` should be a `c_int` but the `syscall` function provides an `isize`.
308-
let flags: i32 = this.try_from_ptr_sized_operand(flags_op)?;
309-
308+
let flags: i32 = this
309+
.read_scalar(flags_op)?
310+
.to_machine_isize(&*this.tcx)?
311+
.try_into()
312+
.map_err(|e| err_unsup_format!(
313+
"Failed to convert pointer sized operand to integer: {}",
314+
e
315+
))?;
316+
// `dirfd` should be a `c_int` but the `syscall` function provides an `isize`.
317+
let dirfd: i32 = this
318+
.read_scalar(dirfd_op)?
319+
.to_machine_isize(&*this.tcx)?
320+
.try_into()
321+
.map_err(|e| err_unsup_format!(
322+
"Failed to convert pointer sized operand to integer: {}",
323+
e
324+
))?;
310325
// we only support interpreting `path` as an absolute directory or as a directory relative
311326
// to `dirfd` when the latter is `AT_FDCWD`. Other behavior is specified but it cannot be
312327
// tested from `libstd`. If you found this error, please open an issue reporting it.
313-
314-
// `dirfd` should be a `c_int` but the `syscall` function provides an `isize`.
315-
if !(path.is_absolute()
316-
|| this.try_from_ptr_sized_operand::<i32>(dirfd_op)?
317-
== this.eval_libc_i32("AT_FDCWD")?)
328+
if !(path.is_absolute() || dirfd == this.eval_libc_i32("AT_FDCWD")?)
318329
{
319330
throw_unsup_format!(
320331
"Using statx with a file descriptor different from `AT_FDCWD` is not supported"

0 commit comments

Comments
 (0)