diff options
author | Austin Clements <[email protected]> | 2010-09-02 18:28:36 -0400 |
---|---|---|
committer | Austin Clements <[email protected]> | 2010-09-02 18:28:36 -0400 |
commit | 79cd8b3eedeb1f85d3b19fb6119bd5224c4c532a (patch) | |
tree | f9afe121e2b9298b35d3ccd61a329f03421c97fa /exec.c | |
parent | d49d31381df93b40c1c4bc18c97ca42c3256e414 (diff) | |
download | xv6-labs-79cd8b3eedeb1f85d3b19fb6119bd5224c4c532a.tar.gz xv6-labs-79cd8b3eedeb1f85d3b19fb6119bd5224c4c532a.tar.bz2 xv6-labs-79cd8b3eedeb1f85d3b19fb6119bd5224c4c532a.zip |
Simplify allocuvm/deallocuvm to operate in a contiguous memory model. This makes their interface match up better with proc->sz and also simplifies the callers (it even gets the main body of exec on one page).
Diffstat (limited to 'exec.c')
-rw-r--r-- | exec.c | 26 |
1 files changed, 11 insertions, 15 deletions
@@ -11,7 +11,7 @@ exec(char *path, char **argv) { char *mem, *s, *last; int i, argc, arglen, len, off; - uint sz, sp, spoffset, argp; + uint sz, sp, spbottom, argp; struct elfhdr elf; struct inode *ip; struct proghdr ph; @@ -41,22 +41,18 @@ exec(char *path, char **argv) continue; if(ph.memsz < ph.filesz) goto bad; - if(!allocuvm(pgdir, (char *)ph.va, ph.memsz)) + if(!(sz = allocuvm(pgdir, sz, ph.va + ph.memsz))) goto bad; - if(ph.va + ph.memsz > sz) - sz = ph.va + ph.memsz; if(!loaduvm(pgdir, (char *)ph.va, ip, ph.offset, ph.filesz)) goto bad; } iunlockput(ip); // Allocate and initialize stack at sz - sz = PGROUNDUP(sz); - if(!allocuvm(pgdir, (char *)sz, PGSIZE)) + sz = spbottom = PGROUNDUP(sz); + if(!(sz = allocuvm(pgdir, sz, sz + PGSIZE))) goto bad; - mem = uva2ka(pgdir, (char *)sz); - spoffset = sz; - sz += PGSIZE; + mem = uva2ka(pgdir, (char *)spbottom); arglen = 0; for(argc=0; argv[argc]; argc++) @@ -67,22 +63,22 @@ exec(char *path, char **argv) argp = sz - arglen - 4*(argc+1); // Copy argv strings and pointers to stack. - *(uint*)(mem+argp-spoffset + 4*argc) = 0; // argv[argc] + *(uint*)(mem+argp-spbottom + 4*argc) = 0; // argv[argc] for(i=argc-1; i>=0; i--){ len = strlen(argv[i]) + 1; sp -= len; - memmove(mem+sp-spoffset, argv[i], len); - *(uint*)(mem+argp-spoffset + 4*i) = sp; // argv[i] + memmove(mem+sp-spbottom, argv[i], len); + *(uint*)(mem+argp-spbottom + 4*i) = sp; // argv[i] } // Stack frame for main(argc, argv), below arguments. sp = argp; sp -= 4; - *(uint*)(mem+sp-spoffset) = argp; + *(uint*)(mem+sp-spbottom) = argp; sp -= 4; - *(uint*)(mem+sp-spoffset) = argc; + *(uint*)(mem+sp-spbottom) = argc; sp -= 4; - *(uint*)(mem+sp-spoffset) = 0xffffffff; // fake return pc + *(uint*)(mem+sp-spbottom) = 0xffffffff; // fake return pc // Save program name for debugging. for(last=s=path; *s; s++) |