kernel: resolving a handle now increments the refcount of the corresponding object

This commit is contained in:
2026-03-12 20:42:05 +00:00
parent 5a37b5e148
commit 6ba236b2fe
5 changed files with 7 additions and 39 deletions

View File

@@ -326,7 +326,7 @@ kern_status_t task_resolve_handle(
} }
if (out_obj) { if (out_obj) {
*out_obj = handle_data->h_object; *out_obj = object_ref(handle_data->h_object);
} }
if (out_flags) { if (out_flags) {

View File

@@ -92,9 +92,6 @@ kern_status_t sys_port_connect(
return status; return status;
} }
/* add a reference to the port object to make sure it isn't deleted
* while we're using it */
object_ref(port_obj);
struct port *port = port_cast(port_obj); struct port *port = port_cast(port_obj);
task_unlock_irqrestore(self, flags); task_unlock_irqrestore(self, flags);
@@ -117,7 +114,6 @@ kern_status_t sys_port_connect(
port_lock_irqsave(port, &flags); port_lock_irqsave(port, &flags);
status = port_connect(port, remote); status = port_connect(port, remote);
port_unlock_irqrestore(port, flags); port_unlock_irqrestore(port, flags);
object_unref(port_obj);
object_unref(&remote->c_base); object_unref(&remote->c_base);
return KERN_OK; return KERN_OK;
@@ -141,9 +137,6 @@ kern_status_t sys_port_disconnect(kern_handle_t port_handle)
return status; return status;
} }
/* add a reference to the port object to make sure it isn't deleted
* while we're using it */
object_ref(port_obj);
task_unlock_irqrestore(self, flags); task_unlock_irqrestore(self, flags);
struct port *port = port_cast(port_obj); struct port *port = port_cast(port_obj);
@@ -251,9 +244,6 @@ kern_status_t sys_msg_send(
return status; return status;
} }
/* add a reference to the port object to make sure it isn't deleted
* while we're using it */
object_ref(port_obj);
task_unlock_irqrestore(self, flags); task_unlock_irqrestore(self, flags);
struct port *port = port_cast(port_obj); struct port *port = port_cast(port_obj);
@@ -293,9 +283,6 @@ kern_status_t sys_msg_recv(kern_handle_t channel_handle, kern_msg_t *out_msg)
return status; return status;
} }
/* add a reference to the port object to make sure it isn't deleted
* while we're using it */
object_ref(channel_obj);
task_unlock_irqrestore(self, flags); task_unlock_irqrestore(self, flags);
struct channel *channel = channel_cast(channel_obj); struct channel *channel = channel_cast(channel_obj);
@@ -338,9 +325,6 @@ kern_status_t sys_msg_reply(
return status; return status;
} }
/* add a reference to the port object to make sure it isn't deleted
* while we're using it */
object_ref(channel_obj);
task_unlock_irqrestore(self, flags); task_unlock_irqrestore(self, flags);
struct channel *channel = channel_cast(channel_obj); struct channel *channel = channel_cast(channel_obj);
@@ -390,9 +374,6 @@ kern_status_t sys_msg_read(
return status; return status;
} }
/* add a reference to the port object to make sure it isn't deleted
* while we're using it */
object_ref(channel_obj);
task_unlock_irqrestore(self, flags); task_unlock_irqrestore(self, flags);
struct channel *channel = channel_cast(channel_obj); struct channel *channel = channel_cast(channel_obj);
@@ -450,9 +431,6 @@ kern_status_t sys_msg_write(
return status; return status;
} }
/* add a reference to the port object to make sure it isn't deleted
* while we're using it */
object_ref(channel_obj);
task_unlock_irqrestore(self, flags); task_unlock_irqrestore(self, flags);
struct channel *channel = channel_cast(channel_obj); struct channel *channel = channel_cast(channel_obj);

View File

@@ -84,7 +84,6 @@ kern_status_t sys_task_create(
return status; return status;
} }
object_ref(parent_obj);
struct task *parent = task_cast(parent_obj); struct task *parent = task_cast(parent_obj);
struct handle *child_handle_slot = NULL, *space_handle_slot = NULL; struct handle *child_handle_slot = NULL, *space_handle_slot = NULL;
@@ -94,6 +93,7 @@ kern_status_t sys_task_create(
&child_handle_slot, &child_handle_slot,
&child_handle); &child_handle);
if (status != KERN_OK) { if (status != KERN_OK) {
object_unref(parent_obj);
task_unlock_irqrestore(self, flags); task_unlock_irqrestore(self, flags);
return status; return status;
} }
@@ -103,6 +103,7 @@ kern_status_t sys_task_create(
&space_handle_slot, &space_handle_slot,
&space_handle); &space_handle);
if (status != KERN_OK) { if (status != KERN_OK) {
object_unref(parent_obj);
handle_table_free_handle(self->t_handles, child_handle); handle_table_free_handle(self->t_handles, child_handle);
task_unlock_irqrestore(self, flags); task_unlock_irqrestore(self, flags);
return status; return status;
@@ -169,7 +170,6 @@ kern_status_t sys_task_create_thread(
return status; return status;
} }
object_ref(target_obj);
struct task *target = task_cast(target_obj); struct task *target = task_cast(target_obj);
struct handle *target_handle = NULL; struct handle *target_handle = NULL;
@@ -238,6 +238,7 @@ kern_status_t sys_task_get_address_space(
&handle_slot, &handle_slot,
&handle); &handle);
if (status != KERN_OK) { if (status != KERN_OK) {
object_unref(task_obj);
task_unlock_irqrestore(self, flags); task_unlock_irqrestore(self, flags);
return status; return status;
} }
@@ -245,6 +246,7 @@ kern_status_t sys_task_get_address_space(
struct task *task = task_cast(task_obj); struct task *task = task_cast(task_obj);
if (!task) { if (!task) {
object_unref(task_obj);
handle_table_free_handle(self->t_handles, handle); handle_table_free_handle(self->t_handles, handle);
task_unlock_irqrestore(self, flags); task_unlock_irqrestore(self, flags);
return KERN_INVALID_ARGUMENT; return KERN_INVALID_ARGUMENT;
@@ -253,6 +255,7 @@ kern_status_t sys_task_get_address_space(
handle_slot->h_object = &task->t_address_space->vr_base; handle_slot->h_object = &task->t_address_space->vr_base;
object_add_handle(&task->t_address_space->vr_base); object_add_handle(&task->t_address_space->vr_base);
task_unlock_irqrestore(self, flags); task_unlock_irqrestore(self, flags);
object_unref(task_obj);
*out = handle; *out = handle;
return KERN_OK; return KERN_OK;
@@ -276,11 +279,11 @@ kern_status_t sys_thread_start(kern_handle_t thread_handle)
return status; return status;
} }
object_ref(thread_obj);
struct thread *thread = thread_cast(thread_obj); struct thread *thread = thread_cast(thread_obj);
task_unlock_irqrestore(self, flags); task_unlock_irqrestore(self, flags);
schedule_thread_on_cpu(thread); schedule_thread_on_cpu(thread);
object_unref(thread_obj);
return KERN_OK; return KERN_OK;
} }

View File

@@ -144,9 +144,6 @@ kern_status_t sys_vm_object_copy(
return status; return status;
} }
object_ref(src_obj);
object_ref(dst_obj);
task_unlock_irqrestore(self, flags); task_unlock_irqrestore(self, flags);
struct vm_object *dst_vmo = vm_object_cast(dst_obj); struct vm_object *dst_vmo = vm_object_cast(dst_obj);

View File

@@ -61,7 +61,6 @@ kern_status_t sys_vm_region_create(
return status; return status;
} }
object_ref(obj);
task_unlock_irqrestore(self, flags); task_unlock_irqrestore(self, flags);
vm_region_lock_irqsave(parent_region, &flags); vm_region_lock_irqsave(parent_region, &flags);
@@ -116,7 +115,6 @@ kern_status_t sys_vm_region_kill(kern_handle_t region_handle)
return KERN_INVALID_ARGUMENT; return KERN_INVALID_ARGUMENT;
} }
object_ref(obj);
task_unlock_irqrestore(self, flags); task_unlock_irqrestore(self, flags);
vm_region_lock_irqsave(region, &flags); vm_region_lock_irqsave(region, &flags);
@@ -162,7 +160,6 @@ kern_status_t sys_vm_region_read(
return KERN_INVALID_ARGUMENT; return KERN_INVALID_ARGUMENT;
} }
object_ref(obj);
task_unlock_irqrestore(self, flags); task_unlock_irqrestore(self, flags);
virt_addr_t src_address = vm_region_get_base_address(region) + offset; virt_addr_t src_address = vm_region_get_base_address(region) + offset;
@@ -214,7 +211,6 @@ kern_status_t sys_vm_region_write(
return KERN_INVALID_ARGUMENT; return KERN_INVALID_ARGUMENT;
} }
object_ref(obj);
task_unlock_irqrestore(self, flags); task_unlock_irqrestore(self, flags);
virt_addr_t dst_address = vm_region_get_base_address(region) + offset; virt_addr_t dst_address = vm_region_get_base_address(region) + offset;
@@ -283,8 +279,6 @@ kern_status_t sys_vm_region_map_absolute(
return KERN_INVALID_ARGUMENT; return KERN_INVALID_ARGUMENT;
} }
object_ref(vmo_obj);
object_ref(region_obj);
task_unlock_irqrestore(self, flags); task_unlock_irqrestore(self, flags);
off_t region_offset = VM_REGION_ANY_OFFSET; off_t region_offset = VM_REGION_ANY_OFFSET;
@@ -369,8 +363,6 @@ kern_status_t sys_vm_region_map_relative(
return KERN_INVALID_ARGUMENT; return KERN_INVALID_ARGUMENT;
} }
object_ref(vmo_obj);
object_ref(region_obj);
task_unlock_irqrestore(self, flags); task_unlock_irqrestore(self, flags);
status = vm_region_map_object( status = vm_region_map_object(
@@ -418,7 +410,6 @@ kern_status_t sys_vm_region_unmap_absolute(
return KERN_INVALID_ARGUMENT; return KERN_INVALID_ARGUMENT;
} }
object_ref(region_obj);
task_unlock_irqrestore(self, flags); task_unlock_irqrestore(self, flags);
off_t region_offset = address - vm_region_get_base_address(region); off_t region_offset = address - vm_region_get_base_address(region);
@@ -458,7 +449,6 @@ kern_status_t sys_vm_region_unmap_relative(
return KERN_INVALID_ARGUMENT; return KERN_INVALID_ARGUMENT;
} }
object_ref(region_obj);
task_unlock_irqrestore(self, flags); task_unlock_irqrestore(self, flags);
status = vm_region_unmap(region, offset, length); status = vm_region_unmap(region, offset, length);