Implement basic syscall_handler using the lookup table, w/ E

This commit is contained in:
sBubshait
2024-11-03 23:47:22 +00:00
parent 87126237ad
commit d626b7a392

View File

@@ -17,6 +17,8 @@ typedef uintptr_t (*syscall_function) (uintptr_t, uintptr_t, uintptr_t);
static void halt (void);
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. */
typedef struct {
syscall_function function;
@@ -29,6 +31,9 @@ static const syscall_arguments syscall_lookup[] = {
[SYS_EXIT] = {(syscall_function) exit, 1},
};
static const int lookup_size
= sizeof (syscall_lookup) / sizeof (syscall_arguments);
void
syscall_init (void)
{
@@ -36,10 +41,23 @@ syscall_init (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);
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