Associate brk with vmap (instead of proc)

上级 297c42cd
...@@ -43,7 +43,6 @@ enum procstate { EMBRYO, SLEEPING, RUNNABLE, RUNNING, ZOMBIE }; ...@@ -43,7 +43,6 @@ enum procstate { EMBRYO, SLEEPING, RUNNABLE, RUNNING, ZOMBIE };
// Per-process state // Per-process state
struct proc : public rcu_freed { struct proc : public rcu_freed {
struct vmap *vmap; // va -> vma struct vmap *vmap; // va -> vma
uptr brk; // Top of heap
char *kstack; // Bottom of kernel stack for this process char *kstack; // Bottom of kernel stack for this process
volatile int pid; // Process ID volatile int pid; // Process ID
struct proc *parent; // Parent process struct proc *parent; // Parent process
......
...@@ -88,6 +88,8 @@ struct vmap { ...@@ -88,6 +88,8 @@ struct vmap {
int copyout(uptr va, void *p, u64 len); int copyout(uptr va, void *p, u64 len);
NEW_DELETE_OPS(vmap) NEW_DELETE_OPS(vmap)
uptr brk_; // Top of heap
private: private:
int pagefault_wcow(vma *m); int pagefault_wcow(vma *m);
}; };
...@@ -136,6 +136,7 @@ doheap(struct eargs *args) ...@@ -136,6 +136,7 @@ doheap(struct eargs *args)
goto bad; goto bad;
if(args->vmap->insert(vmn, BRK, 1) < 0) if(args->vmap->insert(vmn, BRK, 1) < 0)
goto bad; goto bad;
args->vmap->brk_ = BRK + 8; // XXX so that brk-1 points within heap vma..
return; return;
...@@ -202,7 +203,6 @@ exec(const char *path, char **argv) ...@@ -202,7 +203,6 @@ exec(const char *path, char **argv)
// Commit to the user image. // Commit to the user image.
oldvmap = myproc()->vmap; oldvmap = myproc()->vmap;
myproc()->vmap = vmp; myproc()->vmap = vmp;
myproc()->brk = BRK + 8; // XXX so that brk-1 points within heap vma..
myproc()->tf->rip = elf.entry; // main myproc()->tf->rip = elf.entry; // main
switchvm(myproc()); switchvm(myproc());
......
...@@ -36,7 +36,7 @@ struct kstack_tag kstack_tag[NCPU]; ...@@ -36,7 +36,7 @@ struct kstack_tag kstack_tag[NCPU];
enum { sched_debug = 0 }; enum { sched_debug = 0 };
proc::proc(int npid) : proc::proc(int npid) :
rcu_freed("proc"), vmap(0), brk(0), kstack(0), rcu_freed("proc"), vmap(0), kstack(0),
pid(npid), parent(0), tf(0), context(0), killed(0), pid(npid), parent(0), tf(0), context(0), killed(0),
ftable(0), cwd(0), tsc(0), curcycles(0), cpuid(0), epoch(0), ftable(0), cwd(0), tsc(0), curcycles(0), cpuid(0), epoch(0),
on_runq(-1), cpu_pin(0), runq(0), oncv(0), cv_wakeup(0), on_runq(-1), cpu_pin(0), runq(0), oncv(0), cv_wakeup(0),
...@@ -285,10 +285,10 @@ int ...@@ -285,10 +285,10 @@ int
growproc(int n) growproc(int n)
{ {
struct vmap *m = myproc()->vmap; struct vmap *m = myproc()->vmap;
auto curbrk = myproc()->brk; auto curbrk = m->brk_;
if(n < 0 && 0 - n <= curbrk){ if(n < 0 && 0 - n <= curbrk){
myproc()->brk += n; m->brk_ += n;
return 0; return 0;
} }
...@@ -312,7 +312,7 @@ growproc(int n) ...@@ -312,7 +312,7 @@ growproc(int n)
if (e->vma_start <= newstart) { if (e->vma_start <= newstart) {
if (e->vma_end >= newstart + newn) { if (e->vma_end >= newstart + newn) {
myproc()->brk += n; m->brk_ += n;
return 0; return 0;
} }
...@@ -349,7 +349,7 @@ growproc(int n) ...@@ -349,7 +349,7 @@ growproc(int n)
span.replace(newstart, newn, repl); span.replace(newstart, newn, repl);
#endif #endif
myproc()->brk += n; m->brk_ += n;
return 0; return 0;
} }
...@@ -453,7 +453,6 @@ fork(int flags) ...@@ -453,7 +453,6 @@ fork(int flags)
np->vmap->ref++; np->vmap->ref++;
} }
np->brk = myproc()->brk;
np->parent = myproc(); np->parent = myproc();
*np->tf = *myproc()->tf; *np->tf = *myproc()->tf;
......
...@@ -46,7 +46,7 @@ sys_sbrk(int n) ...@@ -46,7 +46,7 @@ sys_sbrk(int n)
{ {
uptr addr; uptr addr;
addr = myproc()->brk; addr = myproc()->vmap->brk_;
if(growproc(n) < 0) if(growproc(n) < 0)
return -1; return -1;
return addr; return addr;
......
...@@ -145,7 +145,8 @@ vmap::vmap() : ...@@ -145,7 +145,8 @@ vmap::vmap() :
#if VM_RADIX #if VM_RADIX
rx(PGSHIFT), rx(PGSHIFT),
#endif #endif
ref(1), pml4(setupkvm()), kshared((char*) ksalloc(slab_kshared)) ref(1), pml4(setupkvm()), kshared((char*) ksalloc(slab_kshared)),
brk_(0)
{ {
if (pml4 == 0) { if (pml4 == 0) {
cprintf("vmap_alloc: setupkvm out of memory\n"); cprintf("vmap_alloc: setupkvm out of memory\n");
...@@ -289,6 +290,8 @@ vmap::copy(int share) ...@@ -289,6 +290,8 @@ vmap::copy(int share)
if (share) if (share)
tlbflush(); // Reload hardware page table tlbflush(); // Reload hardware page table
nm->brk_ = brk_;
return nm; return nm;
err: err:
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论