Make cp a magic symbol.
This commit is contained in:
parent
3bbbaca14d
commit
b6095304b7
10 changed files with 32 additions and 41 deletions
|
@ -397,7 +397,7 @@ console_read(int minor, char *dst, int n)
|
||||||
acquire(&kbd_lock);
|
acquire(&kbd_lock);
|
||||||
while(n > 0){
|
while(n > 0){
|
||||||
while(kbd_r == kbd_w){
|
while(kbd_r == kbd_w){
|
||||||
if(curproc[cpu()]->killed){
|
if(cp->killed){
|
||||||
release(&kbd_lock);
|
release(&kbd_lock);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
11
fs.c
11
fs.c
|
@ -557,7 +557,6 @@ namei(char *path, int mode, uint *ret_off,
|
||||||
char **ret_last, struct inode **ret_ip)
|
char **ret_last, struct inode **ret_ip)
|
||||||
{
|
{
|
||||||
struct inode *dp;
|
struct inode *dp;
|
||||||
struct proc *cp = curproc[cpu()];
|
|
||||||
char *name;
|
char *name;
|
||||||
int namelen;
|
int namelen;
|
||||||
uint off, dev, inum;
|
uint off, dev, inum;
|
||||||
|
@ -648,15 +647,15 @@ wdir(struct inode *dp, char *name, uint ino)
|
||||||
panic("wdir write");
|
panic("wdir write");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the path cp and return its locked inode structure.
|
// Create the path and return its locked inode structure.
|
||||||
// If cp already exists, return 0.
|
// If cp already exists, return 0.
|
||||||
struct inode*
|
struct inode*
|
||||||
mknod(char *cp, short type, short major, short minor)
|
mknod(char *path, short type, short major, short minor)
|
||||||
{
|
{
|
||||||
struct inode *ip, *dp;
|
struct inode *ip, *dp;
|
||||||
char *last;
|
char *last;
|
||||||
|
|
||||||
if((dp = namei(cp, NAMEI_CREATE, 0, &last, 0)) == 0)
|
if((dp = namei(path, NAMEI_CREATE, 0, &last, 0)) == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
ip = mknod1(dp, last, type, major, minor);
|
ip = mknod1(dp, last, type, major, minor);
|
||||||
|
@ -691,13 +690,13 @@ mknod1(struct inode *dp, char *name, short type, short major, short minor)
|
||||||
|
|
||||||
// Unlink the inode named cp.
|
// Unlink the inode named cp.
|
||||||
int
|
int
|
||||||
unlink(char *cp)
|
unlink(char *path)
|
||||||
{
|
{
|
||||||
struct inode *ip, *dp;
|
struct inode *ip, *dp;
|
||||||
struct dirent de;
|
struct dirent de;
|
||||||
uint off, inum, dev;
|
uint off, inum, dev;
|
||||||
|
|
||||||
dp = namei(cp, NAMEI_DELETE, &off, 0, 0);
|
dp = namei(path, NAMEI_DELETE, &off, 0, 0);
|
||||||
if(dp == 0)
|
if(dp == 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
|
14
kalloc.c
14
kalloc.c
|
@ -40,24 +40,22 @@ kinit(void)
|
||||||
kfree(start, mem * PAGE);
|
kfree(start, mem * PAGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Free the len bytes of memory pointed at by cp,
|
// Free the len bytes of memory pointed at by v,
|
||||||
// which normally should have been returned by a
|
// which normally should have been returned by a
|
||||||
// call to kalloc(cp). (The exception is when
|
// call to kalloc(len). (The exception is when
|
||||||
// initializing the allocator; see kinit above.)
|
// initializing the allocator; see kinit above.)
|
||||||
void
|
void
|
||||||
kfree(char *cp, int len)
|
kfree(char *v, int len)
|
||||||
{
|
{
|
||||||
struct run **rr;
|
struct run **rr;
|
||||||
struct run *p = (struct run*) cp;
|
struct run *p = (struct run*)v;
|
||||||
struct run *pend = (struct run*) (cp + len);
|
struct run *pend = (struct run*)(v + len);
|
||||||
int i;
|
|
||||||
|
|
||||||
if(len % PAGE)
|
if(len % PAGE)
|
||||||
panic("kfree");
|
panic("kfree");
|
||||||
|
|
||||||
// Fill with junk to catch dangling refs.
|
// Fill with junk to catch dangling refs.
|
||||||
for(i = 0; i < len; i++)
|
memset(v, 1, len);
|
||||||
cp[i] = 1;
|
|
||||||
|
|
||||||
acquire(&kalloc_lock);
|
acquire(&kalloc_lock);
|
||||||
|
|
||||||
|
|
4
pipe.c
4
pipe.c
|
@ -87,7 +87,7 @@ pipe_write(struct pipe *p, char *addr, int n)
|
||||||
|
|
||||||
for(i = 0; i < n; i++){
|
for(i = 0; i < n; i++){
|
||||||
while(((p->writep + 1) % PIPESIZE) == p->readp){
|
while(((p->writep + 1) % PIPESIZE) == p->readp){
|
||||||
if(p->readopen == 0 || curproc[cpu()]->killed){
|
if(p->readopen == 0 || cp->killed){
|
||||||
release(&p->lock);
|
release(&p->lock);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -111,7 +111,7 @@ pipe_read(struct pipe *p, char *addr, int n)
|
||||||
acquire(&p->lock);
|
acquire(&p->lock);
|
||||||
|
|
||||||
while(p->readp == p->writep){
|
while(p->readp == p->writep){
|
||||||
if(p->writeopen == 0 || curproc[cpu()]->killed){
|
if(p->writeopen == 0 || cp->killed){
|
||||||
release(&p->lock);
|
release(&p->lock);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
14
proc.c
14
proc.c
|
@ -59,7 +59,6 @@ setupsegs(struct proc *p)
|
||||||
int
|
int
|
||||||
growproc(int n)
|
growproc(int n)
|
||||||
{
|
{
|
||||||
struct proc *cp = curproc[cpu()];
|
|
||||||
char *newmem, *oldmem;
|
char *newmem, *oldmem;
|
||||||
|
|
||||||
newmem = kalloc(cp->sz + n);
|
newmem = kalloc(cp->sz + n);
|
||||||
|
@ -183,14 +182,14 @@ scheduler(void)
|
||||||
// before jumping back to us.
|
// before jumping back to us.
|
||||||
|
|
||||||
setupsegs(p);
|
setupsegs(p);
|
||||||
curproc[cpu()] = p;
|
cp = p;
|
||||||
p->state = RUNNING;
|
p->state = RUNNING;
|
||||||
if(setjmp(&cpus[cpu()].jmpbuf) == 0)
|
if(setjmp(&cpus[cpu()].jmpbuf) == 0)
|
||||||
longjmp(&p->jmpbuf);
|
longjmp(&p->jmpbuf);
|
||||||
|
|
||||||
// Process is done running for now.
|
// Process is done running for now.
|
||||||
// It should have changed its p->state before coming back.
|
// It should have changed its p->state before coming back.
|
||||||
curproc[cpu()] = 0;
|
cp = 0;
|
||||||
|
|
||||||
setupsegs(0);
|
setupsegs(0);
|
||||||
}
|
}
|
||||||
|
@ -204,7 +203,6 @@ scheduler(void)
|
||||||
void
|
void
|
||||||
sched(void)
|
sched(void)
|
||||||
{
|
{
|
||||||
struct proc *cp = curproc[cpu()];
|
|
||||||
|
|
||||||
if(cp->state == RUNNING)
|
if(cp->state == RUNNING)
|
||||||
panic("sched running");
|
panic("sched running");
|
||||||
|
@ -213,7 +211,7 @@ sched(void)
|
||||||
if(cpus[cpu()].nlock != 1)
|
if(cpus[cpu()].nlock != 1)
|
||||||
panic("sched locks");
|
panic("sched locks");
|
||||||
|
|
||||||
if(setjmp(&p->jmpbuf) == 0)
|
if(setjmp(&cp->jmpbuf) == 0)
|
||||||
longjmp(&cpus[cpu()].jmpbuf);
|
longjmp(&cpus[cpu()].jmpbuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -221,7 +219,6 @@ sched(void)
|
||||||
void
|
void
|
||||||
yield(void)
|
yield(void)
|
||||||
{
|
{
|
||||||
struct proc *cp = curproc[cpu()];
|
|
||||||
|
|
||||||
acquire(&proc_table_lock);
|
acquire(&proc_table_lock);
|
||||||
cp->state = RUNNABLE;
|
cp->state = RUNNABLE;
|
||||||
|
@ -238,7 +235,7 @@ forkret(void)
|
||||||
release(&proc_table_lock);
|
release(&proc_table_lock);
|
||||||
|
|
||||||
// Jump into assembly, never to return.
|
// Jump into assembly, never to return.
|
||||||
forkret1(curproc[cpu()]->tf);
|
forkret1(cp->tf);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Atomically release lock and sleep on chan.
|
// Atomically release lock and sleep on chan.
|
||||||
|
@ -246,7 +243,6 @@ forkret(void)
|
||||||
void
|
void
|
||||||
sleep(void *chan, struct spinlock *lk)
|
sleep(void *chan, struct spinlock *lk)
|
||||||
{
|
{
|
||||||
struct proc *cp = curproc[cpu()];
|
|
||||||
|
|
||||||
if(cp == 0)
|
if(cp == 0)
|
||||||
panic("sleep");
|
panic("sleep");
|
||||||
|
@ -332,7 +328,6 @@ void
|
||||||
proc_exit(void)
|
proc_exit(void)
|
||||||
{
|
{
|
||||||
struct proc *p;
|
struct proc *p;
|
||||||
struct proc *cp = curproc[cpu()];
|
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
if(cp->pid == 1)
|
if(cp->pid == 1)
|
||||||
|
@ -376,7 +371,6 @@ int
|
||||||
proc_wait(void)
|
proc_wait(void)
|
||||||
{
|
{
|
||||||
struct proc *p;
|
struct proc *p;
|
||||||
struct proc *cp = curproc[cpu()];
|
|
||||||
int i, havekids, pid;
|
int i, havekids, pid;
|
||||||
|
|
||||||
acquire(&proc_table_lock);
|
acquire(&proc_table_lock);
|
||||||
|
|
10
proc.h
10
proc.h
|
@ -50,7 +50,17 @@ struct proc {
|
||||||
// expandable heap
|
// expandable heap
|
||||||
|
|
||||||
extern struct proc proc[];
|
extern struct proc proc[];
|
||||||
|
|
||||||
|
// If xv6 was only for uniprocessors, this could be
|
||||||
|
// struct proc *cp;
|
||||||
|
// Instead we have an array curproc, one per
|
||||||
|
// processor, and #define cp to the right element
|
||||||
|
// in the array. In general such preprocessor
|
||||||
|
// subterfuge is to be avoided, but cp is used
|
||||||
|
// so often that having the shorthand is worth the ugliness.
|
||||||
extern struct proc *curproc[NCPU]; // Current (running) process per CPU
|
extern struct proc *curproc[NCPU]; // Current (running) process per CPU
|
||||||
|
#define cp (curproc[cpu()]) // Current process on this CPU
|
||||||
|
|
||||||
|
|
||||||
#define MPSTACK 512
|
#define MPSTACK 512
|
||||||
|
|
||||||
|
|
|
@ -53,7 +53,6 @@ fetchstr(struct proc *p, uint addr, char **pp)
|
||||||
int
|
int
|
||||||
argint(int argno, int *ip)
|
argint(int argno, int *ip)
|
||||||
{
|
{
|
||||||
struct proc *cp = curproc[cpu()];
|
|
||||||
|
|
||||||
return fetchint(cp, cp->tf->esp + 4 + 4*argno, ip);
|
return fetchint(cp, cp->tf->esp + 4 + 4*argno, ip);
|
||||||
}
|
}
|
||||||
|
@ -65,7 +64,6 @@ int
|
||||||
argptr(int argno, char **pp, int size)
|
argptr(int argno, char **pp, int size)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
struct proc *cp = curproc[cpu()];
|
|
||||||
|
|
||||||
if(argint(argno, &i) < 0)
|
if(argint(argno, &i) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -85,7 +83,7 @@ argstr(int argno, char **pp)
|
||||||
int addr;
|
int addr;
|
||||||
if(argint(argno, &addr) < 0)
|
if(argint(argno, &addr) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
return fetchstr(curproc[cpu()], addr, pp);
|
return fetchstr(cp, addr, pp);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern int sys_chdir(void);
|
extern int sys_chdir(void);
|
||||||
|
@ -133,7 +131,6 @@ static int (*syscalls[])(void) = {
|
||||||
void
|
void
|
||||||
syscall(void)
|
syscall(void)
|
||||||
{
|
{
|
||||||
struct proc *cp = curproc[cpu()];
|
|
||||||
int num = cp->tf->eax;
|
int num = cp->tf->eax;
|
||||||
|
|
||||||
if(num >= 0 && num < NELEM(syscalls) && syscalls[num])
|
if(num >= 0 && num < NELEM(syscalls) && syscalls[num])
|
||||||
|
|
|
@ -22,7 +22,6 @@ argfd(int argno, int *pfd, struct file **pf)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
struct file *f;
|
struct file *f;
|
||||||
struct proc *cp = curproc[cpu()];
|
|
||||||
|
|
||||||
if(argint(argno, &fd) < 0)
|
if(argint(argno, &fd) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -41,7 +40,6 @@ static int
|
||||||
fdalloc(struct file *f)
|
fdalloc(struct file *f)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
struct proc *cp = curproc[cpu()];
|
|
||||||
|
|
||||||
for(fd = 0; fd < NOFILE; fd++){
|
for(fd = 0; fd < NOFILE; fd++){
|
||||||
if(cp->ofile[fd] == 0){
|
if(cp->ofile[fd] == 0){
|
||||||
|
@ -58,7 +56,6 @@ sys_pipe(void)
|
||||||
int *fd;
|
int *fd;
|
||||||
struct file *rf = 0, *wf = 0;
|
struct file *rf = 0, *wf = 0;
|
||||||
int fd0, fd1;
|
int fd0, fd1;
|
||||||
struct proc *cp = curproc[cpu()];
|
|
||||||
|
|
||||||
if(argptr(0, (void*)&fd, 2*sizeof fd[0]) < 0)
|
if(argptr(0, (void*)&fd, 2*sizeof fd[0]) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -109,7 +106,7 @@ sys_close(void)
|
||||||
|
|
||||||
if(argfd(0, &fd, &f) < 0)
|
if(argfd(0, &fd, &f) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
curproc[cpu()]->ofile[fd] = 0;
|
cp->ofile[fd] = 0;
|
||||||
fileclose(f);
|
fileclose(f);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -242,7 +239,6 @@ sys_mkdir(void)
|
||||||
int
|
int
|
||||||
sys_chdir(void)
|
sys_chdir(void)
|
||||||
{
|
{
|
||||||
struct proc *cp = curproc[cpu()];
|
|
||||||
struct inode *ip;
|
struct inode *ip;
|
||||||
char *path;
|
char *path;
|
||||||
|
|
||||||
|
@ -316,7 +312,6 @@ sys_link(void)
|
||||||
int
|
int
|
||||||
sys_exec(void)
|
sys_exec(void)
|
||||||
{
|
{
|
||||||
struct proc *cp = curproc[cpu()];
|
|
||||||
uint sz=0, ap, sp, p1, p2;
|
uint sz=0, ap, sp, p1, p2;
|
||||||
int i, nargs, argbytes, len;
|
int i, nargs, argbytes, len;
|
||||||
struct inode *ip;
|
struct inode *ip;
|
||||||
|
|
|
@ -20,7 +20,7 @@ sys_fork(void)
|
||||||
{
|
{
|
||||||
struct proc *np;
|
struct proc *np;
|
||||||
|
|
||||||
if((np = copyproc(curproc[cpu()])) == 0)
|
if((np = copyproc(cp)) == 0)
|
||||||
return -1;
|
return -1;
|
||||||
np->state = RUNNABLE;
|
np->state = RUNNABLE;
|
||||||
return np->pid;
|
return np->pid;
|
||||||
|
@ -52,7 +52,7 @@ sys_kill(void)
|
||||||
int
|
int
|
||||||
sys_getpid(void)
|
sys_getpid(void)
|
||||||
{
|
{
|
||||||
return curproc[cpu()]->pid;
|
return cp->pid;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -60,7 +60,6 @@ sys_sbrk(void)
|
||||||
{
|
{
|
||||||
int addr;
|
int addr;
|
||||||
int n;
|
int n;
|
||||||
struct proc *cp = curproc[cpu()];
|
|
||||||
|
|
||||||
if(argint(0, &n) < 0)
|
if(argint(0, &n) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
1
trap.c
1
trap.c
|
@ -31,7 +31,6 @@ void
|
||||||
trap(struct trapframe *tf)
|
trap(struct trapframe *tf)
|
||||||
{
|
{
|
||||||
int v = tf->trapno;
|
int v = tf->trapno;
|
||||||
struct proc *cp = curproc[cpu()];
|
|
||||||
|
|
||||||
if(v == T_SYSCALL){
|
if(v == T_SYSCALL){
|
||||||
if(cp->killed)
|
if(cp->killed)
|
||||||
|
|
Loading…
Reference in a new issue