+#include <round.h>
+#include <stdio.h>
+#include <string.h>
+#include "userprog/gdt.h"
+#include "userprog/pagedir.h"
+#include "userprog/tss.h"
+#include "filesys/directory.h"
+#include "filesys/file.h"
+#include "filesys/filesys.h"
+#include "threads/flags.h"
+#include "threads/init.h"
+#include "threads/interrupt.h"
+#include "threads/mmu.h"
+#include "threads/palloc.h"
+#include "threads/thread.h"
+
+static thread_func execute_thread NO_RETURN;
+static bool load (const char *cmdline, void (**eip) (void), void **esp);
+
+/* Starts a new thread running a user program loaded from
+ FILENAME. The new thread may be scheduled before
+ addrspace_execute() returns.*/
+tid_t
+addrspace_execute (const char *filename)
+{
+ char *fn_copy;
+ tid_t tid;
+
+ /* Make a copy of FILENAME.
+ Otherwise there's a race between the caller and load(). */
+ fn_copy = palloc_get (0);
+ if (fn_copy == NULL)
+ return TID_ERROR;
+ strlcpy (fn_copy, filename, PGSIZE);
+
+ /* 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);
+ return tid;
+}