Skip to content

Commit

Permalink
Fix var arg handling
Browse files Browse the repository at this point in the history
  • Loading branch information
tiif committed Jan 14, 2025
1 parent 8b8b141 commit 909364c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/shims/unix/android/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub fn prctl<'tcx>(
) -> InterpResult<'tcx> {
// We do not use `check_shim` here because `prctl` is variadic. The argument
// count is checked bellow.
let (fixed, var) = ecx.check_shim_variadic::<1>(abi, Conv::C, link_name, "prctl", args)?;
let (fixed, _var) = ecx.check_shim_variadic::<1>(abi, Conv::C, link_name, "prctl", args)?;

// FIXME: Use constants once https://github.com/rust-lang/libc/pull/3941 backported to the 0.2 branch.
let pr_set_name = 15;
Expand All @@ -27,7 +27,7 @@ pub fn prctl<'tcx>(
let [op] = fixed;
let res = match ecx.read_scalar(op)?.to_i32()? {
op if op == pr_set_name => {
let [name] = check_min_arg_count("prctl(PR_SET_NAME, ...)", var)?;
let [_, name] = check_min_arg_count("prctl(PR_SET_NAME, ...)", args)?;
let name = ecx.read_scalar(name)?;
let thread = ecx.pthread_self()?;
// The Linux kernel silently truncates long names.
Expand All @@ -38,7 +38,7 @@ pub fn prctl<'tcx>(
Scalar::from_u32(0)
}
op if op == pr_get_name => {
let [name] = check_min_arg_count("prctl(PR_GET_NAME, ...)", var)?;
let [_, name] = check_min_arg_count("prctl(PR_GET_NAME, ...)", args)?;
let name = ecx.read_scalar(name)?;
let thread = ecx.pthread_self()?;
let len = Scalar::from_target_usize(TASK_COMM_LEN as u64, ecx);
Expand Down
9 changes: 7 additions & 2 deletions src/shims/unix/fd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,12 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
interp_ok(Scalar::from_i32(this.try_unwrap_io_result(result)?))
}

fn fcntl(&mut self, fixed: &[OpTy<'tcx>; 2], var: &[OpTy<'tcx>]) -> InterpResult<'tcx, Scalar> {
fn fcntl(
&mut self,
args: &[OpTy<'tcx>],
fixed: &[OpTy<'tcx>; 2],
_var: &[OpTy<'tcx>],
) -> InterpResult<'tcx, Scalar> {
let this = self.eval_context_mut();

let [fd_num, cmd] = fixed;
Expand Down Expand Up @@ -163,7 +168,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
"fcntl(fd, F_DUPFD_CLOEXEC, ...)"
};

let [start] = check_min_arg_count(cmd_name, var)?;
let [_, _, start] = check_min_arg_count(cmd_name, args)?;
let start = this.read_scalar(start)?.to_i32()?;

if let Some(fd) = this.machine.fds.get(fd_num) {
Expand Down
4 changes: 2 additions & 2 deletions src/shims/unix/foreign_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// `fcntl` is variadic. The argument count is checked based on the first argument
// in `this.fcntl()`, so we do not use `check_shim` here.
let (fixed, var) = this.check_shim_variadic::<2>(abi, Conv::C, link_name, "fcntl", args)?;
let result = this.fcntl(fixed, var)?;
let result = this.fcntl(args, fixed, var)?;
this.write_scalar(result, dest)?;
}
"dup" => {
Expand Down Expand Up @@ -236,7 +236,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
"open" | "open64" => {
// `open` is variadic, the third argument is only present when the second argument has O_CREAT (or on linux O_TMPFILE, but miri doesn't support that) set
let (fixed, var) = this.check_shim_variadic::<2>(abi, Conv::C, link_name, "open/open64", args)?;
let result = this.open(fixed, var)?;
let result = this.open(args, fixed, var)?;
this.write_scalar(result, dest)?;
}
"unlink" => {
Expand Down
9 changes: 7 additions & 2 deletions src/shims/unix/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,12 @@ fn maybe_sync_file(

impl<'tcx> EvalContextExt<'tcx> for crate::MiriInterpCx<'tcx> {}
pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
fn open(&mut self, fixed: &[OpTy<'tcx>; 2], var: &[OpTy<'tcx>]) -> InterpResult<'tcx, Scalar> {
fn open(
&mut self,
args: &[OpTy<'tcx>],
fixed: &[OpTy<'tcx>; 2],
_var: &[OpTy<'tcx>],
) -> InterpResult<'tcx, Scalar> {
let [path_raw, flag] = fixed;

let this = self.eval_context_mut();
Expand Down Expand Up @@ -507,7 +512,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// Get the mode. On macOS, the argument type `mode_t` is actually `u16`, but
// C integer promotion rules mean that on the ABI level, it gets passed as `u32`
// (see https://github.com/rust-lang/rust/issues/71915).
let [mode] = check_min_arg_count("open(pathname, O_CREAT, ...)", var)?;
let [_, _, mode] = check_min_arg_count("open(pathname, O_CREAT, ...)", args)?;
let mode = this.read_scalar(mode)?.to_u32()?;

#[cfg(unix)]
Expand Down

0 comments on commit 909364c

Please sign in to comment.