#[repr(u16)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum KernelOp {
MapAnonymous = 0x0001,
Munmap = 0x0002,
Mprotect = 0x0003,
ReadUser = 0x0004,
WriteUser = 0x0005,
Yield = 0x0100,
BlockThread = 0x0101,
ThreadCreate = 0x0102,
ThreadExit = 0x0103,
FutexWake = 0x0104,
GetTimeNs = 0x0200,
GetRandom = 0x0201,
VfsOpen = 0x0400,
VfsRead = 0x0401,
VfsWrite = 0x0402,
VfsStat = 0x0403,
VfsClose = 0x0404,
VfsSeek = 0x0405,
VfsTruncate = 0x0406,
VfsSync = 0x0407,
NetConnect = 0x0500,
NetListen = 0x0501,
NetAccept = 0x0502,
NetSend = 0x0503,
NetRecv = 0x0504,
NetClose = 0x0505,
NetUdpBind = 0x0510,
NetUdpSend = 0x0511,
NetUdpRecv = 0x0512,
SendSignal = 0x0600,
CheckSignals = 0x0601,
DebugPrint = 0x0F00,
DomainExit = 0x1000,
GetDomainId = 0x1001,
GetParentId = 0x1002,
}
impl KernelOp {
pub fn from_u16(value: u16) -> Option<Self> {
match value {
0x0001 => Some(Self::MapAnonymous),
0x0002 => Some(Self::Munmap),
0x0003 => Some(Self::Mprotect),
0x0004 => Some(Self::ReadUser),
0x0005 => Some(Self::WriteUser),
0x0100 => Some(Self::Yield),
0x0101 => Some(Self::BlockThread),
0x0102 => Some(Self::ThreadCreate),
0x0103 => Some(Self::ThreadExit),
0x0104 => Some(Self::FutexWake),
0x0200 => Some(Self::GetTimeNs),
0x0201 => Some(Self::GetRandom),
0x0400 => Some(Self::VfsOpen),
0x0401 => Some(Self::VfsRead),
0x0402 => Some(Self::VfsWrite),
0x0403 => Some(Self::VfsStat),
0x0404 => Some(Self::VfsClose),
0x0405 => Some(Self::VfsSeek),
0x0406 => Some(Self::VfsTruncate),
0x0407 => Some(Self::VfsSync),
0x0500 => Some(Self::NetConnect),
0x0501 => Some(Self::NetListen),
0x0502 => Some(Self::NetAccept),
0x0503 => Some(Self::NetSend),
0x0504 => Some(Self::NetRecv),
0x0505 => Some(Self::NetClose),
0x0510 => Some(Self::NetUdpBind),
0x0511 => Some(Self::NetUdpSend),
0x0512 => Some(Self::NetUdpRecv),
0x0600 => Some(Self::SendSignal),
0x0601 => Some(Self::CheckSignals),
0x0F00 => Some(Self::DebugPrint),
0x1000 => Some(Self::DomainExit),
0x1001 => Some(Self::GetDomainId),
0x1002 => Some(Self::GetParentId),
_ => None,
}
}
pub const fn name(&self) -> &'static str {
match self {
Self::MapAnonymous => "MapAnonymous",
Self::Munmap => "Munmap",
Self::Mprotect => "Mprotect",
Self::ReadUser => "ReadUser",
Self::WriteUser => "WriteUser",
Self::Yield => "Yield",
Self::BlockThread => "BlockThread",
Self::ThreadCreate => "ThreadCreate",
Self::ThreadExit => "ThreadExit",
Self::FutexWake => "FutexWake",
Self::GetTimeNs => "GetTimeNs",
Self::GetRandom => "GetRandom",
Self::VfsOpen => "VfsOpen",
Self::VfsRead => "VfsRead",
Self::VfsWrite => "VfsWrite",
Self::VfsStat => "VfsStat",
Self::VfsClose => "VfsClose",
Self::VfsSeek => "VfsSeek",
Self::VfsTruncate => "VfsTruncate",
Self::VfsSync => "VfsSync",
Self::NetConnect => "NetConnect",
Self::NetListen => "NetListen",
Self::NetAccept => "NetAccept",
Self::NetSend => "NetSend",
Self::NetRecv => "NetRecv",
Self::NetClose => "NetClose",
Self::NetUdpBind => "NetUdpBind",
Self::NetUdpSend => "NetUdpSend",
Self::NetUdpRecv => "NetUdpRecv",
Self::SendSignal => "SendSignal",
Self::CheckSignals => "CheckSignals",
Self::DebugPrint => "DebugPrint",
Self::DomainExit => "DomainExit",
Self::GetDomainId => "GetDomainId",
Self::GetParentId => "GetParentId",
}
}
pub const fn is_nonblocking(&self) -> bool {
match self {
Self::BlockThread | Self::ThreadExit | Self::DomainExit => false,
_ => true,
}
}
}
pub mod prot {
pub const NONE: u32 = 0;
pub const READ: u32 = 1;
pub const WRITE: u32 = 2;
pub const EXEC: u32 = 4;
}
pub mod map {
pub const FIXED: u32 = 1;
pub const POPULATE: u32 = 2;
}
pub mod open {
pub const RDONLY: u32 = 0;
pub const WRONLY: u32 = 1;
pub const RDWR: u32 = 2;
pub const CREAT: u32 = 0x40;
pub const EXCL: u32 = 0x80;
pub const TRUNC: u32 = 0x200;
pub const APPEND: u32 = 0x400;
pub const NONBLOCK: u32 = 0x800;
pub const DIRECTORY: u32 = 0x10000;
pub const CLOEXEC: u32 = 0x80000;
}
pub mod seek {
pub const SET: u32 = 0;
pub const CUR: u32 = 1;
pub const END: u32 = 2;
}
pub mod clock {
pub const REALTIME: u32 = 0;
pub const MONOTONIC: u32 = 1;
}
pub const SYS_SUBMIT: u64 = 500;
pub const MAX_SUBMIT_COUNT: u32 = 64;