i broke sbrk, fix it

This commit is contained in:
rtm 2006-08-29 17:01:40 +00:00
parent 2b19190c13
commit 3b95801add
5 changed files with 13 additions and 10 deletions

2
defs.h
View file

@ -16,7 +16,7 @@ struct jmpbuf;
void setupsegs(struct proc *); void setupsegs(struct proc *);
struct proc * copyproc(struct proc*); struct proc * copyproc(struct proc*);
struct spinlock; struct spinlock;
int growproc(int); uint growproc(int);
void sleep(void *, struct spinlock *); void sleep(void *, struct spinlock *);
void wakeup(void *); void wakeup(void *);
void scheduler(void); void scheduler(void);

6
proc.c
View file

@ -138,7 +138,7 @@ copyproc(struct proc* p)
return np; return np;
} }
int uint
growproc(int n) growproc(int n)
{ {
struct proc *cp = curproc[cpu()]; struct proc *cp = curproc[cpu()];
@ -146,14 +146,14 @@ growproc(int n)
newmem = kalloc(cp->sz + n); newmem = kalloc(cp->sz + n);
if(newmem == 0) if(newmem == 0)
return -1; return 0xffffffff;
memmove(newmem, cp->mem, cp->sz); memmove(newmem, cp->mem, cp->sz);
memset(newmem + cp->sz, 0, n); memset(newmem + cp->sz, 0, n);
oldmem = cp->mem; oldmem = cp->mem;
cp->mem = newmem; cp->mem = newmem;
kfree(oldmem, cp->sz); kfree(oldmem, cp->sz);
cp->sz += n; cp->sz += n;
return 0; return cp->sz - n;
} }
// Per-CPU process scheduler. // Per-CPU process scheduler.

View file

@ -473,15 +473,16 @@ sys_getpid(void)
int int
sys_sbrk(void) sys_sbrk(void)
{ {
unsigned addr;
int n; int n;
struct proc *cp = curproc[cpu()]; struct proc *cp = curproc[cpu()];
if(fetcharg(0, &n) < 0) if(fetcharg(0, &n) < 0)
return -1; return -1;
if(growproc(n) != 0) if((addr = growproc(n)) == 0xffffffff)
return -1; return -1;
setupsegs(cp); setupsegs(cp);
return 0; return addr;
} }
int int

1
trap.c
View file

@ -37,7 +37,6 @@ trap(struct trapframe *tf)
if(v == T_SYSCALL){ if(v == T_SYSCALL){
struct proc *cp = curproc[cpu()]; struct proc *cp = curproc[cpu()];
int num = cp->tf->eax;
if(cp->killed) if(cp->killed)
proc_exit(); proc_exit();
cp->tf = tf; cp->tf = tf;

View file

@ -124,6 +124,7 @@ mem(void)
m1 = 0; m1 = 0;
while ((m2 = malloc(1024)) != 0) { while ((m2 = malloc(1024)) != 0) {
printf(1, "malloc %x\n", m2);
*(char **) m2 = m1; *(char **) m2 = m1;
m1 = m2; m1 = m2;
} }
@ -138,6 +139,8 @@ mem(void)
exit(); exit();
} }
free(m1); free(m1);
printf(1, "mem ok\n");
} }
int int
@ -145,10 +148,10 @@ main(int argc, char *argv[])
{ {
puts("usertests starting\n"); puts("usertests starting\n");
// pipe1();
// preempt();
// exitwait();
mem(); mem();
pipe1();
preempt();
exitwait();
puts("usertests finished\n"); puts("usertests finished\n");
exit(); exit();