Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Porting VMMAP to RawPOSIX #56

Open
wants to merge 58 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
d9a3ba8
Changes from vmmap alice rawposix
ChinmayShringi Nov 25, 2024
5b13d4c
fix: revert removed lines
ChinmayShringi Nov 25, 2024
70fa146
fix: formatting
ChinmayShringi Nov 25, 2024
5a3ebbb
fix: rm new line
ChinmayShringi Nov 25, 2024
ef9e7ad
feat: new constants folder
ChinmayShringi Nov 25, 2024
a19b268
Merge pull request #57 from Lind-Project/feat-constants-fs
rennergade Nov 26, 2024
38d8a32
feat: update from raw-posix
ChinmayShringi Dec 4, 2024
bd567d7
fix: rm commented import
ChinmayShringi Dec 4, 2024
4114b0f
Merge branch 'main' into vmmap-alice
ChinmayShringi Dec 4, 2024
5190179
refactor: rm commented imports
ChinmayShringi Dec 4, 2024
7a39e8a
refactor: rm comments
ChinmayShringi Dec 4, 2024
b430229
feat: add check_and_convert_addr
ChinmayShringi Dec 9, 2024
4189fcf
feat: update cage in syscall
ChinmayShringi Dec 10, 2024
a6502f6
feat: added check addr convert comment
ChinmayShringi Dec 10, 2024
63879ba
feat: add comments
ChinmayShringi Dec 10, 2024
aaf64ab
Merge branch 'main' into vmmap-alice
Yaxuan-w Dec 16, 2024
23e500e
feat: build fixes
ChinmayShringi Dec 21, 2024
d9e67e1
feat: fixed build errors
ChinmayShringi Dec 21, 2024
d072008
feat: removed pendingsigset
ChinmayShringi Dec 21, 2024
ee7fd89
integrate mmap into pthread
qianxichen233 Dec 26, 2024
6172411
Merge branch 'fix-pthread' into mmap-impl
qianxichen233 Dec 26, 2024
d126835
Syscall security nacl alignment (#70)
ChinmayShringi Dec 28, 2024
aeb0ed0
fix: remove comments
ChinmayShringi Dec 29, 2024
eb9338a
fix: rm security
ChinmayShringi Dec 29, 2024
7ff9858
fix: rm todo
ChinmayShringi Dec 29, 2024
29d1d1d
revert: err panic
ChinmayShringi Dec 29, 2024
a244d12
fix: revert todo
ChinmayShringi Dec 29, 2024
f184378
fix: rm nacl comments
ChinmayShringi Dec 29, 2024
d3eeed3
fix: removed nacl
ChinmayShringi Dec 29, 2024
668dbc7
rm: space
ChinmayShringi Dec 29, 2024
67c1a5c
fix: rm interface:cage
ChinmayShringi Dec 29, 2024
5b70b4d
implement program break/integrate with glibc/implement file backed mmap
qianxichen233 Dec 29, 2024
2bfddcc
Merge branch 'fix-pthread' into mmap-impl
qianxichen233 Dec 29, 2024
c5b75a6
fix: rm interface
ChinmayShringi Dec 29, 2024
5dab647
feat: added address check
ChinmayShringi Dec 29, 2024
e86a5d6
feat: removed warnings
ChinmayShringi Dec 29, 2024
85e5e3e
revert: fxstat error
ChinmayShringi Dec 29, 2024
3d725af
Revert "feat: removed warnings"
ChinmayShringi Dec 29, 2024
b391388
rm: duplicate comment
ChinmayShringi Dec 30, 2024
c3ed5e0
Merge branch 'main' into vmmap-alice
qianxichen233 Dec 30, 2024
153836f
Merge branch 'main' into mmap-impl
qianxichen233 Dec 30, 2024
8381c85
Merge branch 'vmmap-alice' into mmap-impl
qianxichen233 Dec 30, 2024
27adcc3
clean up
qianxichen233 Dec 30, 2024
b9d6000
update comment
qianxichen233 Dec 30, 2024
9cdecd4
added test file for mmap and sbrk
qianxichen233 Dec 30, 2024
851ce5f
fixed incorrect handle of 32bit address
qianxichen233 Jan 3, 2025
1a23771
added some memory tests
qianxichen233 Jan 3, 2025
c617d91
Merge pull request #74 from Lind-Project/mmap-impl
rennergade Jan 5, 2025
a180b42
revert: max bound check
ChinmayShringi Jan 5, 2025
33d8184
Merge branch 'vmmap-alice' into syscall-security-nacl-alignment-squash
ChinmayShringi Jan 5, 2025
1ed0144
Merge pull request #71 from Lind-Project/syscall-security-nacl-alignm…
rennergade Jan 6, 2025
ac43ab3
fix: build errors return type
ChinmayShringi Jan 8, 2025
6b66c06
fix: resolved PR commets
ChinmayShringi Jan 8, 2025
61d75eb
fix: test case errors
ChinmayShringi Jan 9, 2025
6ba2660
feat: rm UDSOCK_CAPACITY from const
ChinmayShringi Jan 9, 2025
05f9fc7
fixed initial memory size
qianxichen233 Jan 10, 2025
0df98fa
Merge branch 'main' into vmmap-alice
ChinmayShringi Jan 14, 2025
1b7a811
fix: fixed build errors
ChinmayShringi Jan 15, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/RawPOSIX/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ ringbuf = "0.2.6"
dashmap = { version = "5.1", features=["serde"] }
parking_lot = "0.12"
bit-set = "0.5"
nodit = "0.9.2" # Used for VMMAP
quick_cache = "0.6.9"

[dependencies.lazy_static]
version = "1.0"
Expand Down
202 changes: 202 additions & 0 deletions src/RawPOSIX/src/constants/fs_constants.rs
Original file line number Diff line number Diff line change
@@ -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;
ChinmayShringi marked this conversation as resolved.
Show resolved Hide resolved

// ===== 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
ChinmayShringi marked this conversation as resolved.
Show resolved Hide resolved
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
7 changes: 7 additions & 0 deletions src/RawPOSIX/src/constants/mod.rs
Original file line number Diff line number Diff line change
@@ -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::*;
Loading