]> git.lizzy.rs Git - rust.git/commitdiff
Address consistency of naming for unused/merely validated arguments.
authorChase Albert <thaoeuns@gmail.com>
Thu, 30 Apr 2020 21:30:27 +0000 (17:30 -0400)
committerChase Albert <thaoeuns@gmail.com>
Mon, 4 May 2020 17:51:23 +0000 (13:51 -0400)
src/shims/foreign_items/posix.rs
src/shims/foreign_items/posix/linux.rs
src/shims/foreign_items/posix/macos.rs
src/shims/foreign_items/windows.rs

index 4c50d5ddc5b8c402728cbde578e37c616d915e77..6b28e7070165bc31e736d63bd045e12c02d7eaca 100644 (file)
@@ -56,7 +56,7 @@ fn emulate_foreign_item_by_name(
                 this.write_scalar(Scalar::from_i32(result), dest)?;
             }
             "fcntl" => {
-                let result = this.fcntl(args);
+                let result = this.fcntl(args)?;
                 this.write_scalar(Scalar::from_i32(result), dest)?;
             }
             "read" => {
@@ -168,8 +168,8 @@ fn emulate_foreign_item_by_name(
 
             // Dynamic symbol loading
             "dlsym" => {
-                let &[_handle, symbol] = check_arg_count(args)?;
-                let _handle = this.read_scalar(_handle)?.not_undef()?;
+                let &[handle, symbol] = check_arg_count(args)?;
+                this.read_scalar(handle)?.not_undef()?;
                 let symbol = this.read_scalar(symbol)?.not_undef()?;
                 let symbol_name = this.memory.read_c_str(symbol)?;
                 let err = format!("bad c unicode symbol: {:?}", symbol_name);
@@ -360,8 +360,8 @@ fn emulate_foreign_item_by_name(
 
             // Miscellaneous
             "isatty" => {
-                let &[_fd] = check_arg_count(args)?;
-                let _fd = this.read_scalar(_fd)?.to_i32()?;
+                let &[fd] = check_arg_count(args)?;
+                this.read_scalar(fd)?.to_i32()?;
                 // "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"
                 // FIXME: we just say nothing is a terminal.
                 let enotty = this.eval_libc("ENOTTY")?;
@@ -369,10 +369,10 @@ fn emulate_foreign_item_by_name(
                 this.write_null(dest)?;
             }
             "pthread_atfork" => {
-                let &[_prepare, _parent, _child] = check_arg_count(args)?;
-                let _prepare = this.read_scalar(_prepare)?.not_undef()?;
-                let _parent = this.read_scalar(_parent)?.not_undef()?;
-                let _child = this.read_scalar(_child)?.not_undef()?;
+                let &[prepare, parent, child] = check_arg_count(args)?;
+                this.read_scalar(prepare)?.not_undef()?;
+                this.read_scalar(parent)?.not_undef()?;
+                this.read_scalar(child)?.not_undef()?;
                 // We do not support forking, so there is nothing to do here.
                 this.write_null(dest)?;
             }
index b0f4a45f1c011ed870b37fc2ed5245fac9fa45b2..3f9d1b259a86a1dd334f0816c797d7a592b098f6 100644 (file)
@@ -46,11 +46,11 @@ fn emulate_foreign_item_by_name(
             }
             // Linux-only
             "posix_fadvise" => {
-                let &[_fd, _offset, _len, _advice] = check_arg_count(args)?;
-                let _fd = this.read_scalar(_fd)?.to_i32()?;
-                let _offset = this.read_scalar(_offset)?.to_machine_isize(this)?;
-                let _len = this.read_scalar(_len)?.to_machine_isize(this)?;
-                let _advice = this.read_scalar(_advice)?.to_i32()?;
+                let &[fd, offset, len, advice] = check_arg_count(args)?;
+                this.read_scalar(fd)?.to_i32()?;
+                this.read_scalar(offset)?.to_machine_isize(this)?;
+                this.read_scalar(len)?.to_machine_isize(this)?;
+                this.read_scalar(advice)?.to_i32()?;
                 // fadvise is only informational, we can ignore it.
                 this.write_null(dest)?;
             }
@@ -66,8 +66,8 @@ fn emulate_foreign_item_by_name(
             // Querying system information
             "pthread_attr_getstack" => {
                 // We don't support "pthread_attr_setstack", so we just pretend all stacks have the same values here.
-                let &[_attr_place, addr_place, size_place] = check_arg_count(args)?;
-                let _attr_place = this.deref_operand(_attr_place)?;
+                let &[attr_place, addr_place, size_place] = check_arg_count(args)?;
+                this.deref_operand(attr_place)?;
                 let addr_place = this.deref_operand(addr_place)?;
                 let size_place = this.deref_operand(size_place)?;
 
@@ -102,14 +102,15 @@ fn emulate_foreign_item_by_name(
                     .to_machine_usize(this)?;
 
                 if args.is_empty() {
-                    throw_ub_format!("incorrect number of arguments, needed at least 1");
+                    throw_ub_format!("incorrect number of arguments for syscall, needed at least 1");
                 }
                 match this.read_scalar(args[0])?.to_machine_usize(this)? {
                     // `libc::syscall(NR_GETRANDOM, buf.as_mut_ptr(), buf.len(), GRND_NONBLOCK)`
                     // is called if a `HashMap` is created the regular way (e.g. HashMap<K, V>).
                     id if id == sys_getrandom => {
                         // The first argument is the syscall id, so skip over it.
-                        getrandom(this, &args[1..], dest)?;
+                        let &[_, ptr, len, flags] = check_arg_count(args)?;
+                        getrandom(this, ptr, len, flags, dest)?;
                     }
                     // `statx` is used by `libstd` to retrieve metadata information on `linux`
                     // instead of using `stat`,`lstat` or `fstat` as on `macos`.
@@ -125,13 +126,14 @@ fn emulate_foreign_item_by_name(
 
             // Miscelanneous
             "getrandom" => {
-                getrandom(this, args, dest)?;
+                let &[ptr, len, flags] = check_arg_count(args)?;
+                getrandom(this, ptr, len, flags, dest)?;
             }
             "sched_getaffinity" => {
-                let &[_pid, _cpusetsize, _mask] = check_arg_count(args)?;
-                let _pid = this.read_scalar(_pid)?.to_i32()?;
-                let _cpusetsize = this.read_scalar(_cpusetsize)?.to_machine_usize(this)?;
-                let _mask = this.deref_operand(_mask)?;
+                let &[pid, cpusetsize, mask] = check_arg_count(args)?;
+                this.read_scalar(pid)?.to_i32()?;
+                this.read_scalar(cpusetsize)?.to_machine_usize(this)?;
+                this.deref_operand(mask)?;
                 // FIXME: we just return an error; `num_cpus` then falls back to `sysconf`.
                 let einval = this.eval_libc("EINVAL")?;
                 this.set_last_error(einval)?;
@@ -154,16 +156,17 @@ fn emulate_foreign_item_by_name(
 // Shims the linux `getrandom` syscall.
 fn getrandom<'tcx>(
     this: &mut MiriEvalContext<'_, 'tcx>,
-    args: &[OpTy<'tcx, Tag>],
+    ptr: OpTy<'tcx, Tag>,
+    len: OpTy<'tcx, Tag>,
+    flags: OpTy<'tcx, Tag>,
     dest: PlaceTy<'tcx, Tag>,
 ) -> InterpResult<'tcx> {
-    let &[ptr, len, _flags] = check_arg_count(args)?;
     let ptr = this.read_scalar(ptr)?.not_undef()?;
     let len = this.read_scalar(len)?.to_machine_usize(this)?;
 
     // The only supported flags are GRND_RANDOM and GRND_NONBLOCK,
     // neither of which have any effect on our current PRNG.
-    let _flags = this.read_scalar(_flags)?.to_i32()?;
+    this.read_scalar(flags)?.to_i32()?;
 
     this.gen_random(ptr, len)?;
     this.write_scalar(Scalar::from_machine_usize(len, this), dest)?;
index e9fd3aa8ac81e3a38b4d1427063639c9ba0867bf..685f66d443d4f56abc787a65381831b08c1a48d3 100644 (file)
@@ -104,14 +104,14 @@ fn emulate_foreign_item_by_name(
 
             // Querying system information
             "pthread_get_stackaddr_np" => {
-                let &[_thread] = check_arg_count(args)?;
-                let _thread = this.read_scalar(_thread)?.not_undef()?;
+                let &[thread] = check_arg_count(args)?;
+                this.read_scalar(thread)?.not_undef()?;
                 let stack_addr = Scalar::from_uint(STACK_ADDR, this.pointer_size());
                 this.write_scalar(stack_addr, dest)?;
             }
             "pthread_get_stacksize_np" => {
-                let &[_thread] = check_arg_count(args)?;
-                let _thread = this.read_scalar(_thread)?.not_undef()?;
+                let &[thread] = check_arg_count(args)?;
+                this.read_scalar(thread)?.not_undef()?;
                 let stack_size = Scalar::from_uint(STACK_SIZE, this.pointer_size());
                 this.write_scalar(stack_size, dest)?;
             }
index 9edd20ddcab199010e2ce9b0e071bccad5a40142..3d7afc616e8ed58f514f8b4203e2b197c93445bb 100644 (file)
@@ -97,8 +97,8 @@ fn emulate_foreign_item_by_name(
 
             // Allocation
             "HeapAlloc" => {
-                let &[_handle, flags, size] = check_arg_count(args)?;
-                let _handle = this.read_scalar(_handle)?.to_machine_isize(this)?;
+                let &[handle, flags, size] = check_arg_count(args)?;
+                this.read_scalar(handle)?.to_machine_isize(this)?;
                 let flags = this.read_scalar(flags)?.to_u32()?;
                 let size = this.read_scalar(size)?.to_machine_usize(this)?;
                 let zero_init = (flags & 0x00000008) != 0; // HEAP_ZERO_MEMORY
@@ -106,16 +106,16 @@ fn emulate_foreign_item_by_name(
                 this.write_scalar(res, dest)?;
             }
             "HeapFree" => {
-                let &[_handle, _flags, ptr] = check_arg_count(args)?;
-                let _handle = this.read_scalar(_handle)?.to_machine_isize(this)?;
+                let &[handle, _flags, ptr] = check_arg_count(args)?;
+                this.read_scalar(handle)?.to_machine_isize(this)?;
                 let _flags = this.read_scalar(_flags)?.to_u32()?;
                 let ptr = this.read_scalar(ptr)?.not_undef()?;
                 this.free(ptr, MiriMemoryKind::WinHeap)?;
                 this.write_scalar(Scalar::from_i32(1), dest)?;
             }
             "HeapReAlloc" => {
-                let &[_handle, _flags, ptr, size] = check_arg_count(args)?;
-                let _handle = this.read_scalar(_handle)?.to_machine_isize(this)?;
+                let &[handle, _flags, ptr, size] = check_arg_count(args)?;
+                this.read_scalar(handle)?.to_machine_isize(this)?;
                 let _flags = this.read_scalar(_flags)?.to_u32()?;
                 let ptr = this.read_scalar(ptr)?.not_undef()?;
                 let size = this.read_scalar(size)?.to_machine_usize(this)?;
@@ -216,18 +216,18 @@ fn emulate_foreign_item_by_name(
             }
             "GetConsoleScreenBufferInfo" => {
                 // `term` needs this, so we fake it.
-                let &[_console, _buffer_info] = check_arg_count(args)?;
-                let _console = this.read_scalar(_console)?.to_machine_isize(this)?;
-                let _buffer_info = this.deref_operand(_buffer_info)?;
+                let &[console, buffer_info] = check_arg_count(args)?;
+                this.read_scalar(console)?.to_machine_isize(this)?;
+                this.deref_operand(buffer_info)?;
                 // Indicate an error.
                 // FIXME: we should set last_error, but to what?
                 this.write_null(dest)?;
             }
             "GetConsoleMode" => {
                 // Windows "isatty" (in libtest) needs this, so we fake it.
-                let &[_console, _mode] = check_arg_count(args)?;
-                let _console = this.read_scalar(_console)?.to_machine_isize(this)?;
-                let _mode = this.deref_operand(_mode)?;
+                let &[console, mode] = check_arg_count(args)?;
+                this.read_scalar(console)?.to_machine_isize(this)?;
+                this.deref_operand(mode)?;
                 // Indicate an error.
                 // FIXME: we should set last_error, but to what?
                 this.write_null(dest)?;