bootstrap: migrate openat_with_filter→openat_into, unlinkat_with_filter→unlinkat

This commit is contained in:
Red Bear OS
2026-07-08 00:49:20 +03:00
parent 0f53316100
commit 75950f10a8
3 changed files with 20 additions and 7 deletions
+4 -4
View File
@@ -173,13 +173,13 @@ impl<'sock> NamespaceScheme<'sock> {
return Err(Error::new(ENODEV));
};
let scheme_fd = syscall::openat_with_filter(
let reserved = syscall::reserve_fd(1)?;
let scheme_fd = syscall::openat_into(
cap_fd.as_raw_fd(),
reserved,
reference,
flags,
fcntl_flags as usize,
ctx.uid,
ctx.gid,
)?;
Ok(scheme_fd)
@@ -353,7 +353,7 @@ impl<'sock> SchemeSync for NamespaceScheme<'sock> {
return Err(Error::new(ENODEV));
};
syscall::unlinkat_with_filter(cap_fd.as_raw_fd(), reference, flags, ctx.uid, ctx.gid)?;
syscall::unlinkat(cap_fd.as_raw_fd(), reference, flags)?;
Ok(())
}
+13 -1
View File
@@ -305,9 +305,10 @@ pub struct Xhci<const N: usize> {
device_enumerator: Mutex<Option<thread::JoinHandle<()>>>,
device_enumerator_sender: Sender<DeviceEnumerationRequest>,
device_enumerator_receiver: Receiver<DeviceEnumerationRequest>,
dma_pool: Mutex<Vec<Dma<[u8]>>>,
}
}
// SAFETY: Xhci<N> contains the following fields with their safety mechanisms:
// - `port_states`, `handles`, `drivers`: CHashMap (per-key interior locking)
// - `op`, `ports`, `cmd`, `run`, `primary_event_ring`: Mutex<...>
@@ -501,6 +502,7 @@ impl<const N: usize> Xhci<N> {
device_enumerator: Mutex::new(None),
device_enumerator_sender,
device_enumerator_receiver,
dma_pool: Mutex::new(Vec::new()),
};
xhci.init(max_slots)?;
@@ -1074,6 +1076,16 @@ impl<const N: usize> Xhci<N> {
Self::alloc_dma_zeroed_unsized_raw(self.ac64_effective(), count)
}
fn dma_pool_take(&self, size: usize) -> Option<Dma<[u8]>> {
let mut pool = self.dma_pool.lock().unwrap_or_else(|e| e.into_inner());
pool.iter().position(|b| b.len() >= size).map(|i| pool.swap_remove(i))
}
fn dma_pool_put(&self, buf: Dma<[u8]>) {
const MAX_POOL: usize = 32;
let mut pool = self.dma_pool.lock().unwrap_or_else(|e| e.into_inner());
if pool.len() < MAX_POOL { pool.push(buf); }
}
pub async fn attach_device(&self, port_id: PortId) -> syscall::Result<()> {
if self.port_states.contains_key(&port_id) {
debug!("Already contains port {}", port_id);
+3 -2
View File
@@ -2080,8 +2080,9 @@ impl<const N: usize> Xhci<N> {
// TODO: Validate the size.
// TODO: Sizes above 65536, *perhaps*.
let data_buffer_opt = if req.transfers_data {
let data_buffer = unsafe { self.alloc_dma_zeroed_unsized(req.length as usize)? };
assert_eq!(data_buffer.len(), req.length as usize);
let data_buffer = self.dma_pool_take(req.length as usize).unwrap_or_else(|| unsafe {
self.alloc_dma_zeroed_unsized(req.length as usize).expect("DMA alloc")
});
Some(data_buffer)
} else {
None