Skip to content

Commit

Permalink
update doc for linux-object
Browse files Browse the repository at this point in the history
yunwei37 committed Aug 12, 2020
1 parent 73e4872 commit fe92881
Showing 5 changed files with 73 additions and 5 deletions.
57 changes: 54 additions & 3 deletions linux-object/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,64 +1,115 @@
//! Linux error flags
//! Linux error codes
use core::fmt;
use rcore_fs::vfs::FsError;
use zircon_object::ZxError;

/// Linux Result defination
pub type LxResult<T = ()> = Result<T, LxError>;
/// SysResult Result defination (same as Linux Result)
pub type SysResult = LxResult<usize>;

/// Linux error flag defination
/// Linux error codes defination
#[allow(dead_code)]
#[repr(isize)]
#[derive(Debug)]
pub enum LxError {
/// Undefined
EUNDEF = 0,
/// Operation not permitted
EPERM = 1,
/// No such file or directory
ENOENT = 2,
/// No such process
ESRCH = 3,
/// Interrupted system call
EINTR = 4,
/// I/O error
EIO = 5,
/// No such device or address
ENXIO = 6,
/// Arg list too long
E2BIG = 7,
/// Exec format error
ENOEXEC = 8,
/// Bad file number
EBADF = 9,
/// No child processes
ECHILD = 10,
/// Try again
EAGAIN = 11,
/// Out of memory
ENOMEM = 12,
/// Permission denied
EACCES = 13,
/// Bad address
EFAULT = 14,
/// Block device required
ENOTBLK = 15,
/// Device or resource busy
EBUSY = 16,
/// File exists
EEXIST = 17,
/// Cross-device link
EXDEV = 18,
/// No such device
ENODEV = 19,
/// Not a directory
ENOTDIR = 20,
/// Is a directory
EISDIR = 21,
/// Invalid argument
EINVAL = 22,
/// File table overflow
ENFILE = 23,
/// Too many open files
EMFILE = 24,
/// Not a tty device
ENOTTY = 25,
/// Text file busy
ETXTBSY = 26,
/// File too large
EFBIG = 27,
/// No space left on device
ENOSPC = 28,
/// Illegal seek
ESPIPE = 29,
/// Read-only file system
EROFS = 30,
/// Too many links
EMLINK = 31,
/// Broken pipe
EPIPE = 32,
/// Math argument out of domain
EDOM = 33,
/// Math result not representable
ERANGE = 34,
/// Resource deadlock would occur
EDEADLK = 35,
/// Filename too long
ENAMETOOLONG = 36,
/// No record locks available
ENOLCK = 37,
/// Function not implemented
ENOSYS = 38,
/// Directory not empty
ENOTEMPTY = 39,
/// Too many symbolic links encountered
ELOOP = 40,
ENOTSOCK = 80,
/// Socket operation on non-socket
ENOTSOCK = 88,
/// Protocol not available
ENOPROTOOPT = 92,
/// Protocol family not supported
EPFNOSUPPORT = 96,
/// Address family not supported by protocol
EAFNOSUPPORT = 97,
/// No buffer space available
ENOBUFS = 105,
/// Transport endpoint is already connected
EISCONN = 106,
/// Transport endpoint is not connected
ENOTCONN = 107,
/// Connection refused
ECONNREFUSED = 111,
}

2 changes: 1 addition & 1 deletion linux-object/src/fs/file.rs
Original file line number Diff line number Diff line change
@@ -49,7 +49,7 @@ pub struct OpenOptions {
/// file seek type
#[derive(Debug)]
pub enum SeekFrom {
/// seek from start point
/// seek from start point
Start(u64),
/// seek from end
End(i64),
8 changes: 7 additions & 1 deletion linux-object/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
//! Linux kernel objects
#![no_std]
#![deny(warnings, unsafe_code, unused_must_use, unreachable_patterns)]
#![deny(
warnings,
unsafe_code,
unused_must_use,
unreachable_patterns,
missing_docs
)]
#![feature(bool_to_option)]

extern crate alloc;
6 changes: 6 additions & 0 deletions linux-object/src/process.rs
Original file line number Diff line number Diff line change
@@ -20,9 +20,13 @@ use zircon_object::{
ZxResult,
};

/// Process extension for linux
pub trait ProcessExt {
/// create Linux process
fn create_linux(job: &Arc<Job>, rootfs: Arc<dyn FileSystem>) -> ZxResult<Arc<Self>>;
/// get linux process
fn linux(&self) -> &LinuxProcess;
/// fork from current linux process
fn fork_from(parent: &Arc<Self>, vfork: bool) -> ZxResult<Arc<Self>>;
}

@@ -128,6 +132,7 @@ pub struct LinuxProcess {
inner: Mutex<LinuxProcessInner>,
}

/// Linux process mut inner data
#[derive(Default)]
struct LinuxProcessInner {
/// Execute path
@@ -144,6 +149,7 @@ struct LinuxProcessInner {
children: HashMap<KoID, Arc<Process>>,
}

/// process exit code defination
pub type ExitCode = i32;

impl LinuxProcess {
5 changes: 5 additions & 0 deletions linux-object/src/thread.rs
Original file line number Diff line number Diff line change
@@ -8,10 +8,15 @@ use spin::{Mutex, MutexGuard};
use zircon_object::task::{Process, Thread};
use zircon_object::ZxResult;

/// Thread extension for linux
pub trait ThreadExt {
/// create linux thread
fn create_linux(proc: &Arc<Process>) -> ZxResult<Arc<Self>>;
/// lock and get Linux thread
fn lock_linux(&self) -> MutexGuard<'_, LinuxThread>;
/// Set pointer to thread ID.
fn set_tid_address(&self, tidptr: UserOutPtr<i32>);
/// exit linux thread
fn exit_linux(&self, exit_code: i32);
}

0 comments on commit fe92881

Please sign in to comment.