kernel: handle: add support for allocating a specific handle value

This commit is contained in:
2026-03-29 11:47:22 +01:00
parent dfffb45e66
commit 537242e606
5 changed files with 63 additions and 3 deletions
+50 -1
View File
@@ -109,7 +109,7 @@ static kern_status_t encode_handle_indices(
return KERN_OK;
}
kern_status_t handle_table_alloc_handle(
static kern_status_t alloc_handle(
struct handle_table *tab,
struct handle **out_slot,
kern_handle_t *out_handle)
@@ -164,6 +164,53 @@ kern_status_t handle_table_alloc_handle(
return encode_handle_indices(indices, out_handle);
}
kern_status_t handle_table_alloc_handle(
struct handle_table *tab,
kern_handle_t value,
struct handle **out_slot,
kern_handle_t *out_handle)
{
if (value == KERN_HANDLE_INVALID) {
return alloc_handle(tab, out_slot, out_handle);
}
unsigned int indices[MAX_TABLE_DEPTH];
if (decode_handle_indices(value, indices) != KERN_OK) {
return KERN_HANDLE_INVALID;
}
int i;
for (i = 0; i < MAX_TABLE_DEPTH - 1; i++) {
struct handle_table *next
= tab->t_subtables.t_subtable_list[indices[i]];
if (!next) {
next = handle_table_create();
tab->t_subtables.t_subtable_list[indices[i]] = next;
}
if (!next) {
return KERN_NO_MEMORY;
}
tab = next;
}
unsigned int handle_index = indices[i];
bitmap_set(tab->t_handles.t_handle_map, handle_index);
struct handle *out = &tab->t_handles.t_handle_list[handle_index];
if (out->h_object) {
object_unref(out->h_object);
out->h_object = NULL;
out->h_flags = 0;
}
*out_slot = out;
*out_handle = value;
return KERN_OK;
}
kern_status_t handle_table_free_handle(
struct handle_table *tab,
kern_handle_t handle)
@@ -299,6 +346,7 @@ kern_status_t handle_table_transfer(
case KERN_MSG_HANDLE_MOVE:
status = handle_table_alloc_handle(
dst,
KERN_HANDLE_INVALID,
&dst_entry,
&dst_value);
if (status != KERN_OK) {
@@ -318,6 +366,7 @@ kern_status_t handle_table_transfer(
case KERN_MSG_HANDLE_COPY:
status = handle_table_alloc_handle(
dst,
KERN_HANDLE_INVALID,
&dst_entry,
&dst_value);
if (status != KERN_OK) {