Implement basic syscall_handler using the lookup table, w/ E
This commit is contained in:
@@ -17,6 +17,8 @@ typedef uintptr_t (*syscall_function) (uintptr_t, uintptr_t, uintptr_t);
|
|||||||
static void halt (void);
|
static void halt (void);
|
||||||
static void exit (int status);
|
static void exit (int status);
|
||||||
|
|
||||||
|
static void *validate_user_pointer(void *ptr, size_t size);
|
||||||
|
|
||||||
/* A struct defining a pair of a syscall_function along with its arity. */
|
/* A struct defining a pair of a syscall_function along with its arity. */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
syscall_function function;
|
syscall_function function;
|
||||||
@@ -29,6 +31,9 @@ static const syscall_arguments syscall_lookup[] = {
|
|||||||
[SYS_EXIT] = {(syscall_function) exit, 1},
|
[SYS_EXIT] = {(syscall_function) exit, 1},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static const int lookup_size
|
||||||
|
= sizeof (syscall_lookup) / sizeof (syscall_arguments);
|
||||||
|
|
||||||
void
|
void
|
||||||
syscall_init (void)
|
syscall_init (void)
|
||||||
{
|
{
|
||||||
@@ -36,10 +41,23 @@ syscall_init (void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
syscall_handler (struct intr_frame *f UNUSED)
|
syscall_handler (struct intr_frame *f)
|
||||||
{
|
{
|
||||||
printf ("system call!\n");
|
validate_user_pointer(f->esp, 1);
|
||||||
thread_exit ();
|
int syscall_number = *(int *) f->esp;
|
||||||
|
|
||||||
|
if (syscall_number < 0 || syscall_number >= lookup_size)
|
||||||
|
thread_exit ();
|
||||||
|
|
||||||
|
syscall_arguments syscall = syscall_lookup[syscall_number];
|
||||||
|
|
||||||
|
validate_user_pointer (f->esp, syscall.arity);
|
||||||
|
uintptr_t args[3];
|
||||||
|
|
||||||
|
for (int i=0; i < syscall.arity; i++)
|
||||||
|
args[i] = *(uintptr_t *) (f->esp + 1 + i);
|
||||||
|
|
||||||
|
f->eax = syscall.function(args[0], args[1], args[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|||||||
Reference in New Issue
Block a user