Refactor syscall- and fs-related code into modules

This commit is contained in:
Tate, Hongliang Tian 2018-12-18 14:40:41 +08:00
parent 0cda8dffe7
commit 8601c5da35
11 changed files with 24 additions and 25 deletions

@ -1,9 +1,8 @@
use prelude::*;
use super::*;
use {std};
use std::{fmt};
use std::borrow::BorrowMut;
use std::sgxfs as fs_impl;
pub trait File : Debug + Sync + Send {
fn read(&self, buf: &mut [u8]) -> Result<usize, Error>;

@ -1,6 +1,6 @@
use prelude::*;
use {std, file};
use file::{File, FileRef};
use super::*;
use super::file::{File, FileRef};
use {std};
pub type FileDesc = u32;

@ -1,10 +1,14 @@
use super::*;
use prelude::*;
use {std, file, file_table, process};
use file::{File, SgxFile};
use file_table::{FileDesc};
use {std, process};
use std::sgxfs as fs_impl;
mod file;
mod file_table;
pub use self::file::{File, FileRef, SgxFile, StdinFile, StdoutFile};
pub use self::file_table::{FileDesc, FileTable};
pub const O_RDONLY : u32 = 0x00000000;
pub const O_WRONLY : u32 = 0x00000001;
pub const O_RDWR : u32 = 0x00000002;

@ -28,8 +28,6 @@ use sgx_trts::libc;
#[macro_use]
mod prelude;
mod errno;
mod file;
mod file_table;
mod fs;
mod process;
mod syscall;

@ -1,8 +1,7 @@
use super::*;
use super::task::{Task};
use vm::{ProcessVM, VMRangeTrait};
use file_table::{FileTable};
use file::{File, FileRef,};
use fs::{FileTable, File, FileRef};
#[allow(non_camel_case_types)]
pub type pid_t = u32;

@ -1,6 +1,5 @@
use super::*;
use file::{File, StdinFile, StdoutFile/*, StderrFile*/};
use file_table::{FileTable};
use fs::{File, StdinFile, StdoutFile/*, StderrFile*/, FileTable};
use std::path::Path;
use std::ffi::{CStr, CString};
use std::sgxfs::SgxFile;

@ -1,7 +1,8 @@
use super::*;
use prelude::*;
use {std, file, file_table, fs, process, vm};
use {std, fs, process, vm};
use std::ffi::{CStr, CString};
use fs::{off_t};
use fs::{off_t, FileDesc};
use vm::{VMAreaFlags, VMResizeOptions};
// Use the internal syscall wrappers from sgx_tstd
//use std::libc_fs as fs;
@ -50,7 +51,7 @@ fn clone_cstrings_from_user_safely(user_ptr: *const *const c_char)
fn do_read(fd: c_int, buf: *mut c_void, size: size_t)
-> Result<size_t, Error>
{
let fd = fd as file_table::FileDesc;
let fd = fd as FileDesc;
let safe_buf = {
let buf = buf as *mut u8;
let size = size as usize;
@ -63,7 +64,7 @@ fn do_read(fd: c_int, buf: *mut c_void, size: size_t)
fn do_write(fd: c_int, buf: *const c_void, size: size_t)
-> Result<size_t, Error>
{
let fd = fd as file_table::FileDesc;
let fd = fd as FileDesc;
let safe_buf = {
let buf = buf as *mut u8;
let size = size as usize;
@ -76,7 +77,7 @@ fn do_write(fd: c_int, buf: *const c_void, size: size_t)
fn do_writev(fd: c_int, iov: *const iovec_t, count: c_int)
-> Result<size_t, Error>
{
let fd = fd as file_table::FileDesc;
let fd = fd as FileDesc;
let count = {
if count < 0 {
@ -106,7 +107,7 @@ fn do_writev(fd: c_int, iov: *const iovec_t, count: c_int)
fn do_readv(fd: c_int, iov: *mut iovec_t, count: c_int)
-> Result<size_t, Error>
{
let fd = fd as file_table::FileDesc;
let fd = fd as FileDesc;
let count = {
if count < 0 {
@ -137,7 +138,7 @@ fn do_readv(fd: c_int, iov: *mut iovec_t, count: c_int)
pub fn do_lseek(fd: c_int, offset: off_t, whence: c_int) -> Result<off_t, Error>
{
let fd = fd as file_table::FileDesc;
let fd = fd as FileDesc;
let seek_from = match whence {
0 => { // SEEK_SET
@ -252,7 +253,7 @@ pub extern "C" fn occlum_open(path_buf: * const c_char, flags: c_int, mode: c_in
#[no_mangle]
pub extern "C" fn occlum_close(fd: c_int) -> c_int {
match fs::do_close(fd as file_table::FileDesc) {
match fs::do_close(fd as FileDesc) {
Ok(()) => {
0
},

@ -1,7 +1,6 @@
use prelude::*;
use std::{fmt};
use file_table::{FileDesc};
use fs::{off_t};
use fs::{off_t, FileDesc};
use process::{Process, ProcessRef, get_current};
// TODO: Rename VMSpace to VMUniverse