summaryrefslogtreecommitdiff
path: root/exec.c
diff options
context:
space:
mode:
authorrsc <rsc>2007-08-22 06:01:32 +0000
committerrsc <rsc>2007-08-22 06:01:32 +0000
commiteaea18cb9cbb86018dae8f1decfa217ecbe85fa5 (patch)
tree98c4a9b852ad9b6aaf16016417cf5eeee0b3857e /exec.c
parent3dcf889c1b5c2c5ddf5b4756f2a731c344f6f08e (diff)
downloadxv6-labs-eaea18cb9cbb86018dae8f1decfa217ecbe85fa5.tar.gz
xv6-labs-eaea18cb9cbb86018dae8f1decfa217ecbe85fa5.tar.bz2
xv6-labs-eaea18cb9cbb86018dae8f1decfa217ecbe85fa5.zip
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
Diffstat (limited to 'exec.c')
-rw-r--r--exec.c22
1 files changed, 10 insertions, 12 deletions
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; i<elf.phnum; i++, off+=sizeof(ph)){
+ if(readi(ip, (char*)&ph, off, sizeof(ph)) != sizeof(ph))
goto bad;
if(ph.type != ELF_PROG_LOAD)
continue;
@@ -94,7 +93,7 @@ exec(char *path, char **argv)
for(last=s=path; *s; s++)
if(*s == '/')
last = s+1;
- safestrcpy(cp->name, 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; i<elf.phnum; i++, off+=sizeof(ph)){
+ if(readi(ip, (char*)&ph, off, sizeof(ph)) != sizeof(ph))
goto bad2;
if(ph.type != ELF_PROG_LOAD)
continue;
@@ -115,7 +113,7 @@ exec(char *path, char **argv)
memset(cp->mem + 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;
}