Skip to content
Snippets Groups Projects
Commit 3de44370 authored by a3-alsayed's avatar a3-alsayed
Browse files

Update src/userprog/syscall.c

parent e8aa210f
No related branches found
No related tags found
No related merge requests found
#include "userprog/syscall.h" #include "userprog/syscall.h"
#include <stdio.h> #include <stdio.h>
#include <syscall-nr.h> #include <syscall-nr.h>
#include "devices/shutdown.h"
#include "threads/synch.h"
#include "threads/interrupt.h" #include "threads/interrupt.h"
#include "threads/thread.h" #include "threads/thread.h"
#include "userprog/process.h"
#include "filesys/filesys.h"
typedef int pid_p;
static struct lock f_lock;
static void syscall_handler (struct intr_frame *); static void syscall_handler (struct intr_frame *);
static uint32_t load_stack(struct intr_frame *f, int offset);
/*Function for system call*/
void syscall_halt(void);
void syscall_exit(int);
int syscall_wait (pid_p pid);
bool syscall_create (const char *file, unsigned initial_size);
/*End of system call function*/
void void
syscall_init (void) syscall_init (void)
...@@ -12,10 +26,71 @@ syscall_init (void) ...@@ -12,10 +26,71 @@ syscall_init (void)
intr_register_int (0x30, 3, INTR_ON, syscall_handler, "syscall"); intr_register_int (0x30, 3, INTR_ON, syscall_handler, "syscall");
} }
static uint32_t load_stack(struct intr_frame *f, int offset)
{
return *((uint32_t*)(f->esp + offset));
}
static void static void
syscall_handler (struct intr_frame *f UNUSED) syscall_handler (struct intr_frame *f UNUSED)
{ {
printf ("system call!\n"); int code = (int)load_stack(f, 0);
lock_init(&f_lock);
switch (code)
{
case SYS_HALT:
{
syscall_halt();
break;
}
case SYS_EXIT:
{
syscall_exit((int)load_stack(f,4));
break;
}
case SYS_WAIT:
{
f->eax = syscall_wait((int)load_stack(f,4));
break;
}
case SYS_CREATE:
{
f->eax = syscall_create((const char*)load_stack(f,4), (unsigned)load_stack(f,8));
break;
}
default:
{
printf ("system call (%d) not implemented!\n", code);
thread_exit (); thread_exit ();
} }
}
}
void syscall_halt (void)
{
shutdown_power_off();
}
void syscall_exit (int status)
{
struct thread *cur = thread_current ();
cur->exit_status = status;
thread_exit();
}
int syscall_wait (pid_p pid)
{
return process_wait (pid);
}
bool syscall_create (const char *file, unsigned initial_size)
{
lock_acquire(&f_lock);
bool success = filesys_create(file, initial_size);
lock_release(&f_lock);
return success;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment