Fix for updated comments.
[pintos-anon] / solutions / p3.patch
index bc0b77daf8c42b7f70ae394f04396e0776af9ddb..69e7d4baf30d179658f9beedb48be58f62a10e9f 100644 (file)
@@ -633,7 +633,7 @@ diff -u src/userprog/process.c~ src/userprog/process.c
  
    ASSERT (file != NULL);
    ASSERT (phdr != NULL);
-@@ -360,69 +471,129 @@ load_segment (struct file *file, const s
+@@ -360,73 +471,129 @@ load_segment (struct file *file, const s
        return false; 
      }
  
@@ -728,8 +728,12 @@ diff -u src/userprog/process.c~ src/userprog/process.c
  }
  
 -/* Adds a mapping from user virtual address UPAGE to kernel
--   virtual address KPAGE to the page table.  Fails if UPAGE is
--   already mapped or if memory allocation fails. */
+-   virtual address KPAGE to the page table.
+-   UPAGE must not already be mapped.
+-   KPAGE should probably be a page obtained from the user pool
+-   with palloc_get_page().
+-   Returns true on success, false if UPAGE is already mapped or
+-   if memory allocation fails. */
 +/* Sets up command line arguments in KPAGE, which will be mapped
 +   to UPAGE in user space.  The command line arguments are taken
 +   from CMD_LINE, separated by spaces.  Sets *ESP to the initial
@@ -1579,7 +1583,7 @@ diff -u src/vm/frame.h~ src/vm/frame.h
 diff -u src/vm/page.c~ src/vm/page.c
 --- src/vm/page.c~ 1969-12-31 16:00:00.000000000 -0800
 +++ src/vm/page.c 2005-06-08 14:10:54.000000000 -0700
-@@ -0,0 +1,297 @@
+@@ -0,0 +1,293 @@
 +#include "vm/page.h"
 +#include <stdio.h>
 +#include <string.h>
@@ -1594,29 +1598,25 @@ diff -u src/vm/page.c~ src/vm/page.c
 +/* Maximum size of process stack, in bytes. */
 +#define STACK_MAX (1024 * 1024)
 +
++/* Destroys a page, which must be in the current process's
++   page table.  Used as a callback for hash_destroy(). */
++static void
++destroy_page (struct hash_elem *p_, void *aux UNUSED)
++{
++  struct page *p = hash_entry (p_, struct page, hash_elem);
++  frame_lock (p);
++  if (p->frame)
++    frame_free (p->frame);
++  free (p);
++}
++
 +/* Destroys the current process's page table. */
 +void
 +page_exit (void) 
 +{
-+  struct hash *h;
-+  struct hash_iterator i;
-+
-+  h = thread_current ()->pages;
-+  if (h == NULL)
-+    return;
-+  
-+  hash_first (&i, h);
-+  hash_next (&i);
-+  while (hash_cur (&i))
-+    {
-+      struct page *p = hash_entry (hash_cur (&i), struct page, hash_elem);
-+      hash_next (&i);
-+      frame_lock (p);
-+      if (p->frame)
-+        frame_free (p->frame);
-+      free (p);
-+    }
-+  hash_destroy (h);
++  struct hash *h = thread_current ()->pages;
++  if (h != NULL)
++    hash_destroy (h, destroy_page);
 +}
 +
 +/* Returns the page containing the given virtual ADDRESS,