summaryrefslogtreecommitdiff
path: root/kernel/proc.c
diff options
context:
space:
mode:
authorRobert Morris <[email protected]>2019-07-23 12:17:17 -0400
committerRobert Morris <[email protected]>2019-07-23 12:17:17 -0400
commit54178ad94d758e557bfa369b7f137e2844e030e1 (patch)
treecc2446a7d55d35e30f12f26e44aef68d285bfc91 /kernel/proc.c
parent55bc96d4190e40704fb5e447cef9597b08b8f088 (diff)
downloadxv6-labs-54178ad94d758e557bfa369b7f137e2844e030e1.tar.gz
xv6-labs-54178ad94d758e557bfa369b7f137e2844e030e1.tar.bz2
xv6-labs-54178ad94d758e557bfa369b7f137e2844e030e1.zip
simplify kernel mapping calls
Diffstat (limited to 'kernel/proc.c')
-rw-r--r--kernel/proc.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/kernel/proc.c b/kernel/proc.c
index cebef1a..5ce31c7 100644
--- a/kernel/proc.c
+++ b/kernel/proc.c
@@ -28,12 +28,18 @@ procinit(void)
initlock(&pid_lock, "nextpid");
for(p = proc; p < &proc[NPROC]; p++) {
initlock(&p->lock, "proc");
- // Allocate a page for the kernel stack.
- uint64 kstack = KSTACK((int) (p - proc));
- if((p->kstack = mapkstack(kstack)) == 0) {
- panic("procinit");
- }
+
+ // Allocate a page for the process's kernel stack.
+ // Map it high in memory, followed by an invalid
+ // guard page.
+ char *pa = kalloc();
+ if(pa == 0)
+ panic("kalloc");
+ uint64 va = KSTACK((int) (p - proc));
+ kmap(va, (uint64)pa, PGSIZE, PTE_R | PTE_W);
+ p->kstack = va;
}
+ kvminithart();
}
// Must be called with interrupts disabled,
@@ -113,7 +119,7 @@ found:
// which returns to user space.
memset(&p->context, 0, sizeof p->context);
p->context.ra = (uint64)forkret;
- p->context.sp = (uint64)p->kstack + PGSIZE;
+ p->context.sp = p->kstack + PGSIZE;
return p;
}