Permalink
Browse files

revert process.c

  • Loading branch information...
Frankencelery committed Oct 26, 2012
1 parent 04954aa commit 1645f56f760c521fbd3b94b915beaf98cff14acc
Showing with 53 additions and 18 deletions.
  1. +2 −0 src/tests/userprog/open-normal.c
  2. +1 −14 src/userprog/process.c
  3. +50 −4 src/userprog/syscall.c
@@ -1,12 +1,14 @@
/* Open a file. */
#include <syscall.h>
+#include <stdio.h>
#include "tests/lib.h"
#include "tests/main.h"
void
test_main (void)
{
+ printf("Opening Sample.txt");
int handle = open ("sample.txt");
if (handle < 2)
fail ("open() returned %d", handle);
View
@@ -552,36 +552,24 @@ init_cmd_line (uint8_t *kpage, uint8_t *upage, const char *cmd_line,
int argc;
char **argv;
-
-
-// OLD CODE BELOW!!! _-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
-
-
/* Push a temporary working copy of the command line string. */
- //gives us a pointer to the bottom of the stack
cmd_line_copy = push (kpage, &ofs, cmd_line, strlen (cmd_line) + 1);
if (cmd_line_copy == NULL)
return false;
-printf("Pushing: %s to %s\n",cmd_line, cmd_line_copy);
-
if (push (kpage, &ofs, &null, sizeof null) == NULL)
return false;
-printf("Pushing NULL\n");
-
/* Parse the working copy of the command line into arguments
and push them in reverse order. */
argc = 0;
for (karg = strtok_r (cmd_line_copy, " ", &saveptr); karg != NULL;
karg = strtok_r (NULL, " ", &saveptr))
{
- // translates pointer from kernel space to user space
void *uarg = upage + (karg - (char *) kpage);
if (push (kpage, &ofs, &uarg, sizeof uarg) == NULL)
return false;
argc++;
-printf("Pushing = %s\n", karg);
}
/* Reverse the order of the command line arguments. */
@@ -594,9 +582,8 @@ printf("Pushing = %s\n", karg);
|| push (kpage, &ofs, &null, sizeof null) == NULL)
return false;
-printf("upage: %u\n",upage);
/* Set initial stack pointer. */
- *esp = upage + ofs - 12;
+ *esp = upage + ofs;
return true;
}
View
@@ -45,10 +45,56 @@ syscall_init (void)
/* System call handler. */
static void
-syscall_handler (struct intr_frame *f UNUSED)
+syscall_handler (struct intr_frame *f)
{
- printf ("system call!\n");
- thread_exit ();
+ printf ("system call!\n");
+
+ typedef int syscall_function(int, int, int);
+
+ struct syscall
+ {
+ size_t arg_cnt; //Number of Arguments
+ syscall_function *func; //Implementation
+ };
+
+ /* Table of system calls */
+ static const struct syscall syscall_table[] =
+ {
+ {0, (syscall_function *) sys_halt},
+ {1, (syscall_function *) sys_exit},
+ {1, (syscall_function *) sys_exec},
+ {1, (syscall_function *) sys_wait},
+ {2, (syscall_function *) sys_create},
+ {1, (syscall_function *) sys_remove},
+ {1, (syscall_function *) sys_open},
+ {1, (syscall_function *) sys_filesize},
+ {3, (syscall_function *) sys_read},
+ {3, (syscall_function *) sys_write},
+ {2, (syscall_function *) sys_seek},
+ {1, (syscall_function *) sys_tell},
+ {1, (syscall_function *) sys_close},
+ };
+
+ const struct syscall *sc;
+ unsigned call_nr;
+ int args[3];
+
+ /* Get the system call. */
+ copy_in(&call_nr, f->esp + 1, sizeof *args * sc->arg_cnt);
+ if(call_nr >= sizeof syscall_table / sizeof *syscall_table)
+ thread_exit();
+ sc = syscall_table + call_nr;
+
+ ASSERT(sc->arg_cnt <= sizeof args / sizeof *args);
+ memset(args, 0, sizeof args);
+ copy_in(args, (uint32_t *) f->esp + 1, sizeof *args * sc->arg_cnt);
+
+ /* Execute the system call
+ * and set the return value. */
+ f->eax = sc->func(args[0], args[1], args[2]);
+
+
+ //thread_exit ();
}
/* Returns true if UADDR is a valid, mapped user address,
@@ -109,7 +155,7 @@ copy_in_string (const char *us)
char *ks;
size_t length;
- ks = palloc_get_page (0);
+ ks = palloc_get_page (PAL_ZERO | PAL_ASSERT);
if (ks == NULL)
thread_exit ();

0 comments on commit 1645f56

Please sign in to comment.