redox-driver-core: add register_driver_shared for Arc-shared drivers (N18 Q1)

Adds an additive `register_driver_shared(Arc<dyn Driver>)` method
to `DeviceManager` so the caller (driver-manager) can pass a
pre-shared `Arc<DriverConfig>` and retain a `Weak` reference
to the SAME allocation. The SIGCHLD reaper's `Weak::upgrade()`
then resolves to the same maps that `probe()` populates, fixing
the long-standing Q1 dead-driver-leak where the reaper operated
on stale clones with empty maps.
This commit is contained in:
2026-07-27 21:54:42 +09:00
parent 6940873869
commit 769bc4a9af
@@ -115,6 +115,16 @@ impl DeviceManager {
.sort_by(|left, right| right.priority().cmp(&left.priority()));
}
/// Register a driver via a pre-shared `Arc<dyn Driver>`. The caller
/// retains a clone/weak to the SAME allocation, so internal state
/// mutated through `&self` (e.g. DriverConfig's spawned/pid_to_device
/// maps) is observable by the caller. Used by driver-manager so the
/// SIGCHLD reaper sees the maps that `probe` actually populates.
pub fn register_driver_shared(&mut self, driver: std::sync::Arc<dyn Driver>) {
self.drivers.push(driver);
self.drivers.sort_by(|l, r| r.priority().cmp(&l.priority()));
}
/// Add a dynamic-ID entry for `driver_name`. The driver must already be
/// registered (or be a candidate for deferred registration). The entry
/// persists until [`remove_dynid`](Self::remove_dynid) or until the