From eaea18cb9cbb86018dae8f1decfa217ecbe85fa5 Mon Sep 17 00:00:00 2001 From: rsc Date: Wed, 22 Aug 2007 06:01:32 +0000 Subject: PDF at http://am.lcs.mit.edu/~rsc/xv6.pdf Various changes made while offline. + bwrite sector argument is redundant; use b->sector. + reformatting of files for nicer PDF page breaks + distinguish between locked, unlocked inodes in type signatures + change FD_FILE to FD_INODE + move userinit (nee proc0init) to proc.c + move ROOTDEV to param.h + always parenthesize sizeof argument --- exec.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'exec.c') diff --git a/exec.c b/exec.c index 1f8b1af..de1175c 100644 --- a/exec.c +++ b/exec.c @@ -19,7 +19,7 @@ int exec(char *path, char **argv) { uint sz, sp, p1, p2; - int i, nargs, argbytes, len; + int i, nargs, argbytes, len, off; struct inode *ip; struct elfhdr elf; struct proghdr ph; @@ -29,7 +29,7 @@ exec(char *path, char **argv) sz = 0; mem = 0; - if((ip = namei(path)) == 0) + if((ip = ilock(namei(path))) == 0) return -1; if(readi(ip, (char*)&elf, 0, sizeof(elf)) < sizeof(elf)) @@ -38,9 +38,8 @@ exec(char *path, char **argv) if(elf.magic != ELF_MAGIC) goto bad; - for(i = 0; i < elf.phnum; i++){ - if(readi(ip, (char*)&ph, elf.phoff + i * sizeof(ph), - sizeof(ph)) != sizeof(ph)) + for(i=0, off=elf.phoff; iname, last, sizeof cp->name); + safestrcpy(cp->name, last, sizeof(cp->name)); // commit to the new image. kfree(cp->mem, cp->sz); @@ -102,9 +101,8 @@ exec(char *path, char **argv) cp->mem = mem; mem = 0; - for(i = 0; i < elf.phnum; i++){ - if(readi(ip, (char*)&ph, elf.phoff + i * sizeof(ph), - sizeof(ph)) != sizeof(ph)) + for(i=0, off=elf.phoff; imem + ph.va + ph.filesz, 0, ph.memsz - ph.filesz); } - iput(ip); + iput(iunlock(ip)); cp->tf->eip = elf.entry; cp->tf->esp = sp; @@ -126,11 +124,11 @@ exec(char *path, char **argv) bad: if(mem) kfree(mem, sz); - iput(ip); + iput(iunlock(ip)); return -1; bad2: - iput(ip); + iput(iunlock(ip)); proc_exit(); return 0; } -- cgit v1.2.3