mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-27 12:48:22 +00:00
vmm: change how vmm_destroycontext is handled
This commit is contained in:
@@ -94,7 +94,7 @@ static inline int mmuflagstovnodeflags(mmuflags_t mmuflags) {
|
||||
return flags;
|
||||
}
|
||||
|
||||
void vmm_destroycontext(vmmcontext_t *context, int destroyrangeflags);
|
||||
void vmm_destroycontext(vmmcontext_t *context);
|
||||
vmmcontext_t *vmm_fork(vmmcontext_t *oldcontext);
|
||||
void *vmm_map(void *addr, size_t size, int flags, mmuflags_t mmuflags, void *private);
|
||||
void vmm_unmap(void *addr, size_t size, int flags);
|
||||
|
||||
+6
-10
@@ -471,15 +471,11 @@ vmmcontext_t *vmm_newcontext() {
|
||||
return ctx;
|
||||
}
|
||||
|
||||
void vmm_destroycontext(vmmcontext_t *context, int destroyrangeflags) {
|
||||
vmmrange_t *range = context->space.ranges;
|
||||
while (range) {
|
||||
destroyrange(context, range, 0, range->size, destroyrangeflags);
|
||||
vmmrange_t *next = range->next;
|
||||
freerange(range);
|
||||
range = next;
|
||||
}
|
||||
|
||||
void vmm_destroycontext(vmmcontext_t *context) {
|
||||
vmmcontext_t *oldctx = _cpu()->thread->vmmctx;
|
||||
vmm_switchcontext(context);
|
||||
vmm_unmap(context->space.start, context->space.end - context->space.start, 0);
|
||||
vmm_switchcontext(oldctx);
|
||||
arch_mmu_destroytable(context->pagetable);
|
||||
slab_free(ctxcache, context);
|
||||
}
|
||||
@@ -531,7 +527,7 @@ vmmcontext_t *vmm_fork(vmmcontext_t *oldcontext) {
|
||||
return newcontext;
|
||||
error:
|
||||
spinlock_release(&oldcontext->space.lock);
|
||||
vmm_destroycontext(newcontext, VMM_DESTROY_FLAGS_NOSYNC);
|
||||
vmm_destroycontext(newcontext);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
@@ -97,8 +97,9 @@ void sched_destroythread(thread_t *thread) {
|
||||
}
|
||||
|
||||
void sched_destroyproc(proc_t *proc) {
|
||||
free(proc->threads);
|
||||
slab_free(processcache, proc);
|
||||
//free(proc->threads);
|
||||
//free(proc->fd);
|
||||
//slab_free(processcache, proc);
|
||||
}
|
||||
|
||||
static thread_t *runqueuenext(int minprio) {
|
||||
@@ -197,8 +198,14 @@ __attribute__((noreturn)) void sched_threadexit() {
|
||||
thread_t *thread = _cpu()->thread;
|
||||
proc_t *proc = thread->proc;
|
||||
|
||||
if (proc)
|
||||
__atomic_fetch_sub(&currpid, 1, __ATOMIC_SEQ_CST);
|
||||
vmmcontext_t *oldctx = thread->vmmctx;
|
||||
vmm_switchcontext(&vmm_kernelctx);
|
||||
|
||||
if (proc) {
|
||||
__atomic_fetch_sub(&proc->runningthreadcount, 1, __ATOMIC_SEQ_CST);
|
||||
if (proc->runningthreadcount == 0)
|
||||
vmm_destroycontext(oldctx);
|
||||
}
|
||||
|
||||
_cpu()->thread = NULL;
|
||||
|
||||
|
||||
@@ -123,7 +123,7 @@ syscallret_t syscall_execve(context_t *context, char *upath, char *uargv[], char
|
||||
|
||||
if (vmmctx && ret.errno) {
|
||||
vmm_switchcontext(oldctx);
|
||||
vmm_destroycontext(vmmctx, 0);
|
||||
vmm_destroycontext(vmmctx);
|
||||
}
|
||||
|
||||
if (refnode)
|
||||
@@ -136,8 +136,7 @@ syscallret_t syscall_execve(context_t *context, char *upath, char *uargv[], char
|
||||
free(interp);
|
||||
|
||||
if (ret.errno == 0) {
|
||||
// TODO sync mmap files (unmap all lower memory first before destroying context?)
|
||||
vmm_destroycontext(oldctx, 0);
|
||||
vmm_destroycontext(oldctx);
|
||||
CTX_SP(context) = (uint64_t)stack;
|
||||
CTX_IP(context) = (uint64_t)entry;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user