proc: make switch_to(NULL) a noop

Previously, it would switch out of any address space and into the
boot_pgdir.  However, it wouldn't permanently leave the process's
address space, and boot_pgdir is mapped in all address spaces.  No one
was using it in this manner.

Although I can think of reasons to do this, no one was doing it, and
it's more convenient to have NULL be a noop.  In particular, this is for
PCI code that may or may not need to switch into a process's address
space.

Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
diff --git a/kern/src/process.c b/kern/src/process.c
index 44d8c50..78fcf8d 100644
--- a/kern/src/process.c
+++ b/kern/src/process.c
@@ -1910,7 +1910,9 @@
 }
 
 /* Switches to the address space/context of new_p, doing nothing if we are
- * already in new_p.  This won't add extra refcnts or anything, and needs to be
+ * already in new_p.  You can pass NULL for a noop.
+ *
+ * This won't add extra refcnts or anything, and needs to be
  * paired with switch_back() at the end of whatever function you are in.
  * Specifically, the uncounted refs are one for the old_proc, which is passed
  * back to the caller, and new_p is getting placed in cur_proc. */
@@ -1921,14 +1923,13 @@
 	struct proc *old_proc;
 	uintptr_t ret;
 
+	if (!new_p)
+		return -1;
 	old_proc = pcpui->cur_proc;		/* uncounted ref */
 	/* If we aren't the proc already, then switch to it */
 	if (old_proc != new_p) {
 		pcpui->cur_proc = new_p;	/* uncounted ref */
-		if (new_p)
-			lcr3(new_p->env_cr3);
-		else
-			lcr3(boot_cr3);
+		lcr3(new_p->env_cr3);
 	}
 	ret = (uintptr_t)old_proc;
 	if (is_ktask(kth)) {
@@ -1950,6 +1951,8 @@
 	struct kthread *kth = pcpui->cur_kthread;
 	struct proc *old_proc;
 
+	if (!new_p)
+		return;
 	if (is_ktask(kth)) {
 		if (old_ret & 0x1) {
 			kth->flags &= ~KTH_SAVE_ADDR_SPACE;