kernel: handle: implement handle_table_destroy()

This commit is contained in:
2026-03-18 20:55:35 +00:00
parent c0e212ac98
commit 04d05adbe8

View File

@@ -12,7 +12,7 @@
#define RESERVED_HANDLES 64 #define RESERVED_HANDLES 64
static struct vm_cache handle_table_cache = { static struct vm_cache handle_table_cache = {
.c_name = "handle_table", .c_name = "handle-table",
.c_obj_size = sizeof(struct handle_table), .c_obj_size = sizeof(struct handle_table),
}; };
@@ -33,8 +33,48 @@ struct handle_table *handle_table_create(void)
return out; return out;
} }
static void do_handle_table_destroy_leaf(struct handle_table *tab)
{
while (1) {
unsigned int index = bitmap_lowest_set(
tab->t_handles.t_handle_map,
HANDLES_PER_TABLE);
if (index == BITMAP_NPOS) {
break;
}
struct handle *child = &tab->t_handles.t_handle_list[index];
bitmap_clear(tab->t_subtables.t_subtable_map, index);
if (child->h_object) {
object_remove_handle(child->h_object);
child->h_object = NULL;
}
}
}
static void do_handle_table_destroy(
struct handle_table *tab,
unsigned int depth)
{
if (depth == MAX_TABLE_DEPTH - 1) {
do_handle_table_destroy_leaf(tab);
return;
}
for (size_t i = 0; i < REFS_PER_TABLE; i++) {
struct handle_table *child
= tab->t_subtables.t_subtable_list[i];
if (child) {
do_handle_table_destroy(child, depth + 1);
}
}
vm_cache_free(&handle_table_cache, tab);
}
void handle_table_destroy(struct handle_table *tab) void handle_table_destroy(struct handle_table *tab)
{ {
do_handle_table_destroy(tab, 0);
} }
static kern_status_t decode_handle_indices( static kern_status_t decode_handle_indices(