summaryrefslogtreecommitdiff
path: root/exec.c
diff options
context:
space:
mode:
authorFrans Kaashoek <[email protected]>2017-01-31 20:21:14 -0500
committerFrans Kaashoek <[email protected]>2017-01-31 20:21:14 -0500
commitfbb4c0944422f860484142010bb9f366f3e87bf8 (patch)
tree5e339842d43d09a4d23f1a2165391f00af30e308 /exec.c
parentabf847a083888bbed4260ecacf849ea19f23e810 (diff)
downloadxv6-labs-fbb4c0944422f860484142010bb9f366f3e87bf8.tar.gz
xv6-labs-fbb4c0944422f860484142010bb9f366f3e87bf8.tar.bz2
xv6-labs-fbb4c0944422f860484142010bb9f366f3e87bf8.zip
Read curproc from cpu structure, but be careful because after a schedule event
myproc() points to a different thread. myproc(); sched(); myproc(); // this proc maybe different than the one before sched Thus, in a function that operates on one thread better to retrieve the current process once at the start of the function.
Diffstat (limited to 'exec.c')
-rw-r--r--exec.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/exec.c b/exec.c
index 14d673f..b40134f 100644
--- a/exec.c
+++ b/exec.c
@@ -17,6 +17,7 @@ exec(char *path, char **argv)
struct inode *ip;
struct proghdr ph;
pde_t *pgdir, *oldpgdir;
+ struct proc *curproc = myproc();
begin_op();
@@ -90,15 +91,15 @@ exec(char *path, char **argv)
for(last=s=path; *s; s++)
if(*s == '/')
last = s+1;
- safestrcpy(myproc()->name, last, sizeof(myproc()->name));
+ safestrcpy(curproc->name, last, sizeof(curproc->name));
// Commit to the user image.
- oldpgdir = myproc()->pgdir;
- myproc()->pgdir = pgdir;
- myproc()->sz = sz;
- myproc()->tf->eip = elf.entry; // main
- myproc()->tf->esp = sp;
- switchuvm(myproc());
+ oldpgdir = curproc->pgdir;
+ curproc->pgdir = pgdir;
+ curproc->sz = sz;
+ curproc->tf->eip = elf.entry; // main
+ curproc->tf->esp = sp;
+ switchuvm(curproc);
freevm(oldpgdir);
return 0;