From b1c58194695b8321f532e9f715254c91f9cb6f6e Mon Sep 17 00:00:00 2001 From: sBubshait Date: Wed, 13 Nov 2024 18:06:51 +0000 Subject: [PATCH] Avoid masking the struct syscall_arguments using typedef for consistency --- src/userprog/syscall.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/userprog/syscall.c b/src/userprog/syscall.c index 85deffc..34f85fe 100644 --- a/src/userprog/syscall.c +++ b/src/userprog/syscall.c @@ -14,6 +14,7 @@ #include #define MAX_SYSCALL_ARGS 3 +#define EXIT_FAILURE -1 static unsigned fd_counter = MIN_USER_FD; @@ -51,15 +52,15 @@ static void validate_user_pointer (const void *start, size_t size); static void validate_user_string (const char *str); /* A struct defining a syscall_function pointer along with its arity. */ -typedef struct +struct syscall_arguments { syscall_function function; /* Function pointer. */ int arity; /* Number of arguments of the function. */ - } syscall_arguments; + }; /* A look-up table mapping numbers to system call functions with their number of arguments. */ -static const syscall_arguments syscall_lookup[] = +static const struct syscall_arguments syscall_lookup[] = { [SYS_HALT] = {(syscall_function) syscall_halt, 0}, [SYS_EXIT] = {(syscall_function) syscall_exit, 1}, @@ -79,7 +80,7 @@ static const syscall_arguments syscall_lookup[] = /* The number of syscall functions (i.e, number of elements) within the syscall_lookup table. */ static const int LOOKUP_SIZE - = sizeof (syscall_lookup) / sizeof (syscall_arguments); + = sizeof (syscall_lookup) / sizeof (struct syscall_arguments); /* Initialises the syscall handling system, as well as a global lock to synchronise all file access between processes. */ @@ -104,7 +105,7 @@ syscall_handler (struct intr_frame *f) if (syscall_number >= LOOKUP_SIZE) syscall_exit (EXIT_FAILURE); - syscall_arguments syscall = syscall_lookup[syscall_number]; + struct syscall_arguments syscall = syscall_lookup[syscall_number]; /* Next, read and copy the arguments from the stack pointer. */ validate_user_pointer (f->esp + sizeof (uintptr_t),