Rewrite LL_* (link list) macros

This commit is contained in:
2025-09-21 18:32:22 +02:00
parent d5c2df7365
commit 475f77d30f
6 changed files with 106 additions and 100 deletions

View File

@ -211,58 +211,50 @@ Proc *proc_nextready(void) {
void proc_reaper(void) {
spinlock_acquire(&PROCS.spinlock);
Proc *head = PROCS.procs;
while (head) {
if (head->state == PROC_ZOMBIE) {
Proc *zombie = head;
head = head->next;
LL_REMOVE(PROCS.procs, zombie);
for (size_t i = 0; i < zombie->vobjcnt; i++) {
if (zombie->vobjs[i] != NULL) {
vfs_close(zombie->vobjs[i]);
zombie->vobjs[i] = NULL;
}
}
for (size_t i = 0; i < PROC_PIPEHANDLES_MAX; i++) {
if (zombie->pipes[i] != NULL && zombie->pipes[i]->ownerpid == zombie->pid) {
dlfree(zombie->pipes[i]);
ipc_pipefree(zombie->pipes[i]);
zombie->pipes[i] = NULL;
}
}
pmm_free((uintptr_t)(zombie->platformdata.kstack - PROC_STACKSIZE), PROC_STACKBLOCKS);
pmm_free((uintptr_t)(zombie->platformdata.pstack - PROC_STACKSIZE), PROC_STACKBLOCKS);
if (!zombie->kern) {
VasRange *vashead = zombie->vas;
size_t i = 0;
while (vashead) {
VasRange *tmp = vashead;
vashead = vashead->next;
hal_vmm_unmap_range(zombie->platformdata.cr3, tmp->virtstart, tmp->physstart, tmp->size);
pmm_free((uintptr_t)tmp->physstart, tmp->size / HAL_PAGE_SIZE);
dlfree(tmp);
i++;
}
pmm_free((uintptr_t)zombie->platformdata.cr3, 1);
ProcArg *arg = zombie->procargs.list;
while (arg) {
dlfree(arg->string);
ProcArg *tmp = arg;
arg = arg->next;
dlfree(tmp);
}
}
dlfree(zombie);
} else {
head = head->next;
Proc *head, *tmp;
LL_FOREACH_SAFE(PROCS.procs, head, tmp) {
if (head->state != PROC_ZOMBIE) {
continue;
}
Proc *zombie = head;
LL_REMOVE(PROCS.procs, zombie);
for (size_t i = 0; i < zombie->vobjcnt; i++) {
if (zombie->vobjs[i] != NULL) {
vfs_close(zombie->vobjs[i]);
zombie->vobjs[i] = NULL;
}
}
for (size_t i = 0; i < PROC_PIPEHANDLES_MAX; i++) {
if (zombie->pipes[i] != NULL && zombie->pipes[i]->ownerpid == zombie->pid) {
dlfree(zombie->pipes[i]);
ipc_pipefree(zombie->pipes[i]);
zombie->pipes[i] = NULL;
}
}
pmm_free((uintptr_t)(zombie->platformdata.kstack - PROC_STACKSIZE), PROC_STACKBLOCKS);
pmm_free((uintptr_t)(zombie->platformdata.pstack - PROC_STACKSIZE), PROC_STACKBLOCKS);
if (!zombie->kern) {
VasRange *vas, *vastmp;
LL_FOREACH_SAFE(zombie->vas, vas, vastmp) {
hal_vmm_unmap_range(zombie->platformdata.cr3, vas->virtstart, vas->physstart, vas->size);
pmm_free((uintptr_t)vas->physstart, vas->size / HAL_PAGE_SIZE);
dlfree(vas);
}
pmm_free((uintptr_t)zombie->platformdata.cr3, 1);
ProcArg *arg, *argtmp;
LL_FOREACH_SAFE(zombie->procargs.list, arg, argtmp) {
dlfree(arg->string);
dlfree(arg);
}
}
dlfree(zombie);
}
spinlock_release(&PROCS.spinlock);
}