Permalink
Browse files

Merge branch 'bens'

  • Loading branch information...
2 parents 6643e01 + 2c81076 commit 7244f5e2a43a40ce42b8ca57391a24b33860165f @Frankencelery Frankencelery committed Oct 28, 2012
Showing with 42 additions and 17 deletions.
  1. +2 −0 src/lib/user/syscall.c
  2. +1 −5 src/userprog/process.c
  3. +39 −12 src/userprog/syscall.c
View
@@ -1,5 +1,6 @@
#include <syscall.h>
#include "../syscall-nr.h"
+#include <stdio.h>
/* Invokes syscall NUMBER, passing no arguments, and returns the
return value as an `int'. */
@@ -102,6 +103,7 @@ remove (const char *file)
int
open (const char *file)
{
+ printf("attemping OPEN\n");
return syscall1 (SYS_OPEN, file);
}
View
@@ -583,11 +583,7 @@ init_cmd_line (uint8_t *kpage, uint8_t *upage, const char *cmd_line,
return false;
/* Set initial stack pointer. */
- printf("PHYS_BASE: %x\n", PHYS_BASE);
- printf("upage: %x\n", upage + ofs);
-
- *esp = PHYS_BASE - 32;
- //*esp = upage + ofs;
+ *esp = upage + ofs;
return true;
}
View
@@ -46,9 +46,7 @@ syscall_init (void)
static void
syscall_handler (struct intr_frame *f)
-{
- printf ("system call!\n");
-
+{
typedef int syscall_function(int, int, int);
struct syscall
@@ -79,10 +77,9 @@ syscall_handler (struct intr_frame *f)
unsigned call_nr;
int args[3];
- printf ("system call!\n");
/* Get the system call. */
- copy_in(&call_nr, f->esp + 1, sizeof *args * sc->arg_cnt);
- printf ("system call!\n");
+ copy_in(&call_nr, f->esp, sizeof call_nr);
+
if(call_nr >= sizeof syscall_table / sizeof *syscall_table)
thread_exit();
sc = syscall_table + call_nr;
@@ -140,7 +137,6 @@ copy_in (void *dst_, const void *usrc_, size_t size)
{
uint8_t *dst = dst_;
const uint8_t *usrc = usrc_;
- printf("copying in string from userspace\n");
for (; size > 0; size--, dst++, usrc++)
if (usrc >= (uint8_t *) PHYS_BASE || !get_user (dst, usrc))
@@ -212,14 +208,32 @@ sys_wait (tid_t child)
static int
sys_create (const char *ufile, unsigned initial_size)
{
- return 0;
+ bool sucess = false;
+ char *kfile = copy_in_string(ufile);
+ lock_acquire (&fs_lock);
+ if (kfile != NULL)
+ {
+ sucess = filesys_create (kfile, (off_t)initial_size);
+ }
+ lock_release (&fs_lock);
+
+ return sucess;
}
/* Remove system call. */
static int
sys_remove (const char *ufile)
{
-/* Add code */
+ bool sucess = false;
+ char *kfile = copy_in_string(ufile);
+ lock_acquire (&fs_lock);
+ if (kfile != NULL)
+ {
+ sucess = filesys_remove (kfile) ;
+ }
+ lock_release (&fs_lock);
+
+ return sucess;
}
/* A file descriptor, for binding a file handle to a file. */
@@ -392,14 +406,27 @@ sys_tell (int handle)
static int
sys_close (int handle)
{
-/* Add code */
- thread_exit ();
+ struct file_descriptor *fd = lookup_fd(handle);
+ if (fd != NULL)
+ {
+ struct file *closeFile = fd->file;
+
+ if(closeFile != NULL)
+ {
+ lock_acquire (&fs_lock);
+ file_close (closeFile);
+ list_remove(&fd->elem);
+ lock_release (&fs_lock);
+ return true;
+ }
+ }
+ return false;
}
/* On thread exit, close all open files. */
void
syscall_exit (void)
{
-/* Add code */
+
return;
}

0 comments on commit 7244f5e

Please sign in to comment.