X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fuserprog%2Fprocess.c;h=5b50aa53a199e64001302574428091436809aaf8;hb=35d96421c3bdd3911dc679918ae3d81ab7479797;hp=08e78c683e0024af747573e9fb78e48d63aee4e2;hpb=421148a51f97254bd53d8a3d5965f8ea92c36684;p=pintos-anon diff --git a/src/userprog/process.c b/src/userprog/process.c index 08e78c6..5b50aa5 100644 --- a/src/userprog/process.c +++ b/src/userprog/process.c @@ -82,17 +82,24 @@ execute_thread (void *filename_) NOT_REACHED (); } -/* Destroys the user address space in T and frees all of its - resources. */ +/* Free the current process's resources. */ void -process_destroy (struct thread *t) +process_exit (void) { - ASSERT (t != thread_current ()); - - if (t->pagedir != NULL) + struct thread *cur = thread_current (); + uint32_t *pd; + + /* Destroy the current process's page directory and switch back + to the kernel-only page directory. We have to set + cur->pagedir to NULL before switching page directories, or a + timer interrupt might switch back to the process page + directory. */ + pd = cur->pagedir; + if (pd != NULL) { - pagedir_destroy (t->pagedir); - t->pagedir = NULL; + cur->pagedir = NULL; + pagedir_activate (NULL); + pagedir_destroy (pd); } } @@ -103,10 +110,11 @@ process_activate (void) { struct thread *t = thread_current (); - /* Activate T's page tables. */ + /* Activate thread's page tables. */ pagedir_activate (t->pagedir); - /* Set T's kernel stack for use in processing interrupts. */ + /* Set thread's kernel stack for use in processing + interrupts. */ tss_set_esp0 ((uint8_t *) t + PGSIZE); }