libsel4utils: Remove long running cnode cap deletion Walking the entire cnode and deleting call the caps was done to ensure there were no self references left that would keep the object alive. A more efficient way is to revoke the cnode capability, which will delete any children, allowing the cnode to be cleaned up by the kernel instead.
diff --git a/libsel4utils/src/process.c b/libsel4utils/src/process.c index 42841cd..54475ec 100644 --- a/libsel4utils/src/process.c +++ b/libsel4utils/src/process.c
@@ -697,23 +697,20 @@ void sel4utils_destroy_process(sel4utils_process_t *process, vka_t *vka) { - /* delete all of the caps in the cspace */ - for (int i = 1; i < BIT(CONFIG_SEL4UTILS_CSPACE_SIZE_BITS);i++){ + /* destroy the cnode */ + if (process->own_cspace) { cspacepath_t path; - path.root = process->cspace.cptr; - path.capPtr = i; - path.capDepth = process->cspace_size; - vka_cnode_delete(&path); + vka_cspace_make_path(vka, process->cspace.cptr, &path); + /* need to revoke the cnode to remove any self references that would keep the object + * alive when we try to delete it */ + vka_cnode_revoke(&path); + vka_free_object(vka, &process->cspace); } + /* destroy the thread */ sel4utils_clean_up_thread(vka, &process->vspace, &process->thread); - /* destroy the cnode */ - if (process->own_cspace) { - vka_free_object(vka, &process->cspace); - } - /* tear down the vspace */ if (process->own_vspace) { vspace_tear_down(&process->vspace, VSPACE_FREE);