From: Nathaniel Wesley Filardo Date: Tue, 27 Oct 2015 00:42:02 +0000 (-0400) Subject: A few small cosmetic changes X-Git-Url: https://hydra-www.ietfng.org/gitweb/?a=commitdiff_plain;h=d006c4d0c7f04579089b5f102c18b99055b7e19b;p=xv6-public A few small cosmetic changes Comments, fixing a panic() message, and making trap.c a little more debugger friendly (now possible to breakpoint specifically on a trap-induced exit, rather than the syscall) --- diff --git a/proc.h b/proc.h index 3b9c3ac..ac91b71 100644 --- a/proc.h +++ b/proc.h @@ -27,6 +27,14 @@ extern int ncpu; // holding those two variables in the local cpu's struct cpu. // This is similar to how thread-local variables are implemented // in thread libraries such as Linux pthreads. +// +// One must be very careful with cpu as we might migrate; that is, in +// general, it is only safe to access this variable and *do* anything with +// it while local preemption is disabled. +// +// proc is *observably constant* from a particular proc's perspective, on +// the other hand (the scheduler always restores its value) and so is in +// general safe to access without holding any locks. extern struct cpu *cpu asm("%gs:0"); // &cpus[cpunum()] extern struct proc *proc asm("%gs:4"); // cpus[cpunum()].proc diff --git a/trap.c b/trap.c index 6118f81..043c9e4 100644 --- a/trap.c +++ b/trap.c @@ -32,6 +32,13 @@ idtinit(void) } //PAGEBREAK: 41 +// This is here so you can break on it in gdb +static void +trap_exit() +{ + sti(); + exit(); +} void trap(struct trapframe *tf) { @@ -97,7 +104,7 @@ trap(struct trapframe *tf) // (If it is still executing in the kernel, let it keep running // until it gets to the regular system call return.) if(proc && proc->killed && (tf->cs&3) == DPL_USER) - exit(); + trap_exit(); // Force process to give up CPU on clock tick. // If interrupts were on while locks held, would need to check nlock. @@ -106,5 +113,5 @@ trap(struct trapframe *tf) // Check if the process has been killed since we yielded if(proc && proc->killed && (tf->cs&3) == DPL_USER) - exit(); + trap_exit(); } diff --git a/vm.c b/vm.c index b340696..a58ef21 100644 --- a/vm.c +++ b/vm.c @@ -267,7 +267,7 @@ deallocuvm(pde_t *pgdir, uint oldsz, uint newsz) else if((*pte & PTE_P) != 0){ pa = PTE_ADDR(*pte); if(pa == 0) - panic("kfree"); + panic("deallocuvm"); char *v = P2V(pa); kfree(v); *pte = 0;