Add the rust std as a custom sysroot

This commit is contained in:
2026-03-17 18:29:00 +01:00
parent 404a681254
commit fadecc7c95
47 changed files with 806 additions and 320 deletions

View File

@@ -1,3 +1,7 @@
use io::{IoBase, Read, Write};
use crate::syscall;
#[derive(Debug)]
pub struct File {
fd: u64,
@@ -6,7 +10,7 @@ pub struct File {
impl File {
/// # Safety
/// The file descriptor must be valid
pub unsafe fn new(fd: u64) -> Self {
pub unsafe fn from_raw_fd(fd: u64) -> Self {
Self { fd }
}
@@ -14,3 +18,23 @@ impl File {
self.fd
}
}
impl IoBase for File {
type Error = ();
}
impl Read for File {
fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error> {
Ok(syscall::read(self.as_fd(), buf) as usize)
}
}
impl Write for File {
fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error> {
Ok(syscall::write(self.as_fd(), buf) as usize)
}
fn flush(&mut self) -> Result<(), Self::Error> {
todo!()
}
}