提交 4587b358 创建 作者: Robert Morris's avatar Robert Morris

exec questions

上级 faad047a
...@@ -48,6 +48,9 @@ exec(char *path, char **argv) ...@@ -48,6 +48,9 @@ exec(char *path, char **argv)
} }
iunlockput(ip); iunlockput(ip);
// XXX rtm: what about the BSS? shouldn't there be some
// bzero()ing here?
// Allocate and initialize stack at sz // Allocate and initialize stack at sz
sz = spbottom = PGROUNDUP(sz); sz = spbottom = PGROUNDUP(sz);
if(!(sz = allocuvm(pgdir, sz, sz + PGSIZE))) if(!(sz = allocuvm(pgdir, sz, sz + PGSIZE)))
...@@ -62,6 +65,9 @@ exec(char *path, char **argv) ...@@ -62,6 +65,9 @@ exec(char *path, char **argv)
sp = sz; sp = sz;
argp = sz - arglen - 4*(argc+1); argp = sz - arglen - 4*(argc+1);
// XXX rtm: does the following code work if the
// arguments &c do not fit in one page?
// Copy argv strings and pointers to stack. // Copy argv strings and pointers to stack.
*(uint*)(mem+argp-spbottom + 4*argc) = 0; // argv[argc] *(uint*)(mem+argp-spbottom + 4*argc) = 0; // argv[argc]
for(i=argc-1; i>=0; i--){ for(i=argc-1; i>=0; i--){
......
...@@ -17,12 +17,12 @@ struct { ...@@ -17,12 +17,12 @@ struct {
struct run *freelist; struct run *freelist;
} kmem; } kmem;
extern char end[]; // first address after kernel loaded from ELF file
// Initialize free list of physical pages. // Initialize free list of physical pages.
void void
kinit(void) kinit(void)
{ {
extern char end[];
initlock(&kmem.lock, "kmem"); initlock(&kmem.lock, "kmem");
char *p = (char*)PGROUNDUP((uint)end); char *p = (char*)PGROUNDUP((uint)end);
for( ; p + PGSIZE - 1 < (char*) PHYSTOP; p += PGSIZE) for( ; p + PGSIZE - 1 < (char*) PHYSTOP; p += PGSIZE)
...@@ -39,7 +39,7 @@ kfree(char *v) ...@@ -39,7 +39,7 @@ kfree(char *v)
{ {
struct run *r; struct run *r;
if(((uint) v) % PGSIZE || (uint)v < 1024*1024 || (uint)v >= PHYSTOP) if(((uint) v) % PGSIZE || v < end || (uint)v >= PHYSTOP)
panic("kfree"); panic("kfree");
// Fill with junk to catch dangling refs. // Fill with junk to catch dangling refs.
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论