Address comments.

This commit is contained in:
Chase Albert 2020-05-04 14:24:22 -04:00
parent f46d197431
commit 4e3d1fee51
7 changed files with 22 additions and 26 deletions

View File

@ -477,7 +477,7 @@ fn try_unwrap_io_result<T: From<i32>>(
if let Ok(ops) = args.try_into() {
return Ok(ops);
}
throw_ub_format!("incorrect number of arguments, got {}, needed {}", args.len(), N)
throw_ub_format!("incorrect number of arguments: got {}, expected {}", args.len(), N)
}
pub fn immty_from_int_checked<'tcx>(

View File

@ -454,6 +454,7 @@ fn emulate_foreign_item_by_name(
// Architecture-specific shims
"llvm.x86.sse2.pause" if this.tcx.sess.target.target.arch == "x86" || this.tcx.sess.target.target.arch == "x86_64" => {
let &[] = check_arg_count(args)?;
this.sched_yield()?;
}

View File

@ -102,7 +102,7 @@ fn emulate_foreign_item_by_name(
.to_machine_usize(this)?;
if args.is_empty() {
throw_ub_format!("incorrect number of arguments for syscall, needed at least 1");
throw_ub_format!("incorrect number of arguments for syscall: got 0, expected 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)`
@ -143,6 +143,7 @@ fn emulate_foreign_item_by_name(
// Incomplete shims that we "stub out" just to get pre-main initialization code to work.
// These shims are enabled only when the caller is in the standard library.
"pthread_getattr_np" if this.frame().instance.to_string().starts_with("std::sys::unix::") => {
let &[_thread, _attr] = check_arg_count(args)?;
this.write_null(dest)?;
}

View File

@ -118,8 +118,9 @@ fn emulate_foreign_item_by_name(
// Threading
"pthread_setname_np" => {
let ptr = this.read_scalar(args[0])?.not_undef()?;
this.pthread_setname_np(ptr)?;
let &[name] = check_arg_count(args)?;
let name = this.read_scalar(name)?.not_undef()?;
this.pthread_setname_np(name)?;
}
// Incomplete shims that we "stub out" just to get pre-main initialization code to work.

View File

@ -106,17 +106,17 @@ fn emulate_foreign_item_by_name(
this.write_scalar(res, dest)?;
}
"HeapFree" => {
let &[handle, _flags, ptr] = check_arg_count(args)?;
let &[handle, flags, ptr] = check_arg_count(args)?;
this.read_scalar(handle)?.to_machine_isize(this)?;
let _flags = this.read_scalar(_flags)?.to_u32()?;
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, flags, ptr, size] = check_arg_count(args)?;
this.read_scalar(handle)?.to_machine_isize(this)?;
let _flags = this.read_scalar(_flags)?.to_u32()?;
this.read_scalar(flags)?.to_u32()?;
let ptr = this.read_scalar(ptr)?.not_undef()?;
let size = this.read_scalar(size)?.to_machine_usize(this)?;
let res = this.realloc(ptr, size, MiriMemoryKind::WinHeap)?;

View File

@ -328,22 +328,18 @@ fn fcntl(
this.check_no_isolation("fcntl")?;
let (fd, cmd, start) = if args.len() == 2 {
let &[fd, cmd] = check_arg_count(args)?;
(fd, cmd, None)
} else {
// If args.len() isn't 2 or 3 this will error appropriately.
let &[fd, cmd, start] = check_arg_count(args)?;
(fd, cmd, Some(start))
};
let fd = this.read_scalar(fd)?.to_i32()?;
let cmd = this.read_scalar(cmd)?.to_i32()?;
if args.len() < 2 {
throw_ub_format!("incorrect number of arguments for fcntl: got {}, expected at least 2", args.len());
}
let cmd = this.read_scalar(args[1])?.to_i32()?;
// We only support getting the flags for a descriptor.
if cmd == this.eval_libc_i32("F_GETFD")? {
// Currently this is the only flag that `F_GETFD` returns. It is OK to just return the
// `FD_CLOEXEC` value without checking if the flag is set for the file because `std`
// always sets this flag when opening a file. However we still need to check that the
// file itself is open.
let &[fd, _] = check_arg_count(args)?;
let fd = this.read_scalar(fd)?.to_i32()?;
if this.machine.file_handler.handles.contains_key(&fd) {
Ok(this.eval_libc_i32("FD_CLOEXEC")?)
} else {
@ -356,15 +352,12 @@ fn fcntl(
// because exec() isn't supported. The F_DUPFD and F_DUPFD_CLOEXEC commands only
// differ in whether the FD_CLOEXEC flag is pre-set on the new file descriptor,
// thus they can share the same implementation here.
let &[fd, _, start] = check_arg_count(args)?;
let fd = this.read_scalar(fd)?.to_i32()?;
let start = this.read_scalar(start)?.to_i32()?;
if fd < MIN_NORMAL_FILE_FD {
throw_unsup_format!("duplicating file descriptors for stdin, stdout, or stderr is not supported")
}
let start = start.ok_or_else(|| {
err_unsup_format!(
"fcntl with command F_DUPFD or F_DUPFD_CLOEXEC requires a third argument"
)
})?;
let start = this.read_scalar(start)?.to_i32()?;
let fh = &mut this.machine.file_handler;
let (file_result, writable) = match fh.handles.get(&fd) {
Some(FileHandle { file, writable }) => (file.try_clone(), *writable),

View File

@ -121,12 +121,12 @@ fn prctl(
fn pthread_setname_np(
&mut self,
ptr: Scalar<Tag>,
name: Scalar<Tag>,
) -> InterpResult<'tcx> {
let this = self.eval_context_mut();
this.assert_target_os("macos", "pthread_setname_np");
let name = this.memory.read_c_str(ptr)?.to_owned();
let name = this.memory.read_c_str(name)?.to_owned();
this.set_active_thread_name(name)?;
Ok(())