From 769bc4a9af310ebf462d831edd68eb39cd90ec52 Mon Sep 17 00:00:00 2001 From: vasilito Date: Mon, 27 Jul 2026 21:54:42 +0900 Subject: [PATCH] redox-driver-core: add register_driver_shared for Arc-shared drivers (N18 Q1) Adds an additive `register_driver_shared(Arc)` method to `DeviceManager` so the caller (driver-manager) can pass a pre-shared `Arc` 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. --- .../drivers/redox-driver-core/source/src/manager.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/local/recipes/drivers/redox-driver-core/source/src/manager.rs b/local/recipes/drivers/redox-driver-core/source/src/manager.rs index 90435710fd..002082dea4 100644 --- a/local/recipes/drivers/redox-driver-core/source/src/manager.rs +++ b/local/recipes/drivers/redox-driver-core/source/src/manager.rs @@ -115,6 +115,16 @@ impl DeviceManager { .sort_by(|left, right| right.priority().cmp(&left.priority())); } + /// Register a driver via a pre-shared `Arc`. 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) { + 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