Address comments.
This commit is contained in:
parent
f46d197431
commit
4e3d1fee51
@ -477,7 +477,7 @@ pub fn check_arg_count<'a, 'tcx, const N: usize>(args: &'a [OpTy<'tcx, Tag>]) ->
|
|||||||
if let Ok(ops) = args.try_into() {
|
if let Ok(ops) = args.try_into() {
|
||||||
return Ok(ops);
|
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>(
|
pub fn immty_from_int_checked<'tcx>(
|
||||||
|
@ -454,6 +454,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
|||||||
|
|
||||||
// Architecture-specific shims
|
// Architecture-specific shims
|
||||||
"llvm.x86.sse2.pause" if this.tcx.sess.target.target.arch == "x86" || this.tcx.sess.target.target.arch == "x86_64" => {
|
"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()?;
|
this.sched_yield()?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,7 +102,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
|||||||
.to_machine_usize(this)?;
|
.to_machine_usize(this)?;
|
||||||
|
|
||||||
if args.is_empty() {
|
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)? {
|
match this.read_scalar(args[0])?.to_machine_usize(this)? {
|
||||||
// `libc::syscall(NR_GETRANDOM, buf.as_mut_ptr(), buf.len(), GRND_NONBLOCK)`
|
// `libc::syscall(NR_GETRANDOM, buf.as_mut_ptr(), buf.len(), GRND_NONBLOCK)`
|
||||||
@ -143,6 +143,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
|||||||
// Incomplete shims that we "stub out" just to get pre-main initialization code to work.
|
// 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.
|
// 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::") => {
|
"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)?;
|
this.write_null(dest)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,8 +118,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
|||||||
|
|
||||||
// Threading
|
// Threading
|
||||||
"pthread_setname_np" => {
|
"pthread_setname_np" => {
|
||||||
let ptr = this.read_scalar(args[0])?.not_undef()?;
|
let &[name] = check_arg_count(args)?;
|
||||||
this.pthread_setname_np(ptr)?;
|
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.
|
// Incomplete shims that we "stub out" just to get pre-main initialization code to work.
|
||||||
|
@ -106,17 +106,17 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
|||||||
this.write_scalar(res, dest)?;
|
this.write_scalar(res, dest)?;
|
||||||
}
|
}
|
||||||
"HeapFree" => {
|
"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)?;
|
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 ptr = this.read_scalar(ptr)?.not_undef()?;
|
||||||
this.free(ptr, MiriMemoryKind::WinHeap)?;
|
this.free(ptr, MiriMemoryKind::WinHeap)?;
|
||||||
this.write_scalar(Scalar::from_i32(1), dest)?;
|
this.write_scalar(Scalar::from_i32(1), dest)?;
|
||||||
}
|
}
|
||||||
"HeapReAlloc" => {
|
"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)?;
|
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 ptr = this.read_scalar(ptr)?.not_undef()?;
|
||||||
let size = this.read_scalar(size)?.to_machine_usize(this)?;
|
let size = this.read_scalar(size)?.to_machine_usize(this)?;
|
||||||
let res = this.realloc(ptr, size, MiriMemoryKind::WinHeap)?;
|
let res = this.realloc(ptr, size, MiriMemoryKind::WinHeap)?;
|
||||||
|
@ -328,22 +328,18 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
|||||||
|
|
||||||
this.check_no_isolation("fcntl")?;
|
this.check_no_isolation("fcntl")?;
|
||||||
|
|
||||||
let (fd, cmd, start) = if args.len() == 2 {
|
if args.len() < 2 {
|
||||||
let &[fd, cmd] = check_arg_count(args)?;
|
throw_ub_format!("incorrect number of arguments for fcntl: got {}, expected at least 2", args.len());
|
||||||
(fd, cmd, None)
|
}
|
||||||
} else {
|
let cmd = this.read_scalar(args[1])?.to_i32()?;
|
||||||
// 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()?;
|
|
||||||
// We only support getting the flags for a descriptor.
|
// We only support getting the flags for a descriptor.
|
||||||
if cmd == this.eval_libc_i32("F_GETFD")? {
|
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
|
// 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`
|
// `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
|
// always sets this flag when opening a file. However we still need to check that the
|
||||||
// file itself is open.
|
// 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) {
|
if this.machine.file_handler.handles.contains_key(&fd) {
|
||||||
Ok(this.eval_libc_i32("FD_CLOEXEC")?)
|
Ok(this.eval_libc_i32("FD_CLOEXEC")?)
|
||||||
} else {
|
} else {
|
||||||
@ -356,15 +352,12 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
|||||||
// because exec() isn't supported. The F_DUPFD and F_DUPFD_CLOEXEC commands only
|
// 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,
|
// differ in whether the FD_CLOEXEC flag is pre-set on the new file descriptor,
|
||||||
// thus they can share the same implementation here.
|
// 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 {
|
if fd < MIN_NORMAL_FILE_FD {
|
||||||
throw_unsup_format!("duplicating file descriptors for stdin, stdout, or stderr is not supported")
|
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 fh = &mut this.machine.file_handler;
|
||||||
let (file_result, writable) = match fh.handles.get(&fd) {
|
let (file_result, writable) = match fh.handles.get(&fd) {
|
||||||
Some(FileHandle { file, writable }) => (file.try_clone(), *writable),
|
Some(FileHandle { file, writable }) => (file.try_clone(), *writable),
|
||||||
|
@ -121,12 +121,12 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
|
|||||||
|
|
||||||
fn pthread_setname_np(
|
fn pthread_setname_np(
|
||||||
&mut self,
|
&mut self,
|
||||||
ptr: Scalar<Tag>,
|
name: Scalar<Tag>,
|
||||||
) -> InterpResult<'tcx> {
|
) -> InterpResult<'tcx> {
|
||||||
let this = self.eval_context_mut();
|
let this = self.eval_context_mut();
|
||||||
this.assert_target_os("macos", "pthread_setname_np");
|
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)?;
|
this.set_active_thread_name(name)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user