sched: enforce ref-counting on current task/thread pointers

This commit is contained in:
2026-04-01 18:17:05 +01:00
parent 15c2207ab9
commit 512356ac2d
28 changed files with 364 additions and 103 deletions
+23 -3
View File
@@ -32,8 +32,10 @@ static kern_status_t get_data(
{
spin_lock_t *lock = NULL;
struct btree *futex_list = NULL;
struct task *self = NULL;
if (flags & FUTEX_PRIVATE) {
struct task *self = current_task();
self = get_current_task();
lock = &self->t_base.ob_lock;
futex_list = &self->t_futex;
} else if (flags & FUTEX_SHARED) {
@@ -48,12 +50,20 @@ static kern_status_t get_data(
if (!futex && !(flags & FUTEX_CREATE)) {
spin_unlock_irqrestore(lock, *irq_flags);
if (self) {
put_current_task(self);
}
return KERN_NO_ENTRY;
}
futex = vm_cache_alloc(&futex_cache, VM_NORMAL);
if (!futex) {
spin_unlock_irqrestore(lock, *irq_flags);
if (self) {
put_current_task(self);
}
return KERN_NO_MEMORY;
}
@@ -61,6 +71,10 @@ static kern_status_t get_data(
put_futex(futex_list, futex);
if (self) {
put_current_task(self);
}
*out = futex;
*out_lock = lock;
return KERN_OK;
@@ -68,9 +82,10 @@ static kern_status_t get_data(
static kern_status_t cleanup_data(struct futex *futex, unsigned int flags)
{
struct task *self = NULL;
struct btree *futex_list = NULL;
if (flags & FUTEX_PRIVATE) {
struct task *self = current_task();
self = get_current_task();
futex_list = &self->t_futex;
} else if (flags & FUTEX_SHARED) {
futex_list = &shared_futex_list;
@@ -81,12 +96,16 @@ static kern_status_t cleanup_data(struct futex *futex, unsigned int flags)
btree_delete(futex_list, &futex->f_node);
vm_cache_free(&futex_cache, futex);
if (self) {
put_current_task(self);
}
return KERN_OK;
}
static kern_status_t futex_get_shared(kern_futex_t *futex, futex_key_t *out)
{
struct task *self = current_task();
struct task *self = get_current_task();
struct address_space *space = self->t_address_space;
unsigned long flags;
@@ -97,6 +116,7 @@ static kern_status_t futex_get_shared(kern_futex_t *futex, futex_key_t *out)
out,
&flags);
address_space_unlock_irqrestore(space, flags);
put_current_task(self);
return status;
}