Add constant MAX_SYSCALL_ARGS to avoid magic numbers [Gleb]
This commit is contained in:
@@ -13,6 +13,8 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <syscall-nr.h>
|
#include <syscall-nr.h>
|
||||||
|
|
||||||
|
#define MAX_SYSCALL_ARGS 3
|
||||||
|
|
||||||
static unsigned fd_counter = MIN_USER_FD;
|
static unsigned fd_counter = MIN_USER_FD;
|
||||||
|
|
||||||
struct open_file
|
struct open_file
|
||||||
@@ -96,8 +98,8 @@ static void
|
|||||||
syscall_handler (struct intr_frame *f)
|
syscall_handler (struct intr_frame *f)
|
||||||
{
|
{
|
||||||
/* First, read the system call number from the stack. */
|
/* First, read the system call number from the stack. */
|
||||||
validate_user_pointer (f->esp, 1);
|
validate_user_pointer (f->esp, sizeof (uintptr_t));
|
||||||
unsigned syscall_number = *(int *) f->esp;
|
uintptr_t syscall_number = *(int *) f->esp;
|
||||||
|
|
||||||
/* Ensures the number corresponds to a system call that can be handled. */
|
/* Ensures the number corresponds to a system call that can be handled. */
|
||||||
if (syscall_number >= LOOKUP_SIZE)
|
if (syscall_number >= LOOKUP_SIZE)
|
||||||
@@ -108,9 +110,9 @@ syscall_handler (struct intr_frame *f)
|
|||||||
/* Next, read and copy the arguments from the stack pointer. */
|
/* Next, read and copy the arguments from the stack pointer. */
|
||||||
validate_user_pointer (f->esp + sizeof (uintptr_t),
|
validate_user_pointer (f->esp + sizeof (uintptr_t),
|
||||||
syscall.arity * sizeof (uintptr_t));
|
syscall.arity * sizeof (uintptr_t));
|
||||||
uintptr_t args[3] = {0};
|
uintptr_t args[MAX_SYSCALL_ARGS] = {0};
|
||||||
for (int i=0; i < syscall.arity; i++)
|
for (int i = 0; i < syscall.arity && i < MAX_SYSCALL_ARGS; i++)
|
||||||
args[i] = *(uintptr_t *) (f->esp + sizeof (uintptr_t) * (i + 1));
|
args[i] = *(uintptr_t *) (f->esp + sizeof (uintptr_t) * (i + 1));
|
||||||
|
|
||||||
/* Call the function that handles this system call with the arguments. When
|
/* Call the function that handles this system call with the arguments. When
|
||||||
there is a return value it is stored in f->eax. */
|
there is a return value it is stored in f->eax. */
|
||||||
|
|||||||
Reference in New Issue
Block a user