@@ -14,11 +14,23 @@
#include "threads/init.h"
#include "threads/interrupt.h"
- #include "threads/mmu.h"
+#include "threads/malloc.h"
#include "threads/palloc.h"
#include "threads/thread.h"
+ #include "threads/vaddr.h"
static thread_func execute_thread NO_RETURN;
-static bool load (const char *cmdline, void (**eip) (void), void **esp);
to the kernel-only page directory. */
pd = cur->pagedir;
@@ -193,7 +284,7 @@ struct Elf32_Phdr
+ #define PF_W 2 /* Writable. */
#define PF_R 4 /* Readable. */
- static bool load_segment (struct file *, const struct Elf32_Phdr *);
-static bool setup_stack (void **esp);
+static bool setup_stack (const char *cmd_line, void **esp);
-
- /* Loads an ELF executable from FILENAME into the current thread.
- Stores the executable's entry point into *EIP
+ static bool validate_segment (const struct Elf32_Phdr *, struct file *);
+ static bool load_segment (struct file *file, off_t ofs, uint8_t *upage,
+ bool writable);
@@ -209,13 +300,15 @@ static bool setup_stack (void **esp);
and its initial stack pointer into *ESP.
Returns true if successful, false otherwise. */
kpage = palloc_get_page (PAL_USER | PAL_ZERO);
if (kpage != NULL)
{
-- success = install_page (((uint8_t *) PHYS_BASE) - PGSIZE, kpage);
+- success = install_page (((uint8_t *) PHYS_BASE) - PGSIZE, kpage, true);
- if (success)
- *esp = PHYS_BASE;
+ uint8_t *upage = ((uint8_t *) PHYS_BASE) - PGSIZE;
-+ if (install_page (upage, kpage))
++ if (install_page (upage, kpage, true))
+ success = init_cmd_line (kpage, upage, cmd_line, esp);
else
palloc_free_page (kpage);
diff -u src/userprog/syscall.c~ src/userprog/syscall.c
--- src/userprog/syscall.c~ 2004-09-26 14:15:17.000000000 -0700
+++ src/userprog/syscall.c 2005-06-08 13:45:28.000000000 -0700
-@@ -1,20 +1,480 @@
+@@ -1,20 +1,482 @@
#include "userprog/syscall.h"
#include <stdio.h>
+#include <string.h>
+#include "threads/init.h"
#include "threads/interrupt.h"
+#include "threads/malloc.h"
-+#include "threads/mmu.h"
+#include "threads/palloc.h"
#include "threads/thread.h"
++#include "threads/vaddr.h"
-
+
+
+ struct file_descriptor *fd;
+ fd = list_entry (e, struct file_descriptor, elem);
+ next = list_next (e);
++ lock_acquire (&fs_lock);
+ file_close (fd->file);
++ lock_release (&fs_lock);
+ free (fd);
+ }
+}