Skip to content
Snippets Groups Projects
Commit 92c02b48 authored by Shancang Li's avatar Shancang Li
Browse files

Delete #syscall.c#

parent 84e4546c
No related branches found
No related tags found
No related merge requests found
#include "userprog/syscall.h"
#include <stdio.h>
#include <syscall-nr.h>
#include "threads/interrupt.h"
#include "threads/thread.h"
static void syscall_handler (struct intr_frame *);
void
syscall_init (void)
{
intr_register_int (0x30, 3, INTR_ON, syscall_handler, "syscall");
}
#if defined(BEN_MODS)
static uint32_t load_stack(struct intr_frame *f, int offset)
{
// need to add check for valid address
// i.e. user can do bad things
return *((uint32_t*)(f->esp + offset));
}
static void handle_halt(void)
{
printf("handle_halt\n");
}
static void handle_exit(int status)
{
struct thread * current = thread_current();
current->process_info->exit_status = status;
thread_exit();
}
static tid_t handle_exec(const char *file)
{
printf("handle_exec\n");
return 0;
}
static int handle_wait(tid_t tid)
{
printf("handle_wait\n");
return 0;
}
// file stuff
static int handle_write(int fd, const void * buffer, unsigned int length)
{
// TODO: @bgaster -- validate fd and buffer ptr
if (fd == STDOUT_FILENO) {
putbuf((const char *)buffer, (size_t)length);
}
else {
printf("handle_write does not support fd output\n");
}
return length;
}
#define ARG_CODE 0
#define ARG_1 4
#define ARG_2 8
#define ARG_3 12
#endif
static void
#if defined(BEN_MODS)
syscall_handler (struct intr_frame *f)
#else
syscall_handler (struct intr_frame *f UNUSED)
#endif
{
#if defined(BEN_MODS)
int code = (int)load_stack(f, ARG_CODE);
switch (code) {
case SYS_EXIT:
handle_exit((int)load_stack(f,ARG_1));
break; // will not return here
case SYS_WRITE:
{
int result = handle_write(
(int)load_stack(f,ARG_1),
(void *)load_stack(f, ARG_2),
(unsigned int)load_stack(f, ARG_3));
// set return value
f->eax = result;
break;
}
default:
printf("SYS_CALL (%d) not implemented\n", code);
thread_exit ();
}
#else
printf ("system call!\n");
thread_exit ();
#endif
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment