Merge branch 'master' of git+ssh://amsterdam.csail.mit.edu/home/am0/6.828/xv6

This commit is contained in:
Frans Kaashoek 2012-08-22 20:20:17 -04:00
commit 432acbaf9e
6 changed files with 28 additions and 17 deletions

4
bio.c
View File

@ -79,9 +79,9 @@ bget(uint dev, uint sector)
} }
} }
// Not cached; recycle some existing buffer. // Not cached; recycle some non-busy and clean buffer.
for(b = bcache.head.prev; b != &bcache.head; b = b->prev){ for(b = bcache.head.prev; b != &bcache.head; b = b->prev){
if((b->flags & B_BUSY) == 0){ if((b->flags & B_BUSY) == 0 && (b->flags & B_DIRTY) == 0){
b->dev = dev; b->dev = dev;
b->sector = sector; b->sector = sector;
b->flags = B_BUSY; b->flags = B_BUSY;

4
defs.h
View File

@ -142,8 +142,8 @@ char* strncpy(char*, const char*, int);
int argint(int, int*); int argint(int, int*);
int argptr(int, char**, int); int argptr(int, char**, int);
int argstr(int, char**); int argstr(int, char**);
int fetchint(struct proc*, uint, int*); int fetchint(uint, int*);
int fetchstr(struct proc*, uint, char**); int fetchstr(uint, char**);
void syscall(void); void syscall(void);
// timer.c // timer.c

8
file.c
View File

@ -1,3 +1,7 @@
//
// File descriptors
//
#include "types.h" #include "types.h"
#include "defs.h" #include "defs.h"
#include "param.h" #include "param.h"
@ -87,7 +91,7 @@ filestat(struct file *f, struct stat *st)
return -1; return -1;
} }
// Read from file f. Addr is kernel address. // Read from file f.
int int
fileread(struct file *f, char *addr, int n) fileread(struct file *f, char *addr, int n)
{ {
@ -108,7 +112,7 @@ fileread(struct file *f, char *addr, int n)
} }
//PAGEBREAK! //PAGEBREAK!
// Write to file f. Addr is kernel address. // Write to file f.
int int
filewrite(struct file *f, char *addr, int n) filewrite(struct file *f, char *addr, int n)
{ {

1
log.c
View File

@ -177,6 +177,7 @@ log_write(struct buf *b)
brelse(lbuf); brelse(lbuf);
if (i == log.lh.n) if (i == log.lh.n)
log.lh.n++; log.lh.n++;
b->flags |= B_DIRTY; // XXX prevent eviction
} }
//PAGEBREAK! //PAGEBREAK!

View File

@ -13,28 +13,28 @@
// library system call function. The saved user %esp points // library system call function. The saved user %esp points
// to a saved program counter, and then the first argument. // to a saved program counter, and then the first argument.
// Fetch the int at addr from process p. // Fetch the int at addr from the current process.
int int
fetchint(struct proc *p, uint addr, int *ip) fetchint(uint addr, int *ip)
{ {
if(addr >= p->sz || addr+4 > p->sz) if(addr >= proc->sz || addr+4 > proc->sz)
return -1; return -1;
*ip = *(int*)(addr); *ip = *(int*)(addr);
return 0; return 0;
} }
// Fetch the nul-terminated string at addr from process p. // Fetch the nul-terminated string at addr from the current process.
// Doesn't actually copy the string - just sets *pp to point at it. // Doesn't actually copy the string - just sets *pp to point at it.
// Returns length of string, not including nul. // Returns length of string, not including nul.
int int
fetchstr(struct proc *p, uint addr, char **pp) fetchstr(uint addr, char **pp)
{ {
char *s, *ep; char *s, *ep;
if(addr >= p->sz) if(addr >= proc->sz)
return -1; return -1;
*pp = (char*)addr; *pp = (char*)addr;
ep = (char*)p->sz; ep = (char*)proc->sz;
for(s = *pp; s < ep; s++) for(s = *pp; s < ep; s++)
if(*s == 0) if(*s == 0)
return s - *pp; return s - *pp;
@ -45,7 +45,7 @@ fetchstr(struct proc *p, uint addr, char **pp)
int int
argint(int n, int *ip) argint(int n, int *ip)
{ {
return fetchint(proc, proc->tf->esp + 4 + 4*n, ip); return fetchint(proc->tf->esp + 4 + 4*n, ip);
} }
// Fetch the nth word-sized system call argument as a pointer // Fetch the nth word-sized system call argument as a pointer
@ -74,7 +74,7 @@ argstr(int n, char **pp)
int addr; int addr;
if(argint(n, &addr) < 0) if(argint(n, &addr) < 0)
return -1; return -1;
return fetchstr(proc, addr, pp); return fetchstr(addr, pp);
} }
extern int sys_chdir(void); extern int sys_chdir(void);

View File

@ -1,3 +1,9 @@
//
// File-system system calls.
// Mostly argument checking, since we don't trust
// user code, and calls into file.c and fs.c.
//
#include "types.h" #include "types.h"
#include "defs.h" #include "defs.h"
#include "param.h" #include "param.h"
@ -382,13 +388,13 @@ sys_exec(void)
for(i=0;; i++){ for(i=0;; i++){
if(i >= NELEM(argv)) if(i >= NELEM(argv))
return -1; return -1;
if(fetchint(proc, uargv+4*i, (int*)&uarg) < 0) if(fetchint(uargv+4*i, (int*)&uarg) < 0)
return -1; return -1;
if(uarg == 0){ if(uarg == 0){
argv[i] = 0; argv[i] = 0;
break; break;
} }
if(fetchstr(proc, uarg, &argv[i]) < 0) if(fetchstr(uarg, &argv[i]) < 0)
return -1; return -1;
} }
return exec(path, argv); return exec(path, argv);