WIP: use upper fd table

This commit is contained in:
Jeremy Soller
2025-11-14 12:31:48 -07:00
parent 74e3ad1c2c
commit 0844e6fc90
25 changed files with 404 additions and 451 deletions
+4 -1
View File
@@ -419,7 +419,10 @@ unsafe fn find_env(search: *const c_char) -> Option<(usize, *mut c_char)> {
let mut search = search;
loop {
let end_of_query = *search == 0 || *search == b'=' as c_char;
assert_ne!(*item, 0, "environ has an item without value");
if *item == 0 {
//TODO: environ has an item without value, is this a problem?
break;
}
if *item == b'=' as c_char || end_of_query {
if *item == b'=' as c_char && end_of_query {
// Both keys env here
+5 -11
View File
@@ -41,17 +41,13 @@ pub const SIOCATMARK: c_ulong = 0x8905;
// TODO: some of the structs passed as T have padding bytes, so casting to a byte slice is UB
fn dup_read<T>(fd: c_int, name: &str, t: &mut T) -> syscall::Result<usize> {
let dup = syscall::dup(fd as usize, name.as_bytes())?;
let dup = FdGuard::new(syscall::dup(fd as usize, name.as_bytes())?);
let size = mem::size_of::<T>();
let res = syscall::read(dup, unsafe {
slice::from_raw_parts_mut(t as *mut T as *mut u8, size)
});
let bytes = dup.read(unsafe { slice::from_raw_parts_mut(t as *mut T as *mut u8, size) })?;
let _ = syscall::close(dup);
res.map(|bytes| bytes / size)
Ok(bytes / size)
}
// FIXME: unsound
@@ -60,11 +56,9 @@ fn dup_write<T>(fd: c_int, name: &str, t: &T) -> Result<usize> {
let size = mem::size_of::<T>();
let bytes_written = syscall::write(*dup, unsafe {
slice::from_raw_parts(t as *const T as *const u8, size)
})?;
let bytes = dup.write(unsafe { slice::from_raw_parts(t as *const T as *const u8, size) })?;
Ok(bytes_written / size)
Ok(bytes / size)
}
unsafe fn ioctl_inner(fd: c_int, request: c_ulong, out: *mut c_void) -> Result<c_int> {