mirror of
https://github.com/drasko/codezero.git
synced 2026-01-12 02:43:15 +01:00
Now shared tcb parts freed correctly.
This commit is contained in:
@@ -143,15 +143,25 @@ struct tcb *tcb_create(struct tcb *orig, l4id_t tid, unsigned long utcb,
|
||||
return task;
|
||||
}
|
||||
|
||||
/* FIXME: Modify it to work with shared structures!!! */
|
||||
/* Free shared structures if no references left */
|
||||
void tcb_free_resources(struct tcb *task)
|
||||
{
|
||||
|
||||
if (--task->fs_data->tcb_refs == 0)
|
||||
kfree(task->fs_data);
|
||||
|
||||
if (--task->files->tcb_refs == 0) {
|
||||
kfree(task->files->fdpool);
|
||||
kfree(task->files);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void tcb_destroy(struct tcb *task)
|
||||
{
|
||||
global_remove_task(task);
|
||||
|
||||
if (--task->fs_data->tcb_refs == 0)
|
||||
kfree(task->fs_data);
|
||||
if (--task->files->tcb_refs == 0)
|
||||
kfree(task->files);
|
||||
tcb_free_resources(task);
|
||||
|
||||
kfree(task);
|
||||
}
|
||||
|
||||
@@ -111,15 +111,41 @@ struct tcb *tcb_alloc_init(unsigned int flags)
|
||||
return task;
|
||||
}
|
||||
|
||||
/* NOTE: We may need to delete shared tcb parts here as well. */
|
||||
/*
|
||||
* Free vmas, fd structure and utcb address.
|
||||
* Make sure to sync all IO beforehand
|
||||
*/
|
||||
int task_free_resources(struct tcb *task)
|
||||
{
|
||||
/*
|
||||
* Threads may share file descriptor structure
|
||||
* if no users left, free it.
|
||||
*/
|
||||
if (!(--task->files->tcb_refs))
|
||||
kfree(task->files);
|
||||
|
||||
/*
|
||||
* Threads may share the virtual space.
|
||||
* if no users of the vma struct left,
|
||||
* free it along with all its vma links.
|
||||
*/
|
||||
if (!(--task->vm_area_head->tcb_refs)) {
|
||||
/* Free all vmas */
|
||||
task_release_vmas(task->vm_area_head);
|
||||
|
||||
/* Free the head */
|
||||
kfree(task->vm_area_head);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tcb_destroy(struct tcb *task)
|
||||
{
|
||||
global_remove_task(task);
|
||||
|
||||
if (--task->vm_area_head->tcb_refs == 0)
|
||||
kfree(task->vm_area_head);
|
||||
if (--task->files->tcb_refs == 0)
|
||||
kfree(task->files);
|
||||
/* Free all resources of the task */
|
||||
task_free_resources(task);
|
||||
|
||||
kfree(task);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user