summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Morris <[email protected]>2019-06-04 11:31:50 -0400
committerRobert Morris <[email protected]>2019-06-04 11:31:50 -0400
commitcff3ce6e04ce4a353324630df788df21566807a6 (patch)
tree31040a8262b6de165a2f1d6cc7ead1db33e67a80
parent0e131b226336808c135795f5b9d7defc5a58b2ae (diff)
downloadxv6-labs-cff3ce6e04ce4a353324630df788df21566807a6.tar.gz
xv6-labs-cff3ce6e04ce4a353324630df788df21566807a6.tar.bz2
xv6-labs-cff3ce6e04ce4a353324630df788df21566807a6.zip
more sbrk fixes
-rw-r--r--proc.c4
-rw-r--r--syscall.c6
-rw-r--r--sysproc.c23
-rw-r--r--trap.c5
-rw-r--r--vm.c7
5 files changed, 22 insertions, 23 deletions
diff --git a/proc.c b/proc.c
index b696d0c..768aa6d 100644
--- a/proc.c
+++ b/proc.c
@@ -500,8 +500,6 @@ wakeup(void *chan)
release(&ptable.lock);
}
-#if 0
-
// Kill the process with the given pid.
// Process won't exit until it returns
// to user space (see trap in trap.c).
@@ -525,8 +523,6 @@ kill(int pid)
return -1;
}
-#endif
-
// Copy to either a user address, or kernel address,
// depending on usr_dst.
// Returns 0 on success, -1 on error.
diff --git a/syscall.c b/syscall.c
index 10ed444..ca34f2c 100644
--- a/syscall.c
+++ b/syscall.c
@@ -144,15 +144,15 @@ static int (*syscalls[])(void) = {
[SYS_wait] sys_wait,
[SYS_pipe] sys_pipe,
[SYS_read] sys_read,
-//[SYS_kill] sys_kill,
+[SYS_kill] sys_kill,
[SYS_exec] sys_exec,
[SYS_fstat] sys_fstat,
[SYS_chdir] sys_chdir,
[SYS_dup] sys_dup,
[SYS_getpid] sys_getpid,
[SYS_sbrk] sys_sbrk,
-//[SYS_sleep] sys_sleep,
-//[SYS_uptime] sys_uptime,
+[SYS_sleep] sys_sleep,
+[SYS_uptime] sys_uptime,
[SYS_open] sys_open,
[SYS_write] sys_write,
[SYS_mknod] sys_mknod,
diff --git a/sysproc.c b/sysproc.c
index 82ad884..e57e045 100644
--- a/sysproc.c
+++ b/sysproc.c
@@ -39,24 +39,12 @@ sys_sbrk(void)
if(argint(0, &n) < 0)
return -1;
- printf("sbrk(%d), sz was %d\n", n, (int)myproc()->sz);
addr = myproc()->sz;
if(growproc(n) < 0)
return -1;
return addr;
}
-#if 0
-int
-sys_kill(void)
-{
- int pid;
-
- if(argint(0, &pid) < 0)
- return -1;
- return kill(pid);
-}
-
int
sys_sleep(void)
{
@@ -78,6 +66,16 @@ sys_sleep(void)
return 0;
}
+int
+sys_kill(void)
+{
+ int pid;
+
+ if(argint(0, &pid) < 0)
+ return -1;
+ return kill(pid);
+}
+
// return how many clock tick interrupts have occurred
// since start.
int
@@ -90,4 +88,3 @@ sys_uptime(void)
release(&tickslock);
return xticks;
}
-#endif
diff --git a/trap.c b/trap.c
index 39ff61d..47739ac 100644
--- a/trap.c
+++ b/trap.c
@@ -57,9 +57,12 @@ usertrap(void)
} else {
printf("usertrap(): unexpected scause 0x%x pid=%d\n", r_scause(), p->pid);
printf(" sepc=%p stval=%p\n", r_sepc(), r_stval());
- panic("usertrap");
+ p->killed = 1;
}
+ if(p->killed)
+ exit();
+
usertrapret();
}
diff --git a/vm.c b/vm.c
index 1e014a0..9e24ad0 100644
--- a/vm.c
+++ b/vm.c
@@ -148,8 +148,10 @@ unmappages(pagetable_t pagetable, uint64 va, uint64 size, int do_free)
for(;;){
if((pte = walk(pagetable, a, 0)) == 0)
panic("unmappages: walk");
- if((*pte & PTE_V) == 0)
+ if((*pte & PTE_V) == 0){
+ printf("va=%p pte=%p\n", a, *pte);
panic("unmappages: not mapped");
+ }
if(PTE_FLAGS(*pte) == PTE_V)
panic("unmappages: not a leaf");
if(do_free){
@@ -203,7 +205,8 @@ uvmalloc(pagetable_t pagetable, uint64 oldsz, uint64 newsz)
if(newsz < oldsz)
return oldsz;
- a = PGROUNDUP(oldsz);
+ oldsz = PGROUNDUP(oldsz);
+ a = oldsz;
for(; a < newsz; a += PGSIZE){
mem = kalloc();
if(mem == 0){