Sync computers

This commit is contained in:
2026-03-17 18:29:00 +01:00
parent 404a681254
commit 56a00d0403
34 changed files with 2578 additions and 257 deletions

View File

@@ -10,9 +10,12 @@ pub enum SysCall {
Read = 0,
Write = 1,
Open = 2,
Close = 3,
Seek = 8,
Alloc = 40,
Dealloc = 41,
Spawn = 58,
ExecVE = 59,
Exit = 60,
NanoSleep = 101,
WriteIntTemp = 998,
@@ -26,9 +29,12 @@ impl From<u64> for SysCall {
0 => SysCall::Read,
1 => SysCall::Write,
2 => SysCall::Open,
3 => SysCall::Close,
8 => SysCall::Seek,
40 => SysCall::Alloc,
41 => SysCall::Dealloc,
58 => SysCall::Spawn,
59 => SysCall::ExecVE,
60 => SysCall::Exit,
101 => SysCall::NanoSleep,
998 => SysCall::WriteIntTemp,
@@ -143,30 +149,53 @@ pub fn open<P: AsRef<Path>>(path: P) -> File {
let ptr = path_str.as_ptr();
let size = path_str.len();
let (fd, ..) = syscall!(SysCall::Open, ptr as u64, size as u64);
File::new(fd)
File::from_raw_fd(fd)
}
}
pub fn write(file: &mut File, buf: &[u8]) {
pub fn close(file_descriptor: u64) {
unsafe {
syscall!(SysCall::Close, file_descriptor);
}
}
pub fn write(file_descriptor: u64, buf: &[u8]) -> u64 {
unsafe {
let ptr = buf.as_ptr();
let size = buf.len();
syscall!(SysCall::Write, file.as_fd(), ptr as u64, size as u64);
let (len, ..) = syscall!(SysCall::Write, file_descriptor, ptr as u64, size as u64);
len
}
}
pub fn read(file: &mut File, buf: &mut [u8]) {
pub fn read(file_descriptor: u64, buf: &mut [u8]) -> u64 {
unsafe {
let ptr = buf.as_ptr();
let size = buf.len();
syscall!(SysCall::Read, file.as_fd(), ptr as u64, size as u64);
let (len, ..) = syscall!(SysCall::Read, file_descriptor, ptr as u64, size as u64);
len
}
}
pub fn seek(file: &mut File, seek: SeekFrom) {
pub fn seek(file_descriptor: u64, seek: SeekFrom) {
unsafe {
let (discriminant, value) = match seek {
SeekFrom::Start(v) => (0, v),
SeekFrom::End(v) => (1, v as u64),
SeekFrom::Current(v) => (2, v as u64),
};
syscall!(SysCall::Seek, file.as_fd(), discriminant, value);
syscall!(SysCall::Seek, file_descriptor, discriminant, value);
}
}
pub fn spawn<P: AsRef<Path>>(path: P) {
unsafe {
let path_str = path.as_ref().as_str();
let ptr = path_str.as_ptr();
let size = path_str.len();
syscall!(SysCall::Spawn, ptr as u64, size as u64);
}
}
pub fn execve<P: AsRef<Path>>(path: P) {
unsafe {
let path_str = path.as_ref().as_str();
let ptr = path_str.as_ptr();
let size = path_str.len();
syscall!(SysCall::ExecVE, ptr as u64, size as u64);
}
}