X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fuserprog%2Fprocess.c;h=36c1bd0582437d280e630788d605ab9f87409bd1;hb=691750d03ff70aa5cef5fba81fed82e3a941bf95;hp=08e78c683e0024af747573e9fb78e48d63aee4e2;hpb=f0612244c44f4b4f0bc79e3fc882e9f74bd4a3f4;p=pintos-anon diff --git a/src/userprog/process.c b/src/userprog/process.c index 08e78c6..36c1bd0 100644 --- a/src/userprog/process.c +++ b/src/userprog/process.c @@ -31,7 +31,7 @@ process_execute (const char *filename) /* Make a copy of FILENAME. Otherwise there's a race between the caller and load(). */ - fn_copy = palloc_get (0); + fn_copy = palloc_get_page (0); if (fn_copy == NULL) return TID_ERROR; strlcpy (fn_copy, filename, PGSIZE); @@ -39,7 +39,7 @@ process_execute (const char *filename) /* Create a new thread to execute FILENAME. */ tid = thread_create (filename, PRI_DEFAULT, execute_thread, fn_copy); if (tid == TID_ERROR) - palloc_free (fn_copy); + palloc_free_page (fn_copy); return tid; } @@ -62,7 +62,7 @@ execute_thread (void *filename_) success = load (filename, &if_.eip, &if_.esp); /* If load failed, quit. */ - palloc_free (filename); + palloc_free_page (filename); if (!success) thread_exit (); @@ -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); } @@ -339,14 +347,14 @@ load_segment (struct file *file, const struct Elf32_Phdr *phdr) file into the page and zero the rest. */ size_t read_bytes = filesz_left >= PGSIZE ? PGSIZE : filesz_left; size_t zero_bytes = PGSIZE - read_bytes; - uint8_t *kpage = palloc_get (PAL_USER); + uint8_t *kpage = palloc_get_page (PAL_USER); if (kpage == NULL) return false; /* Do the reading and zeroing. */ if (file_read (file, kpage, read_bytes) != (int) read_bytes) { - palloc_free (kpage); + palloc_free_page (kpage); return false; } memset (kpage + read_bytes, 0, zero_bytes); @@ -355,7 +363,7 @@ load_segment (struct file *file, const struct Elf32_Phdr *phdr) /* Add the page to the process's address space. */ if (!install_page (upage, kpage)) { - palloc_free (kpage); + palloc_free_page (kpage); return false; } } @@ -371,14 +379,14 @@ setup_stack (void **esp) uint8_t *kpage; bool success = false; - kpage = palloc_get (PAL_USER | PAL_ZERO); + kpage = palloc_get_page (PAL_USER | PAL_ZERO); if (kpage != NULL) { success = install_page (((uint8_t *) PHYS_BASE) - PGSIZE, kpage); if (success) *esp = PHYS_BASE; else - palloc_free (kpage); + palloc_free_page (kpage); } else printf ("failed to allocate process stack\n");