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