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 *);
struct proc * copyproc(struct proc*);
struct spinlock;
int growproc(int);
uint growproc(int);
void sleep(void *, struct spinlock *);
void wakeup(void *);
void scheduler(void);

6
proc.c
View file

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

View file

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

1
trap.c
View file

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

View file

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