From f325776e9ce9cf4066245290d22521a3ec0969f8 Mon Sep 17 00:00:00 2001 From: DebugSteven Date: Mon, 10 Oct 2022 10:29:59 -0600 Subject: [PATCH] move linux specific functions --- src/shims/unix/foreign_items.rs | 34 ------------------ src/shims/unix/fs.rs | 15 ++++---- src/shims/unix/linux/foreign_items.rs | 36 ++++++++++++++++++++ src/shims/unix/linux/fs.rs | 3 ++ src/shims/unix/{ => linux}/fs/epoll.rs | 5 +-- src/shims/unix/{ => linux}/fs/event.rs | 4 ++- src/shims/unix/{ => linux}/fs/socketpair.rs | 2 +- src/shims/unix/linux/mod.rs | 1 + tests/{fail/crates => pass-dep}/tokio_mvp.rs | 2 -- 9 files changed, 51 insertions(+), 51 deletions(-) create mode 100644 src/shims/unix/linux/fs.rs rename src/shims/unix/{ => linux}/fs/epoll.rs (82%) rename src/shims/unix/{ => linux}/fs/event.rs (87%) rename src/shims/unix/{ => linux}/fs/socketpair.rs (90%) rename tests/{fail/crates => pass-dep}/tokio_mvp.rs (59%) diff --git a/src/shims/unix/foreign_items.rs b/src/shims/unix/foreign_items.rs index 650dde0313..c21e0441ca 100644 --- a/src/shims/unix/foreign_items.rs +++ b/src/shims/unix/foreign_items.rs @@ -62,40 +62,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> { let result = this.open(args)?; this.write_scalar(Scalar::from_i32(result), dest)?; } - "epoll_create1" => { - let [flag] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; - let result = this.epoll_create1(flag)?; - this.write_scalar(Scalar::from_i32(result), dest)?; - } - "epoll_ctl" => { - let [epfd, op, fd, event] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; - let result = this.epoll_ctl(epfd, op, fd, event)?; - this.write_scalar(Scalar::from_i32(result), dest)?; - } - "epoll_wait" => { - let [epfd, events, maxevents, timeout] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; - let result = this.epoll_wait(epfd, events, maxevents, timeout)?; - this.write_scalar(Scalar::from_i32(result), dest)?; - } - "eventfd" => { - let [val, flag] = - this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; - let result = this.eventfd(val, flag)?; - this.write_scalar(Scalar::from_i32(result), dest)?; - } - "socketpair" => { - let [domain, type_, protocol, sv] = this.check_shim(abi, Abi::C {unwind: false}, link_name, args)?; - - let result = this.socketpair(domain, type_, protocol, sv)?; - this.write_scalar(Scalar::from_i32(result), dest)?; - } - "__libc_current_sigrtmax" => { - // TODO this function takes `void`. does anything go in this let? - let [] = this.check_shim(abi, Abi::C {unwind: false}, link_name, args)?; - - let result = this.libc_current_sigrtmax()?; - this.write_scalar(Scalar::from_i32(result), dest)?; - } "close" => { let [fd] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let result = this.close(fd)?; diff --git a/src/shims/unix/fs.rs b/src/shims/unix/fs.rs index 5953827962..a1de23c152 100644 --- a/src/shims/unix/fs.rs +++ b/src/shims/unix/fs.rs @@ -16,23 +16,19 @@ use rustc_target::abi::{Align, Size}; use crate::shims::os_str::bytes_to_os_str; use crate::*; -use epoll::{Epoll, EpollEvent}; -use event::Event; use shims::os_str::os_str_to_bytes; use shims::time::system_time_to_duration; -use socketpair::SocketPair; - -mod epoll; -mod event; -mod socketpair; +use shims::unix::linux::fs::epoll::{Epoll, EpollEvent}; +use shims::unix::linux::fs::event::Event; +use shims::unix::linux::fs::socketpair::SocketPair; #[derive(Debug)] -struct FileHandle { +pub struct FileHandle { file: File, writable: bool, } -trait FileDescriptor: std::fmt::Debug { +pub trait FileDescriptor: std::fmt::Debug { fn name(&self) -> &'static str; fn as_file_handle<'tcx>(&self) -> InterpResult<'tcx, &FileHandle> { @@ -724,6 +720,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> { } let fh = &mut this.machine.file_handler; + #[allow(clippy::box_default)] let fd = fh.insert_fd(Box::new(Epoll::default())); Ok(fd) } diff --git a/src/shims/unix/linux/foreign_items.rs b/src/shims/unix/linux/foreign_items.rs index 5d000f9d12..990a6e93a1 100644 --- a/src/shims/unix/linux/foreign_items.rs +++ b/src/shims/unix/linux/foreign_items.rs @@ -42,6 +42,42 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> { let result = this.sync_file_range(fd, offset, nbytes, flags)?; this.write_scalar(result, dest)?; } + "epoll_create1" => { + let [flag] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; + let result = this.epoll_create1(flag)?; + this.write_scalar(Scalar::from_i32(result), dest)?; + } + "epoll_ctl" => { + let [epfd, op, fd, event] = + this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; + let result = this.epoll_ctl(epfd, op, fd, event)?; + this.write_scalar(Scalar::from_i32(result), dest)?; + } + "epoll_wait" => { + let [epfd, events, maxevents, timeout] = + this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; + let result = this.epoll_wait(epfd, events, maxevents, timeout)?; + this.write_scalar(Scalar::from_i32(result), dest)?; + } + "eventfd" => { + let [val, flag] = + this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; + let result = this.eventfd(val, flag)?; + this.write_scalar(Scalar::from_i32(result), dest)?; + } + "socketpair" => { + let [domain, type_, protocol, sv] = + this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; + + let result = this.socketpair(domain, type_, protocol, sv)?; + this.write_scalar(Scalar::from_i32(result), dest)?; + } + "__libc_current_sigrtmax" => { + let [] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; + + let result = this.libc_current_sigrtmax()?; + this.write_scalar(Scalar::from_i32(result), dest)?; + } // Time related shims "clock_gettime" => { diff --git a/src/shims/unix/linux/fs.rs b/src/shims/unix/linux/fs.rs new file mode 100644 index 0000000000..15bfd17456 --- /dev/null +++ b/src/shims/unix/linux/fs.rs @@ -0,0 +1,3 @@ +pub mod epoll; +pub mod event; +pub mod socketpair; diff --git a/src/shims/unix/fs/epoll.rs b/src/shims/unix/linux/fs/epoll.rs similarity index 82% rename from src/shims/unix/fs/epoll.rs rename to src/shims/unix/linux/fs/epoll.rs index 09183ae9f7..d72b720eff 100644 --- a/src/shims/unix/fs/epoll.rs +++ b/src/shims/unix/linux/fs/epoll.rs @@ -1,15 +1,12 @@ -// use crate::shims::unix::fs::FileDescriptor; -// use crate::shims::unix::fs::SeekFrom; use crate::*; -use super::FileDescriptor; +use crate::shims::unix::fs::FileDescriptor; use rustc_data_structures::fx::FxHashMap; use std::io; #[derive(Clone, Debug, Default)] pub struct Epoll { - // should () be the epoll_event struct? pub file_descriptors: FxHashMap, } diff --git a/src/shims/unix/fs/event.rs b/src/shims/unix/linux/fs/event.rs similarity index 87% rename from src/shims/unix/fs/event.rs rename to src/shims/unix/linux/fs/event.rs index 9564bd3b2a..c4d09656ea 100644 --- a/src/shims/unix/fs/event.rs +++ b/src/shims/unix/linux/fs/event.rs @@ -1,4 +1,6 @@ -use super::{FileDescriptor, InterpResult}; +use crate::shims::unix::fs::FileDescriptor; + +use rustc_const_eval::interpret::InterpResult; use std::io; diff --git a/src/shims/unix/fs/socketpair.rs b/src/shims/unix/linux/fs/socketpair.rs similarity index 90% rename from src/shims/unix/fs/socketpair.rs rename to src/shims/unix/linux/fs/socketpair.rs index 0bd8453148..f31a7760ba 100644 --- a/src/shims/unix/fs/socketpair.rs +++ b/src/shims/unix/linux/fs/socketpair.rs @@ -1,6 +1,6 @@ use crate::*; -use super::FileDescriptor; +use crate::shims::unix::fs::FileDescriptor; use std::io; diff --git a/src/shims/unix/linux/mod.rs b/src/shims/unix/linux/mod.rs index 498eb57c57..162dfd0e11 100644 --- a/src/shims/unix/linux/mod.rs +++ b/src/shims/unix/linux/mod.rs @@ -1,3 +1,4 @@ pub mod dlsym; pub mod foreign_items; +pub mod fs; pub mod sync; diff --git a/tests/fail/crates/tokio_mvp.rs b/tests/pass-dep/tokio_mvp.rs similarity index 59% rename from tests/fail/crates/tokio_mvp.rs rename to tests/pass-dep/tokio_mvp.rs index 8ea803336b..7b73fc6d99 100644 --- a/tests/fail/crates/tokio_mvp.rs +++ b/tests/pass-dep/tokio_mvp.rs @@ -1,6 +1,4 @@ //@compile-flags: -Zmiri-disable-isolation -Zmiri-permissive-provenance -//@error-pattern: unsupported operation: failed to add event -//@normalize-stderr-test: " = note: inside .*\n" -> "" //@only-target-linux: the errors differ too much between platforms #[tokio::main]