kernel: a grant is a loan — a dead borrower returns the device to its lender
When a driver dies, a device it was *given* now goes back to whoever lent it, rather than to nobody. The device manager gets its hardware back the instant a driver dies and hands it to the replacement, with no window in between. That window was real: the kernel released the claim to no one and the manager re-claimed first-come, so every driver restart reopened the hole this run is closing. It also becomes load-bearing at the next step — once claim refuses a device that has a giver, releasing to nobody would strand a dead driver's hardware permanently, because nobody could ever take it again. A dead lender is no lender: the claim and the giver clear together, so a device is never owed to a ghost. A device nobody lent is released outright, exactly as before. The broker cannot see the task table, so liveness arrives through the same hook idiom the scheduler already uses. Null means assume dead, so a kernel built without the hook frees claims rather than handing them to a ghost. A stale binary nearly passed as proof for the third time this session: the first discrimination patch left `alive` unused, the build failed with three errors, and the old binary reported every assertion passing. Checking the build before reading results is what caught it. Suite 118/118.
This commit is contained in:
@@ -190,6 +190,15 @@ pub fn init() void {
|
||||
scheduler.timer_tick_hook = timerSweepLocked;
|
||||
scheduler.group_exit_hook = groupExitLocked;
|
||||
scheduler.space_mapping_release_hook = dropSpaceMappingHook;
|
||||
// The broker owns devices; the process layer owns the task table. It asks whether a
|
||||
// lender is still alive before handing a dead driver's device back to it.
|
||||
devices_broker.task_alive_hook = taskAliveLocked;
|
||||
}
|
||||
|
||||
/// Whether `id` names a live task. The broker calls this through its hook when
|
||||
/// deciding if a dead holder's device can go back to the task that lent it.
|
||||
fn taskAliveLocked(id: u32) bool {
|
||||
return scheduler.taskByIdLocked(id) != null;
|
||||
}
|
||||
|
||||
/// Return -1 (as an unsigned bit pattern) in the system_call result register.
|
||||
|
||||
Reference in New Issue
Block a user