From 62453ef432877ec31ea8b72b810d321260301982 Mon Sep 17 00:00:00 2001 From: sBubshait Date: Sun, 3 Nov 2024 22:54:03 +0000 Subject: [PATCH] Add a look up table from system call numbers to their handler functions, w/ E --- src/userprog/syscall.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/userprog/syscall.c b/src/userprog/syscall.c index 5fec7d3..6e7fb17 100644 --- a/src/userprog/syscall.c +++ b/src/userprog/syscall.c @@ -10,12 +10,24 @@ static void syscall_handler (struct intr_frame *); /* A syscall_function is a function that receives up to 3 arguments, the arguments to the functions are either ints or pointers taking up to 32 bits in size. */ -typedef uintptr_t syscall_function (uintptr_t, uintptr_t, uintptr_t); +typedef uintptr_t (*syscall_function) (uintptr_t, uintptr_t, uintptr_t); /* System Call Functions */ static void halt (void); static void exit (int status); +/* A struct defining a pair of a syscall_function along with its arity. */ +typedef struct { + syscall_function function; + int arity; +} syscall_arguments; + +/* A look-up table for system call functions mapped using their numbers. */ +static const syscall_arguments syscall_lookup[] = { + [SYS_HALT] = {(syscall_function) halt, 0}, + [SYS_EXIT] = {(syscall_function) exit, 1}, +}; + void syscall_init (void) {