From ef9e7ad5581ffdba3fe60e5cd9a910b91eed3062 Mon Sep 17 00:00:00 2001 From: Chinmay Shringi Date: Mon, 25 Nov 2024 17:42:35 -0500 Subject: [PATCH] feat: new constants folder --- src/RawPOSIX/src/constants/fs_constants.rs | 202 +++++++++ src/RawPOSIX/src/constants/mod.rs | 7 + src/RawPOSIX/src/constants/net_constants.rs | 371 +++++++++++++++++ src/RawPOSIX/src/constants/sys_constants.rs | 97 +++++ src/RawPOSIX/src/interface/misc.rs | 2 +- src/RawPOSIX/src/lib.rs | 1 + src/RawPOSIX/src/safeposix/cage.rs | 16 +- src/RawPOSIX/src/safeposix/dispatcher.rs | 5 +- src/RawPOSIX/src/safeposix/mod.rs | 2 +- src/RawPOSIX/src/safeposix/shm.rs | 10 +- .../src/safeposix/syscalls/fs_calls.rs | 23 +- .../src/safeposix/syscalls/fs_constants.rs | 196 --------- src/RawPOSIX/src/safeposix/syscalls/mod.rs | 6 - .../src/safeposix/syscalls/net_calls.rs | 4 +- .../src/safeposix/syscalls/net_constants.rs | 392 ------------------ .../src/safeposix/syscalls/sys_calls.rs | 31 +- .../src/safeposix/syscalls/sys_constants.rs | 77 ---- src/RawPOSIX/src/safeposix/vmmap.rs | 8 +- src/RawPOSIX/src/safeposix/vmmap_constants.rs | 32 -- src/RawPOSIX/src/tests/sys_tests.rs | 1 + 20 files changed, 747 insertions(+), 736 deletions(-) create mode 100644 src/RawPOSIX/src/constants/fs_constants.rs create mode 100644 src/RawPOSIX/src/constants/mod.rs create mode 100644 src/RawPOSIX/src/constants/net_constants.rs create mode 100644 src/RawPOSIX/src/constants/sys_constants.rs delete mode 100644 src/RawPOSIX/src/safeposix/syscalls/fs_constants.rs delete mode 100644 src/RawPOSIX/src/safeposix/syscalls/net_constants.rs delete mode 100644 src/RawPOSIX/src/safeposix/syscalls/sys_constants.rs delete mode 100644 src/RawPOSIX/src/safeposix/vmmap_constants.rs diff --git a/src/RawPOSIX/src/constants/fs_constants.rs b/src/RawPOSIX/src/constants/fs_constants.rs new file mode 100644 index 00000000..79a1cf04 --- /dev/null +++ b/src/RawPOSIX/src/constants/fs_constants.rs @@ -0,0 +1,202 @@ +//! File System Constants Module +//! These constants define file system-related flags and parameters +//! +//! Primary Source References: +//! - Linux kernel v6.5: include/uapi/asm-generic/fcntl.h +//! - Linux kernel v6.5: include/uapi/linux/stat.h +//! - POSIX.1-2017 (IEEE Std 1003.1-2017) + +#![allow(dead_code)] +#![allow(unused_variables)] + +use crate::interface; + +// ===== File Descriptor Constants ===== +pub const DT_UNKNOWN: u8 = 0; + +pub const STARTINGFD: i32 = 0; // Starting file descriptor number +pub const MAXFD: i32 = 1024; // Maximum number of file descriptors +pub const STARTINGPIPE: i32 = 0; // Starting pipe descriptor number +pub const MAXPIPE: i32 = 1024; // Maximum number of pipes + +// ===== Inode Constants ===== +pub const ROOTDIRECTORYINODE: usize = 1; // Root directory inode number +pub const STREAMINODE: usize = 2; // Stream inode number + +// ===== Pipe Constants ===== +pub const PIPE_CAPACITY: usize = 65536; // Maximum pipe buffer size + +// ===== File Access Permission Flags ===== +pub const F_OK: u32 = 0; // Test for existence +pub const X_OK: u32 = 1; // Test for execute permission +pub const W_OK: u32 = 2; // Test for write permission +pub const R_OK: u32 = 4; // Test for read permission + +// ===== File Access Modes ===== +// Source: include/uapi/asm-generic/fcntl.h +pub const O_RDONLY: i32 = 0o0; // Open read-only +pub const O_WRONLY: i32 = 0o1; // Open write-only +pub const O_RDWR: i32 = 0o2; // Open read-write +pub const O_RDWRFLAGS: i32 = 0o3; // Mask for access modes + +// ===== File Creation and Status Flags ===== +pub const O_CREAT: i32 = 0o100; // Create file if it doesn't exist +pub const O_EXCL: i32 = 0o200; // Error if O_CREAT and file exists +pub const O_NOCTTY: i32 = 0o400; // Don't assign controlling terminal +pub const O_TRUNC: i32 = 0o1000; // Truncate file to zero length +pub const O_APPEND: i32 = 0o2000; // Append mode - writes always at end +pub const O_NONBLOCK: i32 = 0o4000; // Non-blocking mode +// O_NDELAY=O_NONBLOCK +pub const O_SYNC: i32 = 0o10000; // Synchronous writes +// O_FSYNC=O_SYNC +pub const O_ASYNC: i32 = 0o20000; // Signal-driven I/O +pub const O_CLOEXEC: i32 = 0o2000000; // Close on exec + +pub const DEFAULTTIME: u64 = 1323630836; // Default timestamp value + +// ===== File Permissions ===== +// Source: include/uapi/linux/stat.h +pub const S_IRWXA: u32 = 0o777; // All permissions for all users +pub const S_IRWXU: u32 = 0o700; // User read, write, execute +pub const S_IRUSR: u32 = 0o400; // User read +pub const S_IWUSR: u32 = 0o200; // User write +pub const S_IXUSR: u32 = 0o100; // User execute +pub const S_IRWXG: u32 = 0o070; // Group read, write, execute +pub const S_IRGRP: u32 = 0o040; // Group read +pub const S_IWGRP: u32 = 0o020; // Group write +pub const S_IXGRP: u32 = 0o010; // Group execute +pub const S_IRWXO: u32 = 0o007; // Others read, write, execute +pub const S_IROTH: u32 = 0o004; // Others read +pub const S_IWOTH: u32 = 0o002; // Others write +pub const S_IXOTH: u32 = 0o001; // Others execute + +//Commands for FCNTL +pub const F_DUPFD: i32 = 0; +pub const F_GETFD: i32 = 1; +pub const F_SETFD: i32 = 2; +pub const F_GETFL: i32 = 3; +pub const F_SETFL: i32 = 4; +pub const F_GETLK: i32 = 5; +pub const F_GETLK64: i32 = 5; +pub const F_SETLK: i32 = 6; +pub const F_SETLK64: i32 = 6; +pub const F_SETLKW: i32 = 7; +pub const F_SETLKW64: i32 = 7; +pub const F_SETOWN: i32 = 8; +pub const F_GETOWN: i32 = 9; +pub const F_SETSIG: i32 = 10; +pub const F_GETSIG: i32 = 11; +pub const F_SETLEASE: i32 = 1024; +pub const F_GETLEASE: i32 = 1025; +pub const F_NOTIFY: i32 = 1026; + +//Commands for IOCTL +pub const FIONBIO: u32 = 21537; +pub const FIOASYNC: u32 = 21586; + +//File types for open/stat etc. +pub const S_IFBLK: i32 = 0o60000; +pub const S_IFCHR: i32 = 0o20000; +pub const S_IFDIR: i32 = 0o40000; +pub const S_IFIFO: i32 = 0o10000; +pub const S_IFLNK: i32 = 0o120000; +pub const S_IFREG: i32 = 0o100000; +pub const S_IFSOCK: i32 = 0o140000; +pub const S_FILETYPEFLAGS: i32 = 0o170000; + +//for flock syscall +pub const LOCK_SH: i32 = 1; +pub const LOCK_EX: i32 = 2; +pub const LOCK_UN: i32 = 8; +pub const LOCK_NB: i32 = 4; +//for mmap/munmap syscall +pub const MAP_SHARED: i32 = 1; +pub const MAP_PRIVATE: i32 = 2; +pub const MAP_FIXED: i32 = 16; +pub const MAP_ANONYMOUS: i32 = 32; +pub const MAP_HUGE_SHIFT: i32 = 26; +pub const MAP_HUGETLB: i32 = 262144; + +pub const PROT_NONE: i32 = 0; +pub const PROT_READ: i32 = 1; +pub const PROT_WRITE: i32 = 2; +pub const PROT_EXEC: i32 = 4; + +pub const SEEK_SET: i32 = 0; // Seek from beginning of file +pub const SEEK_CUR: i32 = 1; // Seek from current position +pub const SEEK_END: i32 = 2; // Seek from end of file + +pub const IPC_PRIVATE: i32 = 0o0; +pub const IPC_CREAT: i32 = 0o1000; +pub const IPC_EXCL: i32 = 0o2000; + +pub const IPC_RMID: i32 = 0; +pub const IPC_SET: i32 = 1; +pub const IPC_STAT: i32 = 2; + +pub const SHM_DEST: i32 = 0o1000; // Destroy segment when last process detaches +pub const SHM_LOCKED: i32 = 0o2000; // Lock segment in memory +pub const SHM_HUGETLB: i32 = 0o4000; // Use huge TLB pages + +pub const SHM_R: i32 = 0o400; // Read permission +pub const SHM_W: i32 = 0o200; // Write permission +pub const SHM_RDONLY: i32 = 0o10000; // Read-only access +pub const SHM_RND: i32 = 0o20000; // Round attach address to SHMLBA +pub const SHM_REMAP: i32 = 0o40000; // Take-over region on attach +pub const SHM_EXEC: i32 = 0o100000; // Execute permission + +pub const SHMMIN: u32 = 1; // Minimum shared memory segment size +pub const SHMMNI: u32 = 4096; // Maximum number of segments system wide +pub const SHMMAX: u32 = 4278190079; // Maximum shared memory segment size +pub const SHMALL: u32 = 4278190079; // Maximum total shared memory system wide +pub const SHMSEG: u32 = SHMMNI; // Maximum segments per process + +pub const SEM_VALUE_MAX: u32 = 2147483647; // Maximum value for a semaphore + +// ===== Memory Protection Flags ===== +// Source: include/uapi/asm-generic/mman-common.h +pub const PROT_NONE: i32 = 0x0; // Page cannot be accessed +pub const PROT_READ: i32 = 0x1; // Page can be read +pub const PROT_WRITE: i32 = 0x2; // Page can be written +pub const PROT_EXEC: i32 = 0x4; // Page can be executed + +// Mask for all protection bits +// Note: Some architectures may support additional bits +pub const PROT_MASK: u32 = 0x7; + +// ===== Memory Mapping Flags ===== +// Source: include/uapi/asm-generic/mman.h +pub const MAP_SHARED: u32 = 0x01; // Share changes with other processes +pub const MAP_PRIVATE: u32 = 0x02; // Changes are private to this process +pub const MAP_SHARING_MASK: u32 = 0x03; // Mask to isolate sharing bits + +pub const MAP_FIXED: u32 = 0x10; // Interpret address exactly +pub const MAP_ANON: u32 = 0x20; // Don't use a file descriptor +pub const MAP_ANONYMOUS: u32 = MAP_ANON; // Linux alias for MAP_ANON + +// ===== Page Size Constants ===== +// Note: These values are architecture-dependent +// Current values are for x86_64 Linux +pub const PAGESHIFT: u32 = 12; // 4KB pages (1 << 12 = 4096) +pub const PAGESIZE: u32 = 1 << PAGESHIFT; + +// Lind-specific page size constants +pub const MAP_PAGESHIFT: u32 = 16; // Custom value for Lind +pub const MAP_PAGESIZE: u32 = 1 << MAP_PAGESHIFT; + +// ===== Memory Mapping Error Value ===== +// Source: include/uapi/asm-generic/mman-common.h +pub const MAP_FAILED: *mut std::ffi::c_void = (-1isize) as *mut std::ffi::c_void; + +// ===== Memory Remapping Flags ===== +// Source: include/uapi/asm-generic/mman-common.h +pub const MREMAP_MAYMOVE: u32 = 0x01; // Can relocate mapping +pub const MREMAP_FIXED: u32 = 0x02; // New address is specified exactly + +// ===== File Access Modes ===== +// Source: include/uapi/asm-generic/fcntl.h +// NOTE: These should probably be moved to fs_constants.rs +pub const O_ACCMODE: i32 = 0o003; // Mask for file access modes +pub const O_RDONLY: i32 = 0o0; // Open read-only +pub const O_WRONLY: i32 = 0o1; // Open write-only +pub const O_RDWR: i32 = 0o2; // Open read-write diff --git a/src/RawPOSIX/src/constants/mod.rs b/src/RawPOSIX/src/constants/mod.rs new file mode 100644 index 00000000..265316cf --- /dev/null +++ b/src/RawPOSIX/src/constants/mod.rs @@ -0,0 +1,7 @@ +pub mod fs_constants; +pub mod net_constants; +pub mod sys_constants; + +pub use fs_constants::*; +pub use net_constants::*; +pub use sys_constants::*; diff --git a/src/RawPOSIX/src/constants/net_constants.rs b/src/RawPOSIX/src/constants/net_constants.rs new file mode 100644 index 00000000..4290f904 --- /dev/null +++ b/src/RawPOSIX/src/constants/net_constants.rs @@ -0,0 +1,371 @@ +//! Network Constants Module +//! These constants define network-related flags and parameters +//! +//! Primary Source References: +//! - Linux kernel v6.5: include/uapi/linux/socket.h +//! - Linux kernel v6.5: include/uapi/linux/in.h +//! - Linux kernel v6.5: include/uapi/linux/tcp.h +//! - Linux kernel v6.5: include/uapi/linux/poll.h +//! - Linux kernel v6.5: include/uapi/linux/eventpoll.h +//! - POSIX.1-2017 (IEEE Std 1003.1-2017) + +#![allow(dead_code)] +#![allow(non_upper_case_globals)] + +use crate::interface; + +// ===== Lind-specific Configuration ===== +pub const DEFAULT_HOSTNAME: &str = "Lind"; +pub const BLOCK_TIME: interface::RustDuration = interface::RustDuration::from_micros(100); +pub const UDSOCK_CAPACITY: usize = 212992; // Unix domain socket buffer size + +// ===== Socket Types ===== +// Source: include/linux/net.h +pub const SOCK_STREAM: i32 = 1; // Stream (connection) socket +pub const SOCK_DGRAM: i32 = 2; // Datagram (connectionless) socket +pub const SOCK_RAW: i32 = 3; // Raw protocol interface +pub const SOCK_RDM: i32 = 4; // Reliably-delivered message +pub const SOCK_SEQPACKET: i32 = 5; // Sequential packet socket +pub const SOCK_CLOEXEC: i32 = 0o02000000; // Set close-on-exec +pub const SOCK_NONBLOCK: i32 = 0o00004000; // Set non-blocking mode + +// ===== Address Families ===== +// Source: include/linux/socket.h +pub const AF_UNSPEC: i32 = 0; // Unspecified +pub const AF_UNIX: i32 = 1; // Unix domain sockets +pub const AF_LOCAL: i32 = 1; // POSIX name for AF_UNIX +pub const AF_INET: i32 = 2; // Internet IP Protocol +pub const AF_AX25: i32 = 3; // Amateur Radio AX.25 +pub const AF_IPX: i32 = 4; // Novell IPX +pub const AF_APPLETALK: i32 = 5; // AppleTalk DDP +pub const AF_NETROM: i32 = 6; // Amateur Radio NET/ROM +pub const AF_BRIDGE: i32 = 7; // Multiprotocol bridge +pub const AF_ATMPVC: i32 = 8; // ATM PVCs +pub const AF_X25: i32 = 9; // Reserved for X.25 project +pub const AF_INET6: i32 = 10; // IP version 6 +pub const AF_ROSE: i32 = 11; // Amateur Radio X.25 PLP +pub const AF_DECnet: i32 = 12; // Reserved for DECnet project +pub const AF_NETBEUI: i32 = 13; // Reserved for 802.2LLC project +pub const AF_SECURITY: i32 = 14; // Security callback pseudo AF +pub const AF_KEY: i32 = 15; // PF_KEY key management API +pub const AF_NETLINK: i32 = 16; // Netlink +pub const AF_ROUTE: i32 = AF_NETLINK; // Alias to emulate 4.4BSD +pub const AF_PACKET: i32 = 17; // Packet family +pub const AF_ASH: i32 = 18; // Ash +pub const AF_ECONET: i32 = 19; // Acorn Econet +pub const AF_ATMSVC: i32 = 20; // ATM SVCs +pub const AF_RDS: i32 = 21; // RDS sockets +pub const AF_SNA: i32 = 22; // Linux SNA Project +pub const AF_IRDA: i32 = 23; // IRDA sockets +pub const AF_PPPOX: i32 = 24; // PPPoX sockets +pub const AF_WANPIPE: i32 = 25; // Wanpipe API Sockets +pub const AF_LLC: i32 = 26; // Linux LLC +pub const AF_IB: i32 = 27; // Native InfiniBand address +pub const AF_MPLS: i32 = 28; // MPLS +pub const AF_CAN: i32 = 29; // Controller Area Network +pub const AF_TIPC: i32 = 30; // TIPC sockets +pub const AF_BLUETOOTH: i32 = 31; // Bluetooth sockets +pub const AF_IUCV: i32 = 32; // IUCV sockets +pub const AF_RXRPC: i32 = 33; // RxRPC sockets +pub const AF_ISDN: i32 = 34; // mISDN sockets +pub const AF_PHONET: i32 = 35; // Phonet sockets +pub const AF_IEEE802154: i32 = 36; // IEEE802154 sockets +pub const AF_CAIF: i32 = 37; // CAIF sockets +pub const AF_ALG: i32 = 38; // Algorithm sockets +pub const AF_NFC: i32 = 39; // NFC sockets +pub const AF_VSOCK: i32 = 40; // vSockets +pub const AF_KCM: i32 = 41; // Kernel Connection Multiplexor +pub const AF_QIPCRTR: i32 = 42; // Qualcomm IPC Router +pub const AF_SMC: i32 = 43; // SMC sockets +pub const AF_XDP: i32 = 44; // XDP sockets +pub const AF_MCTP: i32 = 45; // Management Component Transport Protocol +pub const AF_MAX: i32 = 46; // Maximum address family value + +// ===== Protocol Families ===== +// Source: include/linux/socket.h +// Note: PF_* constants are aliases for AF_* for backward compatibility +pub const PF_UNSPEC: i32 = AF_UNSPEC; +pub const PF_UNIX: i32 = AF_UNIX; +pub const PF_LOCAL: i32 = AF_LOCAL; +pub const PF_INET: i32 = AF_INET; +pub const PF_AX25: i32 = AF_AX25; +pub const PF_IPX: i32 = AF_IPX; +pub const PF_APPLETALK: i32 = AF_APPLETALK; +pub const PF_NETROM: i32 = AF_NETROM; +pub const PF_BRIDGE: i32 = AF_BRIDGE; +pub const PF_ATMPVC: i32 = AF_ATMPVC; +pub const PF_X25: i32 = AF_X25; +pub const PF_INET6: i32 = AF_INET6; +pub const PF_ROSE: i32 = AF_ROSE; +pub const PF_DECnet: i32 = AF_DECnet; +pub const PF_NETBEUI: i32 = AF_NETBEUI; +pub const PF_SECURITY: i32 = AF_SECURITY; +pub const PF_KEY: i32 = AF_KEY; +pub const PF_NETLINK: i32 = AF_NETLINK; +pub const PF_ROUTE: i32 = AF_ROUTE; +pub const PF_PACKET: i32 = AF_PACKET; +pub const PF_ASH: i32 = AF_ASH; +pub const PF_ECONET: i32 = AF_ECONET; +pub const PF_ATMSVC: i32 = AF_ATMSVC; +pub const PF_RDS: i32 = AF_RDS; +pub const PF_SNA: i32 = AF_SNA; +pub const PF_IRDA: i32 = AF_IRDA; +pub const PF_PPPOX: i32 = AF_PPPOX; +pub const PF_WANPIPE: i32 = AF_WANPIPE; +pub const PF_LLC: i32 = AF_LLC; +pub const PF_IB: i32 = AF_IB; +pub const PF_MPLS: i32 = AF_MPLS; +pub const PF_CAN: i32 = AF_CAN; +pub const PF_TIPC: i32 = AF_TIPC; +pub const PF_BLUETOOTH: i32 = AF_BLUETOOTH; +pub const PF_IUCV: i32 = AF_IUCV; +pub const PF_RXRPC: i32 = AF_RXRPC; +pub const PF_ISDN: i32 = AF_ISDN; +pub const PF_PHONET: i32 = AF_PHONET; +pub const PF_IEEE802154: i32 = AF_IEEE802154; +pub const PF_CAIF: i32 = AF_CAIF; +pub const PF_ALG: i32 = AF_ALG; +pub const PF_NFC: i32 = AF_NFC; +pub const PF_VSOCK: i32 = AF_VSOCK; +pub const PF_KCM: i32 = AF_KCM; +pub const PF_QIPCRTR: i32 = AF_QIPCRTR; +pub const PF_SMC: i32 = AF_SMC; +pub const PF_XDP: i32 = AF_XDP; +pub const PF_MCTP: i32 = AF_MCTP; +pub const PF_MAX: i32 = AF_MAX; + +// ===== IP Protocol Numbers ===== +// Source: include/uapi/linux/in.h +pub const IPPROTO_IP: i32 = 0; // Dummy protocol for TCP +pub const IPPROTO_ICMP: i32 = 1; // Internet Control Message Protocol +pub const IPPROTO_IGMP: i32 = 2; // Internet Group Management Protocol +pub const IPPROTO_GGP: i32 = 3; // Gateway-Gateway Protocol (deprecated) +pub const IPPROTO_IPV4: i32 = 4; // IPv4 encapsulation +pub const IPPROTO_IPIP: i32 = IPPROTO_IPV4; // IP in IP encapsulation +pub const IPPROTO_TCP: i32 = 6; // Transmission Control Protocol +pub const IPPROTO_ST: i32 = 7; // Stream Protocol +pub const IPPROTO_EGP: i32 = 8; // Exterior Gateway Protocol +pub const IPPROTO_PIGP: i32 = 9; // Private Interior Gateway Protocol +pub const IPPROTO_RCCMON: i32 = 10; // BBN RCC Monitoring +pub const IPPROTO_NVPII: i32 = 11; // Network Voice Protocol +pub const IPPROTO_PUP: i32 = 12; // PARC Universal Packet Protocol +pub const IPPROTO_ARGUS: i32 = 13; // ARGUS +pub const IPPROTO_EMCON: i32 = 14; // EMCON +pub const IPPROTO_XNET: i32 = 15; // Cross Net Debugger +pub const IPPROTO_CHAOS: i32 = 16; // Chaos +pub const IPPROTO_UDP: i32 = 17; // User Datagram Protocol +pub const IPPROTO_MUX: i32 = 18; // Multiplexing Protocol +pub const IPPROTO_MEAS: i32 = 19; // DCN Measurement Subsystems +pub const IPPROTO_HMP: i32 = 20; // Host Monitoring Protocol +pub const IPPROTO_PRM: i32 = 21; // Packet Radio Measurement Protocol +pub const IPPROTO_IDP: i32 = 22; // Xerox NS IDP +pub const IPPROTO_TRUNK1: i32 = 23; // Trunk-1 +pub const IPPROTO_TRUNK2: i32 = 24; // Trunk-2 +pub const IPPROTO_LEAF1: i32 = 25; // Leaf-1 +pub const IPPROTO_LEAF2: i32 = 26; // Leaf-2 +pub const IPPROTO_RDP: i32 = 27; // Reliable Datagram Protocol +pub const IPPROTO_IRTP: i32 = 28; // Internet Reliable Transaction Protocol +pub const IPPROTO_TP: i32 = 29; // ISO Transport Protocol Class 4 +pub const IPPROTO_BLT: i32 = 30; // Bulk Data Transfer Protocol +pub const IPPROTO_NSP: i32 = 31; // Network Services Protocol +pub const IPPROTO_INP: i32 = 32; // Merit Internodal Protocol +pub const IPPROTO_SEP: i32 = 33; // Sequential Exchange Protocol +pub const IPPROTO_3PC: i32 = 34; // Third Party Connect Protocol +pub const IPPROTO_IDPR: i32 = 35; // Inter-Domain Policy Routing Protocol +pub const IPPROTO_XTP: i32 = 36; // Xpress Transport Protocol +pub const IPPROTO_DDP: i32 = 37; // Datagram Delivery Protocol +pub const IPPROTO_CMTP: i32 = 38; // Control Message Transport Protocol +pub const IPPROTO_TPXX: i32 = 39; // TP++ Transport Protocol +pub const IPPROTO_IL: i32 = 40; // IL Transport Protocol +pub const IPPROTO_IPV6: i32 = 41; // IPv6 header +pub const IPPROTO_SDRP: i32 = 42; // Source Demand Routing Protocol +pub const IPPROTO_ROUTING: i32 = 43; // IPv6 routing header +pub const IPPROTO_FRAGMENT: i32 = 44; // IPv6 fragmentation header +pub const IPPROTO_IDRP: i32 = 45; // Inter-Domain Routing Protocol +pub const IPPROTO_RSVP: i32 = 46; // Resource Reservation Protocol +pub const IPPROTO_GRE: i32 = 47; // Generic Routing Encapsulation +pub const IPPROTO_MHRP: i32 = 48; // Mobile Host Routing Protocol +pub const IPPROTO_BHA: i32 = 49; // BHA +pub const IPPROTO_ESP: i32 = 50; // IPv6 Encapsulating Security Payload +pub const IPPROTO_AH: i32 = 51; // IPv6 Authentication Header +pub const IPPROTO_INLSP: i32 = 52; // Integrated Net Layer Security Protocol +pub const IPPROTO_SWIPE: i32 = 53; // IP with Encryption +pub const IPPROTO_NHRP: i32 = 54; // Next Hop Resolution Protocol + // 55-57: Unassigned +pub const IPPROTO_ICMPV6: i32 = 58; // ICMPv6 +pub const IPPROTO_NONE: i32 = 59; // IPv6 no next header +pub const IPPROTO_DSTOPTS: i32 = 60; // IPv6 destination options +pub const IPPROTO_AHIP: i32 = 61; // Any host internal protocol +pub const IPPROTO_CFTP: i32 = 62; // CFTP +pub const IPPROTO_HELLO: i32 = 63; // "hello" routing protocol +pub const IPPROTO_SATEXPAK: i32 = 64; // SATNET/Backroom EXPAK +pub const IPPROTO_KRYPTOLAN: i32 = 65; // Kryptolan +pub const IPPROTO_RVD: i32 = 66; // Remote Virtual Disk +pub const IPPROTO_IPPC: i32 = 67; // Pluribus Packet Core +pub const IPPROTO_ADFS: i32 = 68; // Any distributed file system +pub const IPPROTO_SATMON: i32 = 69; // SATNET Monitoring +pub const IPPROTO_VISA: i32 = 70; // VISA Protocol +pub const IPPROTO_IPCV: i32 = 71; // Internet Packet Core Utility +pub const IPPROTO_CPNX: i32 = 72; // Computer Protocol Network Executive +pub const IPPROTO_CPHB: i32 = 73; // Computer Protocol Heart Beat +pub const IPPROTO_WSN: i32 = 74; // Wang Span Network +pub const IPPROTO_PVP: i32 = 75; // Packet Video Protocol +pub const IPPROTO_BRSATMON: i32 = 76; // BackRoom SATNET Monitoring +pub const IPPROTO_ND: i32 = 77; // Sun net disk protocol (temporary) +pub const IPPROTO_WBMON: i32 = 78; // WIDEBAND Monitoring +pub const IPPROTO_WBEXPAK: i32 = 79; // WIDEBAND EXPAK +pub const IPPROTO_EON: i32 = 80; // ISO CNLP +pub const IPPROTO_VMTP: i32 = 81; // Versatile Message Transaction Protocol +pub const IPPROTO_SVMTP: i32 = 82; // Secure VMTP +pub const IPPROTO_VINES: i32 = 83; // VINES +pub const IPPROTO_TTP: i32 = 84; // TTP +pub const IPPROTO_IGP: i32 = 85; // NSFNET-IGP +pub const IPPROTO_DGP: i32 = 86; // Dissimilar Gateway Protocol +pub const IPPROTO_TCF: i32 = 87; // TCF +pub const IPPROTO_IGRP: i32 = 88; // Interior Gateway Routing Protocol +pub const IPPROTO_OSPFIGP: i32 = 89; // OSPF IGP +pub const IPPROTO_SRPC: i32 = 90; // Sprite RPC Protocol +pub const IPPROTO_LARP: i32 = 91; // Locus Address Resolution Protocol +pub const IPPROTO_MTP: i32 = 92; // Multicast Transport Protocol +pub const IPPROTO_AX25: i32 = 93; // AX.25 Frames +pub const IPPROTO_IPEIP: i32 = 94; // IP encapsulated in IP +pub const IPPROTO_MICP: i32 = 95; // Mobile Internetworking Control Protocol +pub const IPPROTO_SCCSP: i32 = 96; // Semaphore Communications Security Protocol +pub const IPPROTO_ETHERIP: i32 = 97; // Ethernet-within-IP Encapsulation +pub const IPPROTO_ENCAP: i32 = 98; // Encapsulation Header +pub const IPPROTO_APES: i32 = 99; // Any private encryption scheme +pub const IPPROTO_GMTP: i32 = 100; // GMTP +pub const IPPROTO_PIM: i32 = 103; // Protocol Independent Multicast +pub const IPPROTO_IPCOMP: i32 = 108; // IP Payload Compression Protocol +pub const IPPROTO_PGM: i32 = 113; // PGM Reliable Transport Protocol +pub const IPPROTO_SCTP: i32 = 132; // Stream Control Transmission Protocol +pub const IPPROTO_DIVERT: i32 = 254; // Divert pseudo-protocol +pub const IPPROTO_RAW: i32 = 255; // Raw IP packets +pub const IPPROTO_MAX: i32 = 256; +pub const IPPROTO_DONE: i32 = 257; // All processing for this packet is done + +// ===== Message Flags ===== +// Source: include/linux/socket.h +pub const MSG_OOB: i32 = 1; // Process out-of-band data +pub const MSG_PEEK: i32 = 2; // Peek at incoming message +pub const MSG_DONTROUTE: i32 = 4; // Don't use local routing +pub const MSG_TRYHARD: i32 = 4; // Synonym for MSG_DONTROUTE for DECnet +pub const MSG_CTRUNC: i32 = 8; // Control data lost before delivery +pub const MSG_PROBE: i32 = 0x10; // Do not send, probe path for MTU +pub const MSG_TRUNC: i32 = 0x20; // Message was truncated +pub const MSG_DONTWAIT: i32 = 0x40; // Non-blocking I/O +pub const MSG_EOR: i32 = 0x80; // End of record +pub const MSG_WAITALL: i32 = 0x100; // Wait for a full request +pub const MSG_FIN: i32 = 0x200; // Sender will send no more +pub const MSG_SYN: i32 = 0x400; // Initiate a connection +pub const MSG_CONFIRM: i32 = 0x800; // Confirm path validity +pub const MSG_RST: i32 = 0x1000; // Reset the connection +pub const MSG_ERRQUEUE: i32 = 0x2000; // Fetch message from error queue +pub const MSG_NOSIGNAL: i32 = 0x4000; // Do not generate SIGPIPE +pub const MSG_MORE: i32 = 0x8000; // Sender will send more +pub const MSG_WAITFORONE: i32 = 0x10000; // Wait for at least one packet +pub const MSG_SENDPAGE_NOPOLICY: i32 = 0x10000; // sendpage() internal: no policy +pub const MSG_SENDPAGE_NOTLAST: i32 = 0x20000; // sendpage() internal: not last page +pub const MSG_BATCH: i32 = 0x40000; // sendmmsg(): more messages coming +pub const MSG_EOF: i32 = MSG_FIN; // Alias for MSG_FIN +pub const MSG_NO_SHARED_FRAGS: i32 = 0x80000; // sendpage() internal: no shared frags +pub const MSG_SENDPAGE_DECRYPTED: i32 = 0x100000; // sendpage() internal: page needs encryption + +// ===== Shutdown Constants ===== +// Source: include/linux/socket.h +pub const SHUT_RD: i32 = 0; // Disable further receives +pub const SHUT_WR: i32 = 1; // Disable further sends +pub const SHUT_RDWR: i32 = 2; // Disable further sends/receives + +// ===== Socket Options ===== +// Source: include/uapi/asm-generic/socket.h +pub const SOL_SOCKET: i32 = 1; // Socket-level options +pub const SO_DEBUG: i32 = 1; // Debug info recording +pub const SO_REUSEADDR: i32 = 2; // Allow reuse of local addresses +pub const SO_TYPE: i32 = 3; // Get socket type +pub const SO_ERROR: i32 = 4; // Get and clear error status +pub const SO_DONTROUTE: i32 = 5; // Use interface addresses +pub const SO_BROADCAST: i32 = 6; // Permit sending of broadcast msgs +pub const SO_SNDBUF: i32 = 7; // Send buffer size +pub const SO_RCVBUF: i32 = 8; // Receive buffer size +pub const SO_SNDBUFFORCE: i32 = 32; // Send buffer size (privileged) +pub const SO_RCVBUFFORCE: i32 = 33; // Receive buffer size (privileged) +pub const SO_KEEPALIVE: i32 = 9; // Keep connections alive +pub const SO_OOBINLINE: i32 = 10; // Leave received OOB data in line +pub const SO_NO_CHECK: i32 = 11; // Disable checksums +pub const SO_PRIORITY: i32 = 12; // Set the protocol-defined priority +pub const SO_LINGER: i32 = 13; // Linger on close if data present +pub const SO_BSDCOMPAT: i32 = 14; // Enable BSD bug-to-bug compatibility +pub const SO_REUSEPORT: i32 = 15; // Allow reuse of address/port pairs +pub const SO_PASSCRED: i32 = 16; // Receive SCM_CREDENTIALS messages +pub const SO_PEERCRED: i32 = 17; // Get socket's peer credentials +pub const SO_RCVLOWAT: i32 = 18; // Receive low-water mark +pub const SO_SNDLOWAT: i32 = 19; // Send low-water mark +pub const SO_RCVTIMEO_OLD: i32 = 20; // Receive timeout (old) +pub const SO_SNDTIMEO_OLD: i32 = 21; // Send timeout (old) +pub const SO_PEERNAME: i32 = 28; // Name of connected peer +pub const SO_ACCEPTCONN: i32 = 30; // Socket has had listen() + +// ===== TCP Options ===== +// Source: include/uapi/linux/tcp.h +pub const SOL_TCP: i32 = IPPROTO_TCP; // TCP protocol level +pub const SOL_UDP: i32 = IPPROTO_UDP; // UDP protocol level + +pub const TCP_NODELAY: i32 = 0x01; // Don't delay send to coalesce packets +pub const TCP_MAXSEG: i32 = 0x02; // Set maximum segment size +pub const TCP_NOPUSH: i32 = 0x04; // Don't push last block of write +pub const TCP_NOOPT: i32 = 0x08; // Don't use TCP options +pub const TCP_KEEPALIVE: i32 = 0x10; // Idle time for keepalive +pub const TCP_CONNECTIONTIMEOUT: i32 = 0x20; // Connection timeout +pub const PERSIST_TIMEOUT: i32 = 0x40; // Persist timeout +pub const TCP_RXT_CONNDROPTIME: i32 = 0x80; // Retransmission timeout before drop +pub const TCP_RXT_FINDROP: i32 = 0x100; // Drop after 3 FIN retransmissions + +// ===== Socket Object ID Range ===== +// Lind-specific constants +pub const MINSOCKOBJID: i32 = 0; +pub const MAXSOCKOBJID: i32 = 1024; + +// ===== Poll Constants ===== +// Source: include/uapi/asm-generic/poll.h +pub const POLLIN: i16 = 0o1; // Ready for reading +pub const POLLPRI: i16 = 0o2; // Priority data ready +pub const POLLOUT: i16 = 0o4; // Ready for writing +pub const POLLERR: i16 = 0o10; // Error condition +pub const POLLHUP: i16 = 0o20; // Hung up +pub const POLLNVAL: i16 = 0o40; // Invalid polling request + +// ===== Epoll Constants ===== +// Source: include/uapi/linux/eventpoll.h +pub const EPOLLIN: i32 = 0x001; // Ready for reading +pub const EPOLLPRI: i32 = 0x002; // Priority data ready +pub const EPOLLOUT: i32 = 0x004; // Ready for writing +pub const EPOLLRDNORM: i32 = 0x040; // Normal data ready for reading +pub const EPOLLRDBAND: i32 = 0x080; // Priority band data ready for reading +pub const EPOLLWRNORM: i32 = 0x100; // Normal data ready for writing +pub const EPOLLWRBAND: i32 = 0x200; // Priority band data ready for writing +pub const EPOLLMSG: i32 = 0x400; // Message ready +pub const EPOLLERR: i32 = 0x008; // Error condition +pub const EPOLLHUP: i32 = 0x010; // Hang up +pub const EPOLLRDHUP: i32 = 0x2000; // Peer closed the connection +pub const EPOLLWAKEUP: i32 = 1 << 29; // Prevent system suspend +pub const EPOLLONESHOT: i32 = 1 << 30; // One-shot edge trigger +pub const EPOLLET: i32 = 1 << 31; // Edge-triggered + +pub const EPOLL_CTL_ADD: i32 = 1; // Add a file descriptor +pub const EPOLL_CTL_DEL: i32 = 2; // Remove a file descriptor +pub const EPOLL_CTL_MOD: i32 = 3; // Change event registration + +pub const FD_SET_MAX_FD: i32 = 1024; // Maximum file descriptor for fd_set + +// ===== Connection States ===== +// Lind-specific enum for internal use +#[derive(Debug, PartialEq, Eq, Clone)] +pub enum ConnState { + NOTCONNECTED, + CONNECTED, + CONNRDONLY, + CONNWRONLY, + LISTEN, + INPROGRESS, +} diff --git a/src/RawPOSIX/src/constants/sys_constants.rs b/src/RawPOSIX/src/constants/sys_constants.rs new file mode 100644 index 00000000..34492abf --- /dev/null +++ b/src/RawPOSIX/src/constants/sys_constants.rs @@ -0,0 +1,97 @@ +//! System Constants Module +//! +//! Primary Source References: +//! - Linux kernel v6.5: include/uapi/asm-generic/signal.h +//! - Linux kernel v6.5: include/uapi/asm-generic/resource.h +//! - POSIX.1-2017 (IEEE Std 1003.1-2017) +//! - Linux man-pages project: signal(7) + +#![allow(dead_code)] +#![allow(unused_variables)] + +use crate::interface; + +// ===== User and Group ID Constants ===== +// Lind-specific default values +pub const DEFAULT_UID: u32 = 1000; // Default user ID +pub const DEFAULT_GID: u32 = 1000; // Default group ID + +// ===== Resource Limits ===== +// Source: include/uapi/asm-generic/resource.h +pub const SIGNAL_MAX: i32 = 64; // Maximum number of signals + +// File descriptor limits +pub const NOFILE_CUR: u64 = 1024; // Soft limit for number of open files +pub const NOFILE_MAX: u64 = 4 * 1024; // Hard limit for number of open files + +// Stack size limits +pub const STACK_CUR: u64 = 8192 * 1024; // Soft limit for stack size (8MB) +pub const STACK_MAX: u64 = 1 << 32; // Hard limit for stack size (4GB) + +// Resource identifiers +pub const RLIMIT_STACK: u64 = 0; // Limit type for stack size +pub const RLIMIT_NOFILE: u64 = 1; // Limit type for number of files + +// ===== Process Exit Status ===== +// Source: and POSIX standard +pub const EXIT_SUCCESS: i32 = 0; // Successful termination +pub const EXIT_FAILURE: i32 = 1; // Unsuccessful termination + +// ===== Signal Constants ===== +// Source: include/uapi/asm-generic/signal.h +// Reference: https://man7.org/linux/man-pages/man7/signal.7.html +// Note: Signal numbers can vary by architecture. These are for x86/ARM. + +// Terminal control signals +pub const SIGHUP: i32 = 1; // Hangup +pub const SIGINT: i32 = 2; // Interrupt (Ctrl+C) +pub const SIGQUIT: i32 = 3; // Quit (Ctrl+\) +pub const SIGTERM: i32 = 15; // Termination request + +// Error signals +pub const SIGILL: i32 = 4; // Illegal instruction +pub const SIGTRAP: i32 = 5; // Trace/breakpoint trap +pub const SIGABRT: i32 = 6; // Abort program +pub const SIGIOT: i32 = 6; // Alias for SIGABRT +pub const SIGBUS: i32 = 7; // Bus error (bad memory access) +pub const SIGFPE: i32 = 8; // Floating point exception +pub const SIGSEGV: i32 = 11; // Segmentation violation +pub const SIGSYS: i32 = 31; // Bad system call +pub const SIGUNUSED: i32 = 31; // Alias for SIGSYS + +// User-defined signals +pub const SIGUSR1: i32 = 10; // User-defined signal 1 +pub const SIGUSR2: i32 = 12; // User-defined signal 2 + +// Process control signals +pub const SIGCHLD: i32 = 17; // Child stopped or terminated +pub const SIGCONT: i32 = 18; // Continue if stopped +pub const SIGSTOP: i32 = 19; // Stop process +pub const SIGTSTP: i32 = 20; // Stop typed at terminal +pub const SIGTTIN: i32 = 21; // Terminal input for background process +pub const SIGTTOU: i32 = 22; // Terminal output for background process + +// Resource limit signals +pub const SIGXCPU: i32 = 24; // CPU time limit exceeded +pub const SIGXFSZ: i32 = 25; // File size limit exceeded + +// Alarm signals +pub const SIGALRM: i32 = 14; // Timer signal from alarm(2) +pub const SIGVTALRM: i32 = 26; // Virtual timer expired +pub const SIGPROF: i32 = 27; // Profiling timer expired + +// I/O signals +pub const SIGPIPE: i32 = 13; // Broken pipe +pub const SIGURG: i32 = 23; // Urgent condition on socket +pub const SIGWINCH: i32 = 28; // Window resize signal +pub const SIGIO: i32 = 29; // I/O now possible +pub const SIGPOLL: i32 = 29; // Pollable event (same as SIGIO) +pub const SIGPWR: i32 = 30; // Power failure + +// Signal actions +pub const SIG_BLOCK: i32 = 0; // Block signals in signal mask +pub const SIG_UNBLOCK: i32 = 1; // Unblock signals in signal mask +pub const SIG_SETMASK: i32 = 2; // Set the signal mask + +// Timer types +pub const ITIMER_REAL: i32 = 0; // Real-time timer diff --git a/src/RawPOSIX/src/interface/misc.rs b/src/RawPOSIX/src/interface/misc.rs index 2476b23f..0f9fcd5c 100644 --- a/src/RawPOSIX/src/interface/misc.rs +++ b/src/RawPOSIX/src/interface/misc.rs @@ -34,7 +34,7 @@ pub use serde_cbor::{ use crate::interface; use crate::interface::errnos::VERBOSE; use crate::interface::types::SigsetType; -use crate::safeposix::syscalls::fs_constants::SEM_VALUE_MAX; +use crate::constants::SEM_VALUE_MAX; use std::sync::LazyLock; use std::time::Duration; diff --git a/src/RawPOSIX/src/lib.rs b/src/RawPOSIX/src/lib.rs index d7f3d819..29e66e4a 100644 --- a/src/RawPOSIX/src/lib.rs +++ b/src/RawPOSIX/src/lib.rs @@ -11,3 +11,4 @@ pub mod interface; pub mod safeposix; pub mod tests; pub mod fdtables; +pub mod constants; diff --git a/src/RawPOSIX/src/safeposix/cage.rs b/src/RawPOSIX/src/safeposix/cage.rs index 2e6d6ad4..372b39a1 100644 --- a/src/RawPOSIX/src/safeposix/cage.rs +++ b/src/RawPOSIX/src/safeposix/cage.rs @@ -1,6 +1,14 @@ #![allow(dead_code)] use crate::interface; -//going to get the datatypes and errnos from the cage file from now on +use crate::constants::{ + SIGNAL_MAX, + S_IRWXU, S_IRWXG, S_IRWXO, + PROT_READ, PROT_WRITE, + O_RDONLY, O_WRONLY, O_RDWR, O_CREAT, O_TRUNC, + MAP_SHARED, MAP_PRIVATE, +}; + +// Going to get the datatypes and errnos from the cage file from now on pub use crate::interface::errnos::{syscall_error, Errno}; pub use crate::interface::types::{ @@ -8,12 +16,8 @@ pub use crate::interface::types::{ }; use super::filesystem::normpath; -pub use super::syscalls::fs_constants::*; -pub use super::syscalls::net_constants::*; -pub use super::syscalls::sys_constants::*; -pub use super::vmmap::*; -pub use super::vmmap_constants::*; +pub use super::vmmap::*; pub use crate::interface::CAGE_TABLE; #[derive(Debug, Clone, Copy)] diff --git a/src/RawPOSIX/src/safeposix/dispatcher.rs b/src/RawPOSIX/src/safeposix/dispatcher.rs index 9d0673ab..427411bb 100644 --- a/src/RawPOSIX/src/safeposix/dispatcher.rs +++ b/src/RawPOSIX/src/safeposix/dispatcher.rs @@ -135,6 +135,7 @@ use crate::interface::types; use crate::interface::{SigactionStruct, StatData}; use crate::{fdtables, interface}; use crate::interface::errnos::*; +use crate::constants::{O_RDONLY, O_WRONLY}; macro_rules! get_onearg { ($arg: expr) => { @@ -1155,8 +1156,8 @@ pub fn lindrustinit(verbosity: isize) { // STDIN let dev_null = CString::new("/home/lind/lind_project/src/safeposix-rust/tmp/dev/null").unwrap(); unsafe { - libc::open(dev_null.as_ptr(), libc::O_RDONLY); - libc::open(dev_null.as_ptr(), libc::O_WRONLY); + libc::open(dev_null.as_ptr(), O_RDONLY); + libc::open(dev_null.as_ptr(), O_WRONLY); libc::dup(1); } diff --git a/src/RawPOSIX/src/safeposix/mod.rs b/src/RawPOSIX/src/safeposix/mod.rs index 6f4bc0e3..2f4c3760 100644 --- a/src/RawPOSIX/src/safeposix/mod.rs +++ b/src/RawPOSIX/src/safeposix/mod.rs @@ -4,4 +4,4 @@ pub mod filesystem; pub mod shm; pub mod syscalls; pub mod vmmap; -pub mod vmmap_constants; +// pub mod vmmap_constants; diff --git a/src/RawPOSIX/src/safeposix/shm.rs b/src/RawPOSIX/src/safeposix/shm.rs index a450af6e..5df5c742 100644 --- a/src/RawPOSIX/src/safeposix/shm.rs +++ b/src/RawPOSIX/src/safeposix/shm.rs @@ -1,8 +1,12 @@ // Filesystem metadata struct #![allow(dead_code)] -use super::syscalls::fs_constants::*; -use super::syscalls::sys_constants::*; +use crate::constants::{ + PROT_NONE, PROT_READ, PROT_WRITE, + MAP_SHARED, MAP_PRIVATE, MAP_FIXED, MAP_ANONYMOUS, + SHM_RDONLY, SHM_DEST, +}; + use crate::interface; use libc::*; @@ -118,7 +122,7 @@ impl ShmSegment { } } interface::RustHashEntry::Vacant(_) => { - panic!("Cage not avilable in segment attached cages"); + panic!("Cage not available in segment attached cages"); } }; } diff --git a/src/RawPOSIX/src/safeposix/syscalls/fs_calls.rs b/src/RawPOSIX/src/safeposix/syscalls/fs_calls.rs index 18b6f3aa..675e51f2 100644 --- a/src/RawPOSIX/src/safeposix/syscalls/fs_calls.rs +++ b/src/RawPOSIX/src/safeposix/syscalls/fs_calls.rs @@ -1,10 +1,23 @@ #![allow(dead_code)] use std::fs; -use super::fs_constants; -// File system related system calls -use super::fs_constants::*; -use super::sys_constants; +// Removed these since we'll import from constants directly +// use super::fs_constants; +// use super::fs_constants::*; +// use super::sys_constants; + +// Add constants imports +use crate::constants::{ + S_IRWXU, S_IRWXG, S_IRWXO, + PROT_READ, PROT_WRITE, + O_RDONLY, O_WRONLY, O_RDWR, O_CREAT, O_TRUNC, O_CLOEXEC, + MAP_SHARED, MAP_PRIVATE, + SEEK_SET, SEEK_CUR, SEEK_END, + SHMMIN, SHMMAX, SHM_RDONLY, SHM_DEST, + DEFAULT_UID, DEFAULT_GID, + SEM_VALUE_MAX, +}; + use crate::interface; use crate::interface::get_errno; use crate::interface::handle_errno; @@ -1178,7 +1191,7 @@ impl Cage { let metadata = &SHM_METADATA; let prot: i32; if let Some(mut segment) = metadata.shmtable.get_mut(&shmid) { - if 0 != (shmflg & fs_constants::SHM_RDONLY) { + if 0 != (shmflg & SHM_RDONLY) { prot = PROT_READ; } else { prot = PROT_READ | PROT_WRITE; diff --git a/src/RawPOSIX/src/safeposix/syscalls/fs_constants.rs b/src/RawPOSIX/src/safeposix/syscalls/fs_constants.rs deleted file mode 100644 index a5c1fb61..00000000 --- a/src/RawPOSIX/src/safeposix/syscalls/fs_constants.rs +++ /dev/null @@ -1,196 +0,0 @@ -// File system related constants -#![allow(dead_code)] -#![allow(unused_variables)] - -use crate::interface; - -// Define constants using static or const -// Imported into fs_calls file -// pub const DT_UNKNOWN: u8 = 0; - -// pub const STARTINGFD: i32 = 0; -// pub const MAXFD: i32 = 1024; -// pub const STARTINGPIPE: i32 = 0; -// pub const MAXPIPE: i32 = 1024; - -// pub const ROOTDIRECTORYINODE: usize = 1; -// pub const STREAMINODE: usize = 2; - -// pub const PIPE_CAPACITY: usize = 65536; - -// pub const F_OK: u32 = 0; -// pub const X_OK: u32 = 1; -// pub const W_OK: u32 = 2; -// pub const R_OK: u32 = 4; - -// pub const O_RDONLY: i32 = 0o0; -// pub const O_WRONLY: i32 = 0o1; -// pub const O_RDWR: i32 = 0o2; -// pub const O_RDWRFLAGS: i32 = 0o3; - -// pub const O_CREAT: i32 = 0o100; -// pub const O_EXCL: i32 = 0o200; -// pub const O_NOCTTY: i32 = 0o400; -// pub const O_TRUNC: i32 = 0o1000; -// pub const O_APPEND: i32 = 0o2000; -// pub const O_NONBLOCK: i32 = 0o4000; -// // O_NDELAY=O_NONBLOCK -// pub const O_SYNC: i32 = 0o10000; -// // O_FSYNC=O_SYNC -// pub const O_ASYNC: i32 = 0o20000; -// pub const O_CLOEXEC: i32 = 0o2000000; - -// pub const DEFAULTTIME: u64 = 1323630836; - -//Standard flag combinations -pub const S_IRWXA: u32 = 0o777; -pub const S_IRWXU: u32 = 0o700; -pub const S_IRUSR: u32 = 0o400; -pub const S_IWUSR: u32 = 0o200; -pub const S_IXUSR: u32 = 0o100; -pub const S_IRWXG: u32 = 0o070; -pub const S_IRGRP: u32 = 0o040; -pub const S_IWGRP: u32 = 0o020; -pub const S_IXGRP: u32 = 0o010; -pub const S_IRWXO: u32 = 0o007; -pub const S_IROTH: u32 = 0o004; -pub const S_IWOTH: u32 = 0o002; -pub const S_IXOTH: u32 = 0o001; - -// //Commands for FCNTL -// pub const F_DUPFD: i32 = 0; -// pub const F_GETFD: i32 = 1; -// pub const F_SETFD: i32 = 2; -// pub const F_GETFL: i32 = 3; -// pub const F_SETFL: i32 = 4; -// pub const F_GETLK: i32 = 5; -// pub const F_GETLK64: i32 = 5; -// pub const F_SETLK: i32 = 6; -// pub const F_SETLK64: i32 = 6; -// pub const F_SETLKW: i32 = 7; -// pub const F_SETLKW64: i32 = 7; -// pub const F_SETOWN: i32 = 8; -// pub const F_GETOWN: i32 = 9; -// pub const F_SETSIG: i32 = 10; -// pub const F_GETSIG: i32 = 11; -// pub const F_SETLEASE: i32 = 1024; -// pub const F_GETLEASE: i32 = 1025; -// pub const F_NOTIFY: i32 = 1026; - -// //Commands for IOCTL -// pub const FIONBIO: u32 = 21537; -// pub const FIOASYNC: u32 = 21586; - -// //File types for open/stat etc. -// pub const S_IFBLK: i32 = 0o60000; -// pub const S_IFCHR: i32 = 0o20000; -// pub const S_IFDIR: i32 = 0o40000; -// pub const S_IFIFO: i32 = 0o10000; -// pub const S_IFLNK: i32 = 0o120000; -// pub const S_IFREG: i32 = 0o100000; -// pub const S_IFSOCK: i32 = 0o140000; -// pub const S_FILETYPEFLAGS: i32 = 0o170000; - -// //for flock syscall -// pub const LOCK_SH: i32 = 1; -// pub const LOCK_EX: i32 = 2; -// pub const LOCK_UN: i32 = 8; -// pub const LOCK_NB: i32 = 4; -// //for mmap/munmap syscall -// pub const MAP_SHARED: i32 = 1; -// pub const MAP_PRIVATE: i32 = 2; -// pub const MAP_FIXED: i32 = 16; -// pub const MAP_ANONYMOUS: i32 = 32; -// pub const MAP_HUGE_SHIFT: i32 = 26; -// pub const MAP_HUGETLB: i32 = 262144; - -// pub const PROT_NONE: i32 = 0; -// pub const PROT_READ: i32 = 1; -// pub const PROT_WRITE: i32 = 2; -// pub const PROT_EXEC: i32 = 4; - -// pub const SEEK_SET: i32 = 0; -// pub const SEEK_CUR: i32 = 1; -// pub const SEEK_END: i32 = 2; - -// pub const IPC_PRIVATE: i32 = 0o0; -// pub const IPC_CREAT: i32 = 0o1000; -// pub const IPC_EXCL: i32 = 0o2000; - -// pub const IPC_RMID: i32 = 0; -// pub const IPC_SET: i32 = 1; -// pub const IPC_STAT: i32 = 2; - -pub const SHM_DEST: i32 = 0o1000; -pub const SHM_LOCKED: i32 = 0o2000; -pub const SHM_HUGETLB: i32 = 0o4000; - -pub const SHM_R: i32 = 0o400; -pub const SHM_W: i32 = 0o200; -pub const SHM_RDONLY: i32 = 0o10000; -pub const SHM_RND: i32 = 0o20000; -pub const SHM_REMAP: i32 = 0o40000; -pub const SHM_EXEC: i32 = 0o100000; - -pub const SHMMIN: u32 = 1; -pub const SHMMNI: u32 = 4096; -pub const SHMMAX: u32 = 4278190079; // (ULONG_MAX - (1UL << 24)) -pub const SHMALL: u32 = 4278190079; // (ULONG_MAX - (1UL << 24)); -pub const SHMSEG: u32 = SHMMNI; - -pub const SEM_VALUE_MAX: u32 = 2147483647; - -// //device info for char files -// #[derive(interface::SerdeSerialize, interface::SerdeDeserialize, PartialEq, Eq, Debug)] -// pub struct DevNo { -// pub major: u32, -// pub minor: u32, -// } -// pub const NULLDEVNO: DevNo = DevNo { major: 1, minor: 3 }; -// pub const ZERODEVNO: DevNo = DevNo { major: 1, minor: 5 }; -// pub const RANDOMDEVNO: DevNo = DevNo { major: 1, minor: 8 }; -// pub const URANDOMDEVNO: DevNo = DevNo { major: 1, minor: 9 }; - -// pub const FILEDATAPREFIX: &str = "linddata."; - -// pub fn is_reg(mode: u32) -> bool { -// (mode as i32 & S_FILETYPEFLAGS) == S_IFREG -// } - -// pub fn is_chr(mode: u32) -> bool { -// (mode as i32 & S_FILETYPEFLAGS) == S_IFCHR -// } - -// pub fn is_dir(mode: u32) -> bool { -// (mode as i32 & S_FILETYPEFLAGS) == S_IFDIR -// } - -// pub fn is_wronly(flags: i32) -> bool { -// (flags & O_RDWRFLAGS) == O_WRONLY -// } -// pub fn is_rdonly(flags: i32) -> bool { -// (flags & O_RDWRFLAGS) == O_RDONLY -// } - -// //the same as the glibc makedev -// pub fn makedev(dev: &DevNo) -> u64 { -// ((dev.major as u64 & 0x00000fff) << 8) -// | ((dev.major as u64 & 0xfffff000) << 32) -// | ((dev.minor as u64 & 0x000000ff) << 0) -// | ((dev.minor as u64 & 0xffffff00) << 12) -// } - -// //the same as the glibc major and minor functions -// pub fn major(devnum: u64) -> u32 { -// (((devnum & 0x00000000000fff00) >> 8) | ((devnum & 0xfffff00000000000) >> 32)) as u32 -// } -// pub fn minor(devnum: u64) -> u32 { -// (((devnum & 0x00000000000000ff) >> 0) | ((devnum & 0x00000ffffff00000) >> 12)) as u32 -// } - -// pub fn devtuple(devnum: u64) -> DevNo { -// DevNo { -// major: major(devnum), -// minor: minor(devnum), -// } -// } diff --git a/src/RawPOSIX/src/safeposix/syscalls/mod.rs b/src/RawPOSIX/src/safeposix/syscalls/mod.rs index 51b60b43..efb27fb2 100644 --- a/src/RawPOSIX/src/safeposix/syscalls/mod.rs +++ b/src/RawPOSIX/src/safeposix/syscalls/mod.rs @@ -1,12 +1,6 @@ pub mod fs_calls; -pub mod fs_constants; pub mod net_calls; -pub mod net_constants; pub mod sys_calls; -pub mod sys_constants; pub use fs_calls::*; -pub use fs_constants::*; pub use net_calls::*; -pub use net_constants::*; pub use sys_calls::*; -pub use sys_constants::*; diff --git a/src/RawPOSIX/src/safeposix/syscalls/net_calls.rs b/src/RawPOSIX/src/safeposix/syscalls/net_calls.rs index 471b85b9..39ce957c 100644 --- a/src/RawPOSIX/src/safeposix/syscalls/net_calls.rs +++ b/src/RawPOSIX/src/safeposix/syscalls/net_calls.rs @@ -1,9 +1,9 @@ #![allow(dead_code)] -use super::net_constants; +use crate::constants::net_constants; use crate::{interface::FdSet, safeposix::cage::*}; use crate::interface::*; use crate::interface; -use super::sys_constants; +use crate::constants::sys_constants; use crate::fdtables::{self, FDTableEntry}; diff --git a/src/RawPOSIX/src/safeposix/syscalls/net_constants.rs b/src/RawPOSIX/src/safeposix/syscalls/net_constants.rs deleted file mode 100644 index c600aeeb..00000000 --- a/src/RawPOSIX/src/safeposix/syscalls/net_constants.rs +++ /dev/null @@ -1,392 +0,0 @@ -// Network related constants -#![allow(dead_code)] -#![allow(non_upper_case_globals)] - -use crate::interface; - -//used for gethostname syscall -pub const DEFAULT_HOSTNAME: &str = "Lind"; -pub const BLOCK_TIME: interface::RustDuration = interface::RustDuration::from_micros(100); - -pub const UDSOCK_CAPACITY: usize = 212992; - -// Define constants using static or const -// Imported into net_calls file - -pub const SOCK_STREAM: i32 = 1; //stream socket -pub const SOCK_DGRAM: i32 = 2; //datagram socket -pub const SOCK_RAW: i32 = 3; //raw protocol interface -pub const SOCK_RDM: i32 = 4; //reliably delivered message -pub const SOCK_SEQPACKET: i32 = 5; //sequenced packet stream -pub const SOCK_CLOEXEC: i32 = 0o02000000; // Atomically set close-on-exec -pub const SOCK_NONBLOCK: i32 = 0o00004000; // Mark as non-blocking - -/* Supported address families. */ -pub const AF_UNSPEC: i32 = 0; -pub const AF_UNIX: i32 = 1; /* Unix domain sockets */ -pub const AF_LOCAL: i32 = 1; /* POSIX name for AF_UNIX */ -pub const AF_INET: i32 = 2; /* Internet IP Protocol */ -pub const AF_AX25: i32 = 3; /* Amateur Radio AX.25 */ -pub const AF_IPX: i32 = 4; /* Novell IPX */ -pub const AF_APPLETALK: i32 = 5; /* AppleTalk DDP */ -pub const AF_NETROM: i32 = 6; /* Amateur Radio NET/ROM */ -pub const AF_BRIDGE: i32 = 7; /* Multiprotocol bridge */ -pub const AF_ATMPVC: i32 = 8; /* ATM PVCs */ -pub const AF_X25: i32 = 9; /* Reserved for X.25 project */ -pub const AF_INET6: i32 = 10; /* IP version 6 */ -pub const AF_ROSE: i32 = 11; /* Amateur Radio X.25 PLP */ -pub const AF_DECnet: i32 = 12; /* Reserved for DECnet project */ -pub const AF_NETBEUI: i32 = 13; /* Reserved for 802.2LLC project*/ -pub const AF_SECURITY: i32 = 14; /* Security callback pseudo AF */ -pub const AF_KEY: i32 = 15; /* PF_KEY key management API */ -pub const AF_NETLINK: i32 = 16; -pub const AF_ROUTE: i32 = AF_NETLINK; /* Alias to emulate 4.4BSD */ -pub const AF_PACKET: i32 = 17; /* Packet family */ -pub const AF_ASH: i32 = 18; /* Ash */ -pub const AF_ECONET: i32 = 19; /* Acorn Econet */ -pub const AF_ATMSVC: i32 = 20; /* ATM SVCs */ -pub const AF_RDS: i32 = 21; /* RDS sockets */ -pub const AF_SNA: i32 = 22; /* Linux SNA Project (nutters!) */ -pub const AF_IRDA: i32 = 23; /* IRDA sockets */ -pub const AF_PPPOX: i32 = 24; /* PPPoX sockets */ -pub const AF_WANPIPE: i32 = 25; /* Wanpipe API Sockets */ -pub const AF_LLC: i32 = 26; /* Linux LLC */ -pub const AF_IB: i32 = 27; /* Native InfiniBand address */ -pub const AF_MPLS: i32 = 28; /* MPLS */ -pub const AF_CAN: i32 = 29; /* Controller Area Network */ -pub const AF_TIPC: i32 = 30; /* TIPC sockets */ -pub const AF_BLUETOOTH: i32 = 31; /* Bluetooth sockets */ -pub const AF_IUCV: i32 = 32; /* IUCV sockets */ -pub const AF_RXRPC: i32 = 33; /* RxRPC sockets */ -pub const AF_ISDN: i32 = 34; /* mISDN sockets */ -pub const AF_PHONET: i32 = 35; /* Phonet sockets */ -pub const AF_IEEE802154: i32 = 36; /* IEEE802154 sockets */ -pub const AF_CAIF: i32 = 37; /* CAIF sockets */ -pub const AF_ALG: i32 = 38; /* Algorithm sockets */ -pub const AF_NFC: i32 = 39; /* NFC sockets */ -pub const AF_VSOCK: i32 = 40; /* vSockets */ -pub const AF_KCM: i32 = 41; /* Kernel Connection Multiplexor*/ -pub const AF_QIPCRTR: i32 = 42; /* Qualcomm IPC Router */ -pub const AF_SMC: i32 = 43; /* smc sockets: reserve number for - * PF_SMC protocol family that - * reuses AF_INET address family - */ -pub const AF_XDP: i32 = 44; /* XDP sockets */ -pub const AF_MCTP: i32 = 45; /* Management component - * transport protocol - */ - -pub const AF_MAX: i32 = 46; /* For now.. */ - -/* Protocol families, same as address families. */ -pub const PF_UNSPEC: i32 = AF_UNSPEC; -pub const PF_UNIX: i32 = AF_UNIX; -pub const PF_LOCAL: i32 = AF_LOCAL; -pub const PF_INET: i32 = AF_INET; -pub const PF_AX25: i32 = AF_AX25; -pub const PF_IPX: i32 = AF_IPX; -pub const PF_APPLETALK: i32 = AF_APPLETALK; -pub const PF_NETROM: i32 = AF_NETROM; -pub const PF_BRIDGE: i32 = AF_BRIDGE; -pub const PF_ATMPVC: i32 = AF_ATMPVC; -pub const PF_X25: i32 = AF_X25; -pub const PF_INET6: i32 = AF_INET6; -pub const PF_ROSE: i32 = AF_ROSE; -pub const PF_DECnet: i32 = AF_DECnet; -pub const PF_NETBEUI: i32 = AF_NETBEUI; -pub const PF_SECURITY: i32 = AF_SECURITY; -pub const PF_KEY: i32 = AF_KEY; -pub const PF_NETLINK: i32 = AF_NETLINK; -pub const PF_ROUTE: i32 = AF_ROUTE; -pub const PF_PACKET: i32 = AF_PACKET; -pub const PF_ASH: i32 = AF_ASH; -pub const PF_ECONET: i32 = AF_ECONET; -pub const PF_ATMSVC: i32 = AF_ATMSVC; -pub const PF_RDS: i32 = AF_RDS; -pub const PF_SNA: i32 = AF_SNA; -pub const PF_IRDA: i32 = AF_IRDA; -pub const PF_PPPOX: i32 = AF_PPPOX; -pub const PF_WANPIPE: i32 = AF_WANPIPE; -pub const PF_LLC: i32 = AF_LLC; -pub const PF_IB: i32 = AF_IB; -pub const PF_MPLS: i32 = AF_MPLS; -pub const PF_CAN: i32 = AF_CAN; -pub const PF_TIPC: i32 = AF_TIPC; -pub const PF_BLUETOOTH: i32 = AF_BLUETOOTH; -pub const PF_IUCV: i32 = AF_IUCV; -pub const PF_RXRPC: i32 = AF_RXRPC; -pub const PF_ISDN: i32 = AF_ISDN; -pub const PF_PHONET: i32 = AF_PHONET; -pub const PF_IEEE802154: i32 = AF_IEEE802154; -pub const PF_CAIF: i32 = AF_CAIF; -pub const PF_ALG: i32 = AF_ALG; -pub const PF_NFC: i32 = AF_NFC; -pub const PF_VSOCK: i32 = AF_VSOCK; -pub const PF_KCM: i32 = AF_KCM; -pub const PF_QIPCRTR: i32 = AF_QIPCRTR; -pub const PF_SMC: i32 = AF_SMC; -pub const PF_XDP: i32 = AF_XDP; -pub const PF_MCTP: i32 = AF_MCTP; -pub const PF_MAX: i32 = AF_MAX; - -// protocols... - -pub const IPPROTO_IP: i32 = 0; // dummy for IP -pub const IPPROTO_ICMP: i32 = 1; // control message protocol -pub const IPPROTO_IGMP: i32 = 2; // group mgmt protocol -pub const IPPROTO_GGP: i32 = 3; // gateway^2 (deprecated) -pub const IPPROTO_IPV4: i32 = 4; // IPv4 encapsulation -pub const IPPROTO_IPIP: i32 = IPPROTO_IPV4; // for compatibility -pub const IPPROTO_TCP: i32 = 6; // tcp -pub const IPPROTO_ST: i32 = 7; // Stream protocol II -pub const IPPROTO_EGP: i32 = 8; // exterior gateway protocol -pub const IPPROTO_PIGP: i32 = 9; // private interior gateway -pub const IPPROTO_RCCMON: i32 = 10; // BBN RCC Monitoring -pub const IPPROTO_NVPII: i32 = 11; // network voice protocol -pub const IPPROTO_PUP: i32 = 12; // pup -pub const IPPROTO_ARGUS: i32 = 13; // Argus -pub const IPPROTO_EMCON: i32 = 14; // EMCON -pub const IPPROTO_XNET: i32 = 15; // Cross Net Debugger -pub const IPPROTO_CHAOS: i32 = 16; // Chaos -pub const IPPROTO_UDP: i32 = 17; // user datagram protocol -pub const IPPROTO_MUX: i32 = 18; // Multiplexing -pub const IPPROTO_MEAS: i32 = 19; // DCN Measurement Subsystems -pub const IPPROTO_HMP: i32 = 20; // Host Monitoring -pub const IPPROTO_PRM: i32 = 21; // Packet Radio Measurement -pub const IPPROTO_IDP: i32 = 22; // xns idp -pub const IPPROTO_TRUNK1: i32 = 23; // Trunk-1 -pub const IPPROTO_TRUNK2: i32 = 24; // Trunk-2 -pub const IPPROTO_LEAF1: i32 = 25; // Leaf-1 -pub const IPPROTO_LEAF2: i32 = 26; // Leaf-2 -pub const IPPROTO_RDP: i32 = 27; // Reliable Data -pub const IPPROTO_IRTP: i32 = 28; // Reliable Transaction -pub const IPPROTO_TP: i32 = 29; // tp-4 w/ class negotiation -pub const IPPROTO_BLT: i32 = 30; // Bulk Data Transfer -pub const IPPROTO_NSP: i32 = 31; // Network Services -pub const IPPROTO_INP: i32 = 32; // Merit Internodal -pub const IPPROTO_SEP: i32 = 33; // Sequential Exchange -pub const IPPROTO_3PC: i32 = 34; // Third Party Connect -pub const IPPROTO_IDPR: i32 = 35; // InterDomain Policy Routing -pub const IPPROTO_XTP: i32 = 36; // XTP -pub const IPPROTO_DDP: i32 = 37; // Datagram Delivery -pub const IPPROTO_CMTP: i32 = 38; // Control Message Transport -pub const IPPROTO_TPXX: i32 = 39; // TP++ Transport -pub const IPPROTO_IL: i32 = 40; // IL transport protocol -pub const IPPROTO_IPV6: i32 = 41; // IP6 header -pub const IPPROTO_SDRP: i32 = 42; // Source Demand Routing -pub const IPPROTO_ROUTING: i32 = 43; // IP6 routing header -pub const IPPROTO_FRAGMENT: i32 = 44; // IP6 fragmentation header -pub const IPPROTO_IDRP: i32 = 45; // InterDomain Routing -pub const IPPROTO_RSVP: i32 = 46; // resource reservation -pub const IPPROTO_GRE: i32 = 47; // General Routing Encap. -pub const IPPROTO_MHRP: i32 = 48; // Mobile Host Routing -pub const IPPROTO_BHA: i32 = 49; // BHA -pub const IPPROTO_ESP: i32 = 50; // IP6 Encap Sec. Payload -pub const IPPROTO_AH: i32 = 51; // IP6 Auth Header -pub const IPPROTO_INLSP: i32 = 52; // Integ. Net Layer Security -pub const IPPROTO_SWIPE: i32 = 53; // IP with encryption -pub const IPPROTO_NHRP: i32 = 54; // Next Hop Resolution - // 55-57: Unassigned -pub const IPPROTO_ICMPV6: i32 = 58; // ICMP6 -pub const IPPROTO_NONE: i32 = 59; // IP6 no next header -pub const IPPROTO_DSTOPTS: i32 = 60; // IP6 destination option -pub const IPPROTO_AHIP: i32 = 61; // any host internal protocol -pub const IPPROTO_CFTP: i32 = 62; // CFTP -pub const IPPROTO_HELLO: i32 = 63; // "hello" routing protocol -pub const IPPROTO_SATEXPAK: i32 = 64; // SATNET/Backroom EXPAK -pub const IPPROTO_KRYPTOLAN: i32 = 65; // Kryptolan -pub const IPPROTO_RVD: i32 = 66; // Remote Virtual Disk -pub const IPPROTO_IPPC: i32 = 67; // Pluribus Packet Core -pub const IPPROTO_ADFS: i32 = 68; // Any distributed FS -pub const IPPROTO_SATMON: i32 = 69; // Satnet Monitoring -pub const IPPROTO_VISA: i32 = 70; // VISA Protocol -pub const IPPROTO_IPCV: i32 = 71; // Packet Core Utility -pub const IPPROTO_CPNX: i32 = 72; // Comp. Prot. Net. Executive -pub const IPPROTO_CPHB: i32 = 73; // Comp. Prot. HeartBeat -pub const IPPROTO_WSN: i32 = 74; // Wang Span Network -pub const IPPROTO_PVP: i32 = 75; // Packet Video Protocol -pub const IPPROTO_BRSATMON: i32 = 76; // BackRoom SATNET Monitoring -pub const IPPROTO_ND: i32 = 77; // Sun net disk proto (temp.) -pub const IPPROTO_WBMON: i32 = 78; // WIDEBAND Monitoring -pub const IPPROTO_WBEXPAK: i32 = 79; // WIDEBAND EXPAK -pub const IPPROTO_EON: i32 = 80; // ISO cnlp -pub const IPPROTO_VMTP: i32 = 81; // VMTP -pub const IPPROTO_SVMTP: i32 = 82; // Secure VMTP -pub const IPPROTO_VINES: i32 = 83; // Banyon VINES -pub const IPPROTO_TTP: i32 = 84; // TTP -pub const IPPROTO_IGP: i32 = 85; // NSFNET-IGP -pub const IPPROTO_DGP: i32 = 86; // dissimilar gateway prot. -pub const IPPROTO_TCF: i32 = 87; // TCF -pub const IPPROTO_IGRP: i32 = 88; // Cisco/GXS IGRP -pub const IPPROTO_OSPFIGP: i32 = 89; // OSPFIGP -pub const IPPROTO_SRPC: i32 = 90; // Strite RPC protocol -pub const IPPROTO_LARP: i32 = 91; // Locus Address Resoloution -pub const IPPROTO_MTP: i32 = 92; // Multicast Transport -pub const IPPROTO_AX25: i32 = 93; // AX.25 Frames -pub const IPPROTO_IPEIP: i32 = 94; // IP encapsulated in IP -pub const IPPROTO_MICP: i32 = 95; // Mobile Int.ing control -pub const IPPROTO_SCCSP: i32 = 96; // Semaphore Comm. security -pub const IPPROTO_ETHERIP: i32 = 97; // Ethernet IP encapsulation -pub const IPPROTO_ENCAP: i32 = 98; // encapsulation header -pub const IPPROTO_APES: i32 = 99; // any private encr. scheme -pub const IPPROTO_GMTP: i32 = 100; // GMTP -pub const IPPROTO_PIM: i32 = 103; // Protocol Independent Mcast -pub const IPPROTO_IPCOMP: i32 = 108; // payload compression (IPComp) -pub const IPPROTO_PGM: i32 = 113; // PGM -pub const IPPROTO_SCTP: i32 = 132; // SCTP -pub const IPPROTO_DIVERT: i32 = 254; // divert pseudo-protocol -pub const IPPROTO_RAW: i32 = 255; // raw IP packet -pub const IPPROTO_MAX: i32 = 256; -// last return value of *_input(), meaning "all job for this pkt is done". -pub const IPPROTO_DONE: i32 = 257; - -pub const MSG_OOB: i32 = 1; -pub const MSG_PEEK: i32 = 2; -pub const MSG_DONTROUTE: i32 = 4; -pub const MSG_TRYHARD: i32 = 4; /* Synonym for MSG_DONTROUTE for DECnet */ -pub const MSG_CTRUNC: i32 = 8; -pub const MSG_PROBE: i32 = 0x10; /* Do not send. Only probe path f.e. for MTU */ -pub const MSG_TRUNC: i32 = 0x20; -pub const MSG_DONTWAIT: i32 = 0x40; /* Nonblocking io */ -pub const MSG_EOR: i32 = 0x80; /* End of record */ -pub const MSG_WAITALL: i32 = 0x100; /* Wait for a full request */ -pub const MSG_FIN: i32 = 0x200; -pub const MSG_SYN: i32 = 0x400; -pub const MSG_CONFIRM: i32 = 0x800; /* Confirm path validity */ -pub const MSG_RST: i32 = 0x1000; -pub const MSG_ERRQUEUE: i32 = 0x2000; /* Fetch message from error queue */ -pub const MSG_NOSIGNAL: i32 = 0x4000; /* Do not generate SIGPIPE */ -pub const MSG_MORE: i32 = 0x8000; /* Sender will send more */ -pub const MSG_WAITFORONE: i32 = 0x10000; /* recvmmsg(): block until 1+ packets avail */ -pub const MSG_SENDPAGE_NOPOLICY: i32 = 0x10000; /* sendpage() internal : do no apply policy */ -pub const MSG_SENDPAGE_NOTLAST: i32 = 0x20000; /* sendpage() internal : not the last page */ -pub const MSG_BATCH: i32 = 0x40000; /* sendmmsg(): more messages coming */ -pub const MSG_EOF: i32 = MSG_FIN; -pub const MSG_NO_SHARED_FRAGS: i32 = 0x80000; /* sendpage() internal : page frags are not shared */ -pub const MSG_SENDPAGE_DECRYPTED: i32 = 0x100000; /* sendpage() internal : page may carry - * plain text and require encryption - */ - -//shutdown -pub const SHUT_RD: i32 = 0; -pub const SHUT_WR: i32 = 1; -pub const SHUT_RDWR: i32 = 2; - -////////////////////// setsockopt / getsockopt... -pub const SOL_SOCKET: i32 = 1; - -pub const SO_DEBUG: i32 = 1; -pub const SO_REUSEADDR: i32 = 2; -pub const SO_TYPE: i32 = 3; -pub const SO_ERROR: i32 = 4; -pub const SO_DONTROUTE: i32 = 5; -pub const SO_BROADCAST: i32 = 6; -pub const SO_SNDBUF: i32 = 7; -pub const SO_RCVBUF: i32 = 8; -pub const SO_SNDBUFFORCE: i32 = 32; -pub const SO_RCVBUFFORCE: i32 = 33; -pub const SO_KEEPALIVE: i32 = 9; -pub const SO_OOBINLINE: i32 = 10; -pub const SO_NO_CHECK: i32 = 11; -pub const SO_PRIORITY: i32 = 12; -pub const SO_LINGER: i32 = 13; -pub const SO_BSDCOMPAT: i32 = 14; -pub const SO_REUSEPORT: i32 = 15; -pub const SO_PASSCRED: i32 = 16; -pub const SO_PEERCRED: i32 = 17; -pub const SO_RCVLOWAT: i32 = 18; -pub const SO_SNDLOWAT: i32 = 19; -pub const SO_RCVTIMEO_OLD: i32 = 20; -pub const SO_SNDTIMEO_OLD: i32 = 21; -pub const SO_PEERNAME: i32 = 28; -pub const SO_ACCEPTCONN: i32 = 30; - -// pub const SO_SECURITY_AUTHENTICATION: i32 = 22; -// pub const SO_SECURITY_ENCRYPTION_TRANSPORT: i32 = 23; -// pub const SO_SECURITY_ENCRYPTION_NETWORK: i32 = 24; - -// pub const SO_BINDTODEVICE: i32 = 25; - -// /* Socket filtering */ -// pub const SO_ATTACH_FILTER: i32 = 26; -// pub const SO_DETACH_FILTER: i32 = 27; - -// pub const SO_TIMESTAMP: i32 = 29; -// pub const SCM_TIMESTAMP: i32 = SO_TIMESTAMP; - -// pub const SO_PEERSEC: i32 = 31; -// pub const SO_PASSSEC: i32 = 34; -// pub const SO_TIMESTAMPNS: i32 = 35; -// pub const SCM_TIMESTAMPNS: i32 = SO_TIMESTAMPNS; - -// pub const SO_MARK: i32 = 36; - -// pub const SO_TIMESTAMPING: i32 = 37; -// pub const SCM_TIMESTAMPING: i32 = SO_TIMESTAMPING; - -// pub const SO_PROTOCOL: i32 = 38; -// pub const SO_DOMAIN: i32 = 39; - -// pub const SO_RXQ_OVFL: i32 = 40; - -// Use this to specify options on a socket. Use the protocol with setsockopt -// to specify something for all sockets with a protocol -pub const SOL_TCP: i32 = IPPROTO_TCP; -pub const SOL_UDP: i32 = IPPROTO_UDP; - -pub const TCP_NODELAY: i32 = 0x01; // don't delay send to coalesce packets -pub const TCP_MAXSEG: i32 = 0x02; // set maximum segment size -pub const TCP_NOPUSH: i32 = 0x04; // don't push last block of write -pub const TCP_NOOPT: i32 = 0x08; // don't use TCP options -pub const TCP_KEEPALIVE: i32 = 0x10; // idle time used when SO_KEEPALIVE is enabled -pub const TCP_CONNECTIONTIMEOUT: i32 = 0x20; // connection timeout -pub const PERSIST_TIMEOUT: i32 = 0x40; // time after which a connection in persist timeout - // will terminate. - // see draft-ananth-tcpm-persist-02.txt -pub const TCP_RXT_CONNDROPTIME: i32 = 0x80; // time after which tcp retransmissions will be - // stopped and the connection will be dropped -pub const TCP_RXT_FINDROP: i32 = 0x100; // When set, a connection is dropped after 3 FINs - -pub const MINSOCKOBJID: i32 = 0; -pub const MAXSOCKOBJID: i32 = 1024; - -//POLL CONSTANTS -pub const POLLIN: i16 = 0o1; // There is data to read. -pub const POLLPRI: i16 = 0o2; //There is urgent data to read. -pub const POLLOUT: i16 = 0o4; // Writing now will not block. -pub const POLLERR: i16 = 0o10; // Error condition. -pub const POLLHUP: i16 = 0o20; // Hung up. -pub const POLLNVAL: i16 = 0o40; // Invalid polling request. - -//EPOLL CONSTANTS -pub const EPOLLIN: i32 = 0x001; -pub const EPOLLPRI: i32 = 0x002; -pub const EPOLLOUT: i32 = 0x004; -pub const EPOLLRDNORM: i32 = 0x040; -pub const EPOLLRDBAND: i32 = 0x080; -pub const EPOLLWRNORM: i32 = 0x100; -pub const EPOLLWRBAND: i32 = 0x200; -pub const EPOLLMSG: i32 = 0x400; -pub const EPOLLERR: i32 = 0x008; -pub const EPOLLHUP: i32 = 0x010; -pub const EPOLLRDHUP: i32 = 0x2000; -pub const EPOLLWAKEUP: i32 = 1 << 29; -pub const EPOLLONESHOT: i32 = 1 << 30; -pub const EPOLLET: i32 = 1 << 31; - -pub const EPOLL_CTL_ADD: i32 = 1; -pub const EPOLL_CTL_DEL: i32 = 2; -pub const EPOLL_CTL_MOD: i32 = 3; - -pub const FD_SET_MAX_FD: i32 = 1024; - -//for internal use -#[derive(Debug, PartialEq, Eq, Clone)] -pub enum ConnState { - NOTCONNECTED, - CONNECTED, - CONNRDONLY, - CONNWRONLY, - LISTEN, - INPROGRESS, -} diff --git a/src/RawPOSIX/src/safeposix/syscalls/sys_calls.rs b/src/RawPOSIX/src/safeposix/syscalls/sys_calls.rs index f2659924..c45e02ad 100644 --- a/src/RawPOSIX/src/safeposix/syscalls/sys_calls.rs +++ b/src/RawPOSIX/src/safeposix/syscalls/sys_calls.rs @@ -1,10 +1,19 @@ #![allow(dead_code)] // System related system calls -use super::fs_constants::*; -use super::net_constants::*; -use super::sys_constants; -use super::sys_constants::*; +use crate::constants::{ + DEFAULT_UID, DEFAULT_GID, + SIG_BLOCK, SIG_UNBLOCK, SIG_SETMASK, + SIGNAL_MAX, + ITIMER_REAL, + RLIMIT_NOFILE, RLIMIT_STACK, + NOFILE_CUR, NOFILE_MAX, + STACK_CUR, STACK_MAX, + SHMMIN, SHMMAX, + SHM_RDONLY, SHM_DEST, + SEM_VALUE_MAX, +}; + use crate::interface; use crate::safeposix::cage; use crate::safeposix::cage::*; @@ -518,7 +527,7 @@ impl Cage { if let Some(some_set) = set { let curr_sigset = sigset.load(interface::RustAtomicOrdering::Relaxed); res = match how { - cage::SIG_BLOCK => { + SIG_BLOCK => { // Block signals in set sigset.store( curr_sigset | *some_set, @@ -526,7 +535,7 @@ impl Cage { ); 0 } - cage::SIG_UNBLOCK => { + SIG_UNBLOCK => { // Unblock signals in set let newset = curr_sigset & !*some_set; let pendingsignals = curr_sigset & some_set; @@ -534,7 +543,7 @@ impl Cage { self.send_pending_signals(pendingsignals, pthreadid); 0 } - cage::SIG_SETMASK => { + SIG_SETMASK => { // Set sigset to set sigset.store(*some_set, interface::RustAtomicOrdering::Relaxed); 0 @@ -552,7 +561,7 @@ impl Cage { old_value: Option<&mut interface::ITimerVal>, ) -> i32 { match which { - sys_constants::ITIMER_REAL => { + ITIMER_REAL => { if let Some(some_old_value) = old_value { let (curr_duration, next_duration) = self.interval_timer.get_itimer(); some_old_value.it_value.tv_sec = curr_duration.as_secs() as i64; @@ -582,11 +591,11 @@ impl Cage { pub fn getrlimit(&self, res_type: u64, rlimit: &mut interface::Rlimit) -> i32 { match res_type { - sys_constants::RLIMIT_NOFILE => { + RLIMIT_NOFILE => { rlimit.rlim_cur = NOFILE_CUR; rlimit.rlim_max = NOFILE_MAX; } - sys_constants::RLIMIT_STACK => { + RLIMIT_STACK => { rlimit.rlim_cur = STACK_CUR; rlimit.rlim_max = STACK_MAX; } @@ -597,7 +606,7 @@ impl Cage { pub fn setrlimit(&self, res_type: u64, _limit_value: u64) -> i32 { match res_type { - sys_constants::RLIMIT_NOFILE => { + RLIMIT_NOFILE => { if NOFILE_CUR > NOFILE_MAX { -1 } else { diff --git a/src/RawPOSIX/src/safeposix/syscalls/sys_constants.rs b/src/RawPOSIX/src/safeposix/syscalls/sys_constants.rs deleted file mode 100644 index 89feb715..00000000 --- a/src/RawPOSIX/src/safeposix/syscalls/sys_constants.rs +++ /dev/null @@ -1,77 +0,0 @@ -// System related constants -#![allow(dead_code)] -#![allow(unused_variables)] - -use crate::interface; - -// Define constants using static or const -// Imported into fs_calls file - -//GID AND UID DEFAULT VALUES - -pub const DEFAULT_UID: u32 = 1000; -pub const DEFAULT_GID: u32 = 1000; - -// RESOURCE LIMITS - -pub const SIGNAL_MAX: i32 = 64; - -pub const NOFILE_CUR: u64 = 1024; -pub const NOFILE_MAX: u64 = 4 * 1024; - -pub const STACK_CUR: u64 = 8192 * 1024; -pub const STACK_MAX: u64 = 1 << 32; - -pub const RLIMIT_STACK: u64 = 0; -pub const RLIMIT_NOFILE: u64 = 1; - -// Constants for exit_syscall status - -pub const EXIT_SUCCESS: i32 = 0; -pub const EXIT_FAILURE: i32 = 1; - -// Signal Table (x86/ARM) -// Based on https://man7.org/linux/man-pages/man7/signal.7.html -pub const SIGHUP: i32 = 1; -pub const SIGINT: i32 = 2; -pub const SIGQUIT: i32 = 3; -pub const SIGILL: i32 = 4; -pub const SIGTRAP: i32 = 5; -pub const SIGABRT: i32 = 6; -pub const SIGIOT: i32 = 6; -pub const SIGBUS: i32 = 7; -// pub const SIGEMT: i32 -pub const SIGFPE: i32 = 8; -pub const SIGKILL: i32 = 9; -pub const SIGUSR1: i32 = 10; -pub const SIGSEGV: i32 = 11; -pub const SIGUSR2: i32 = 12; -pub const SIGPIPE: i32 = 13; -pub const SIGALRM: i32 = 14; -pub const SIGTERM: i32 = 15; -pub const SIGSTKFLT: i32 = 16; -pub const SIGCHLD: i32 = 17; -// pub const SIGCLD: i32 -pub const SIGCONT: i32 = 18; -pub const SIGSTOP: i32 = 19; -pub const SIGTSTP: i32 = 20; -pub const SIGTTIN: i32 = 21; -pub const SIGTTOU: i32 = 22; -pub const SIGURG: i32 = 23; -pub const SIGXCPU: i32 = 24; -pub const SIGXFSZ: i32 = 25; -pub const SIGVTALRM: i32 = 26; -pub const SIGPROF: i32 = 27; -pub const SIGWINCH: i32 = 28; -pub const SIGIO: i32 = 29; -pub const SIGPOLL: i32 = 29; -pub const SIGPWR: i32 = 30; -// pub const SIGINFO: i32 -// pub const SIGLOST: i32 -pub const SIGSYS: i32 = 31; -pub const SIGUNUSED: i32 = 31; - -pub const SIG_BLOCK: i32 = 0; -pub const SIG_UNBLOCK: i32 = 1; -pub const SIG_SETMASK: i32 = 2; -pub const ITIMER_REAL: i32 = 0; diff --git a/src/RawPOSIX/src/safeposix/vmmap.rs b/src/RawPOSIX/src/safeposix/vmmap.rs index 08ae0d1d..7e2eface 100644 --- a/src/RawPOSIX/src/safeposix/vmmap.rs +++ b/src/RawPOSIX/src/safeposix/vmmap.rs @@ -1,4 +1,8 @@ -use super::vmmap_constants::*; +use crate::constants::{ + PROT_NONE, PROT_READ, PROT_WRITE, PROT_EXEC, + MAP_SHARED, MAP_PRIVATE, MAP_FIXED, MAP_ANONYMOUS, + MAP_FAILED +}; use std::io; use nodit::NoditMap; use nodit::{interval::ie, Interval}; @@ -67,7 +71,7 @@ impl VmmapEntry { // this is effectively whatever mode the file was opened with // we need this because we shouldnt be able to change filed backed mappings // to have protections exceeding that of the file - fn get_max_prot(&self, cage_id: u64, virtual_fd: u64 -> i32 { + fn get_max_prot(&self, cage_id: u64, virtual_fd: u64) -> i32 { let wrappedvfd = fdtables::translate_virtual_fd(cage_id, virtual_fd as u64); if wrappedvfd.is_err() { diff --git a/src/RawPOSIX/src/safeposix/vmmap_constants.rs b/src/RawPOSIX/src/safeposix/vmmap_constants.rs deleted file mode 100644 index 373dba64..00000000 --- a/src/RawPOSIX/src/safeposix/vmmap_constants.rs +++ /dev/null @@ -1,32 +0,0 @@ -pub const PROT_READ: i32 = 0x1; /* Page can be read. */ -pub const PROT_WRITE: i32 = 0x2; /* Page can be written. */ -pub const PROT_EXEC: i32 = 0x4; /* Page can be executed. */ -pub const PROT_NONE: i32 = 0x0; /* Page can not be accessed. */ - -pub const PROT_MASK: u32 = 0x7; - -pub const MAP_SHARED: u32 = 0x01; /* Share changes. */ -pub const MAP_PRIVATE: u32 = 0x02; /* Changes are private. */ - -/* this must be a multiple of the system page size */ -pub const PAGESHIFT: u32 = 12; -pub const PAGESIZE: u32 = 1 << PAGESHIFT; - -pub const MAP_PAGESHIFT: u32 = 16; -pub const MAP_PAGESIZE: u32 = 1 << MAP_PAGESHIFT; - -pub const MAP_SHARING_MASK: u32 = 0x03; - -pub const MAP_FIXED: u32 = 0x10; /* Interpret addr exactly. */ -pub const MAP_ANON: u32 = 0x20; /* Don't use a file. */ -pub const MAP_ANONYMOUS: u32 = MAP_ANON; /* Linux alias. */ - -pub const MAP_FAILED: *mut std::ffi::c_void = (-1isize) as *mut std::ffi::c_void; - -pub const MREMAP_MAYMOVE: u32 = 0x01; -pub const MREMAP_FIXED: u32 = 0x02; - -pub const O_ACCMODE: i32 = 0003; -pub const O_RDONLY: i32 = 00; -pub const O_WRONLY: i32 = 01; -pub const O_RDWR: i32 = 02; diff --git a/src/RawPOSIX/src/tests/sys_tests.rs b/src/RawPOSIX/src/tests/sys_tests.rs index 5d3bbb1d..22260b38 100644 --- a/src/RawPOSIX/src/tests/sys_tests.rs +++ b/src/RawPOSIX/src/tests/sys_tests.rs @@ -6,6 +6,7 @@ pub mod sys_tests { use super::super::*; use crate::interface; + use crate::constants::DEFAULT_UID; // use crate::safeposix::cage::{FileDescriptor::*, *}; use crate::safeposix::{cage::*, dispatcher::*, filesystem};