Skip to content

Commit

Permalink
move linux specific functions
Browse files Browse the repository at this point in the history
  • Loading branch information
DebugSteven committed Oct 16, 2022
1 parent 8f87eff commit f325776
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 51 deletions.
34 changes: 0 additions & 34 deletions src/shims/unix/foreign_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down
15 changes: 6 additions & 9 deletions src/shims/unix/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down Expand Up @@ -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)
}
Expand Down
36 changes: 36 additions & 0 deletions src/shims/unix/linux/foreign_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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" => {
Expand Down
3 changes: 3 additions & 0 deletions src/shims/unix/linux/fs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub mod epoll;
pub mod event;
pub mod socketpair;
Original file line number Diff line number Diff line change
@@ -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<i32, EpollEvent>,
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use super::{FileDescriptor, InterpResult};
use crate::shims::unix::fs::FileDescriptor;

use rustc_const_eval::interpret::InterpResult;

use std::io;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::*;

use super::FileDescriptor;
use crate::shims::unix::fs::FileDescriptor;

use std::io;

Expand Down
1 change: 1 addition & 0 deletions src/shims/unix/linux/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod dlsym;
pub mod foreign_items;
pub mod fs;
pub mod sync;
Original file line number Diff line number Diff line change
@@ -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]
Expand Down

0 comments on commit f325776

Please sign in to comment.