Skip to content

Commit 4d3dff2

Browse files
committed
Address consistency of naming for unused/merely validated arguments.
1 parent 46aaab3 commit 4d3dff2

File tree

4 files changed

+45
-42
lines changed

4 files changed

+45
-42
lines changed

src/shims/foreign_items/posix.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
5656
this.write_scalar(Scalar::from_i32(result), dest)?;
5757
}
5858
"fcntl" => {
59-
let result = this.fcntl(args);
59+
let result = this.fcntl(args)?;
6060
this.write_scalar(Scalar::from_i32(result), dest)?;
6161
}
6262
"read" => {
@@ -168,8 +168,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
168168

169169
// Dynamic symbol loading
170170
"dlsym" => {
171-
let &[_handle, symbol] = check_arg_count(args)?;
172-
let _handle = this.read_scalar(_handle)?.not_undef()?;
171+
let &[handle, symbol] = check_arg_count(args)?;
172+
this.read_scalar(handle)?.not_undef()?;
173173
let symbol = this.read_scalar(symbol)?.not_undef()?;
174174
let symbol_name = this.memory.read_c_str(symbol)?;
175175
let err = format!("bad c unicode symbol: {:?}", symbol_name);
@@ -360,19 +360,19 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
360360

361361
// Miscellaneous
362362
"isatty" => {
363-
let &[_fd] = check_arg_count(args)?;
364-
let _fd = this.read_scalar(_fd)?.to_i32()?;
363+
let &[fd] = check_arg_count(args)?;
364+
this.read_scalar(fd)?.to_i32()?;
365365
// "returns 1 if fd is an open file descriptor referring to a terminal; otherwise 0 is returned, and errno is set to indicate the error"
366366
// FIXME: we just say nothing is a terminal.
367367
let enotty = this.eval_libc("ENOTTY")?;
368368
this.set_last_error(enotty)?;
369369
this.write_null(dest)?;
370370
}
371371
"pthread_atfork" => {
372-
let &[_prepare, _parent, _child] = check_arg_count(args)?;
373-
let _prepare = this.read_scalar(_prepare)?.not_undef()?;
374-
let _parent = this.read_scalar(_parent)?.not_undef()?;
375-
let _child = this.read_scalar(_child)?.not_undef()?;
372+
let &[prepare, parent, child] = check_arg_count(args)?;
373+
this.read_scalar(prepare)?.not_undef()?;
374+
this.read_scalar(parent)?.not_undef()?;
375+
this.read_scalar(child)?.not_undef()?;
376376
// We do not support forking, so there is nothing to do here.
377377
this.write_null(dest)?;
378378
}

src/shims/foreign_items/posix/linux.rs

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
4646
}
4747
// Linux-only
4848
"posix_fadvise" => {
49-
let &[_fd, _offset, _len, _advice] = check_arg_count(args)?;
50-
let _fd = this.read_scalar(_fd)?.to_i32()?;
51-
let _offset = this.read_scalar(_offset)?.to_machine_isize(this)?;
52-
let _len = this.read_scalar(_len)?.to_machine_isize(this)?;
53-
let _advice = this.read_scalar(_advice)?.to_i32()?;
49+
let &[fd, offset, len, advice] = check_arg_count(args)?;
50+
this.read_scalar(fd)?.to_i32()?;
51+
this.read_scalar(offset)?.to_machine_isize(this)?;
52+
this.read_scalar(len)?.to_machine_isize(this)?;
53+
this.read_scalar(advice)?.to_i32()?;
5454
// fadvise is only informational, we can ignore it.
5555
this.write_null(dest)?;
5656
}
@@ -66,8 +66,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
6666
// Querying system information
6767
"pthread_attr_getstack" => {
6868
// We don't support "pthread_attr_setstack", so we just pretend all stacks have the same values here.
69-
let &[_attr_place, addr_place, size_place] = check_arg_count(args)?;
70-
let _attr_place = this.deref_operand(_attr_place)?;
69+
let &[attr_place, addr_place, size_place] = check_arg_count(args)?;
70+
this.deref_operand(attr_place)?;
7171
let addr_place = this.deref_operand(addr_place)?;
7272
let size_place = this.deref_operand(size_place)?;
7373

@@ -102,14 +102,15 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
102102
.to_machine_usize(this)?;
103103

104104
if args.is_empty() {
105-
throw_ub_format!("incorrect number of arguments, needed at least 1");
105+
throw_ub_format!("incorrect number of arguments for syscall, needed at least 1");
106106
}
107107
match this.read_scalar(args[0])?.to_machine_usize(this)? {
108108
// `libc::syscall(NR_GETRANDOM, buf.as_mut_ptr(), buf.len(), GRND_NONBLOCK)`
109109
// is called if a `HashMap` is created the regular way (e.g. HashMap<K, V>).
110110
id if id == sys_getrandom => {
111111
// The first argument is the syscall id, so skip over it.
112-
getrandom(this, &args[1..], dest)?;
112+
let &[_, ptr, len, flags] = check_arg_count(args)?;
113+
getrandom(this, ptr, len, flags, dest)?;
113114
}
114115
// `statx` is used by `libstd` to retrieve metadata information on `linux`
115116
// instead of using `stat`,`lstat` or `fstat` as on `macos`.
@@ -125,13 +126,14 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
125126

126127
// Miscelanneous
127128
"getrandom" => {
128-
getrandom(this, args, dest)?;
129+
let &[ptr, len, flags] = check_arg_count(args)?;
130+
getrandom(this, ptr, len, flags, dest)?;
129131
}
130132
"sched_getaffinity" => {
131-
let &[_pid, _cpusetsize, _mask] = check_arg_count(args)?;
132-
let _pid = this.read_scalar(_pid)?.to_i32()?;
133-
let _cpusetsize = this.read_scalar(_cpusetsize)?.to_machine_usize(this)?;
134-
let _mask = this.deref_operand(_mask)?;
133+
let &[pid, cpusetsize, mask] = check_arg_count(args)?;
134+
this.read_scalar(pid)?.to_i32()?;
135+
this.read_scalar(cpusetsize)?.to_machine_usize(this)?;
136+
this.deref_operand(mask)?;
135137
// FIXME: we just return an error; `num_cpus` then falls back to `sysconf`.
136138
let einval = this.eval_libc("EINVAL")?;
137139
this.set_last_error(einval)?;
@@ -154,16 +156,17 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
154156
// Shims the linux `getrandom` syscall.
155157
fn getrandom<'tcx>(
156158
this: &mut MiriEvalContext<'_, 'tcx>,
157-
args: &[OpTy<'tcx, Tag>],
159+
ptr: OpTy<'tcx, Tag>,
160+
len: OpTy<'tcx, Tag>,
161+
flags: OpTy<'tcx, Tag>,
158162
dest: PlaceTy<'tcx, Tag>,
159163
) -> InterpResult<'tcx> {
160-
let &[ptr, len, _flags] = check_arg_count(args)?;
161164
let ptr = this.read_scalar(ptr)?.not_undef()?;
162165
let len = this.read_scalar(len)?.to_machine_usize(this)?;
163166

164167
// The only supported flags are GRND_RANDOM and GRND_NONBLOCK,
165168
// neither of which have any effect on our current PRNG.
166-
let _flags = this.read_scalar(_flags)?.to_i32()?;
169+
this.read_scalar(flags)?.to_i32()?;
167170

168171
this.gen_random(ptr, len)?;
169172
this.write_scalar(Scalar::from_machine_usize(len, this), dest)?;

src/shims/foreign_items/posix/macos.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,14 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
104104

105105
// Querying system information
106106
"pthread_get_stackaddr_np" => {
107-
let &[_thread] = check_arg_count(args)?;
108-
let _thread = this.read_scalar(_thread)?.not_undef()?;
107+
let &[thread] = check_arg_count(args)?;
108+
this.read_scalar(thread)?.not_undef()?;
109109
let stack_addr = Scalar::from_uint(STACK_ADDR, this.pointer_size());
110110
this.write_scalar(stack_addr, dest)?;
111111
}
112112
"pthread_get_stacksize_np" => {
113-
let &[_thread] = check_arg_count(args)?;
114-
let _thread = this.read_scalar(_thread)?.not_undef()?;
113+
let &[thread] = check_arg_count(args)?;
114+
this.read_scalar(thread)?.not_undef()?;
115115
let stack_size = Scalar::from_uint(STACK_SIZE, this.pointer_size());
116116
this.write_scalar(stack_size, dest)?;
117117
}

src/shims/foreign_items/windows.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -97,25 +97,25 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
9797

9898
// Allocation
9999
"HeapAlloc" => {
100-
let &[_handle, flags, size] = check_arg_count(args)?;
101-
let _handle = this.read_scalar(_handle)?.to_machine_isize(this)?;
100+
let &[handle, flags, size] = check_arg_count(args)?;
101+
this.read_scalar(handle)?.to_machine_isize(this)?;
102102
let flags = this.read_scalar(flags)?.to_u32()?;
103103
let size = this.read_scalar(size)?.to_machine_usize(this)?;
104104
let zero_init = (flags & 0x00000008) != 0; // HEAP_ZERO_MEMORY
105105
let res = this.malloc(size, zero_init, MiriMemoryKind::WinHeap);
106106
this.write_scalar(res, dest)?;
107107
}
108108
"HeapFree" => {
109-
let &[_handle, _flags, ptr] = check_arg_count(args)?;
110-
let _handle = this.read_scalar(_handle)?.to_machine_isize(this)?;
109+
let &[handle, _flags, ptr] = check_arg_count(args)?;
110+
this.read_scalar(handle)?.to_machine_isize(this)?;
111111
let _flags = this.read_scalar(_flags)?.to_u32()?;
112112
let ptr = this.read_scalar(ptr)?.not_undef()?;
113113
this.free(ptr, MiriMemoryKind::WinHeap)?;
114114
this.write_scalar(Scalar::from_i32(1), dest)?;
115115
}
116116
"HeapReAlloc" => {
117-
let &[_handle, _flags, ptr, size] = check_arg_count(args)?;
118-
let _handle = this.read_scalar(_handle)?.to_machine_isize(this)?;
117+
let &[handle, _flags, ptr, size] = check_arg_count(args)?;
118+
this.read_scalar(handle)?.to_machine_isize(this)?;
119119
let _flags = this.read_scalar(_flags)?.to_u32()?;
120120
let ptr = this.read_scalar(ptr)?.not_undef()?;
121121
let size = this.read_scalar(size)?.to_machine_usize(this)?;
@@ -216,18 +216,18 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
216216
}
217217
"GetConsoleScreenBufferInfo" => {
218218
// `term` needs this, so we fake it.
219-
let &[_console, _buffer_info] = check_arg_count(args)?;
220-
let _console = this.read_scalar(_console)?.to_machine_isize(this)?;
221-
let _buffer_info = this.deref_operand(_buffer_info)?;
219+
let &[console, buffer_info] = check_arg_count(args)?;
220+
this.read_scalar(console)?.to_machine_isize(this)?;
221+
this.deref_operand(buffer_info)?;
222222
// Indicate an error.
223223
// FIXME: we should set last_error, but to what?
224224
this.write_null(dest)?;
225225
}
226226
"GetConsoleMode" => {
227227
// Windows "isatty" (in libtest) needs this, so we fake it.
228-
let &[_console, _mode] = check_arg_count(args)?;
229-
let _console = this.read_scalar(_console)?.to_machine_isize(this)?;
230-
let _mode = this.deref_operand(_mode)?;
228+
let &[console, mode] = check_arg_count(args)?;
229+
this.read_scalar(console)?.to_machine_isize(this)?;
230+
this.deref_operand(mode)?;
231231
// Indicate an error.
232232
// FIXME: we should set last_error, but to what?
233233
this.write_null(dest)?;

0 commit comments

Comments
 (0)