From d82476d59fb1076542a163bb2e6534023be43720 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Sun, 14 Mar 2021 13:09:18 +0100 Subject: intr_esp doesn't deref --- src/userprog/syscall.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'src/userprog') diff --git a/src/userprog/syscall.c b/src/userprog/syscall.c index a699784..0e0d97e 100644 --- a/src/userprog/syscall.c +++ b/src/userprog/syscall.c @@ -179,8 +179,8 @@ ptr_is_valid (const void *ptr) return true; } -// cast to TYPE and deref argument N from f->esp -#define INTR_ESP(N, TYPE) *(TYPE *)(f->esp+(4*(N))) +// cast argument N from f->esp to TYPE without dereferencing +#define INTR_ESP(N, TYPE) (TYPE *)(f->esp+(4*(N))) #define CHECK_ESP_AND_MAYBE_EXIT(N) \ do { \ @@ -196,7 +196,7 @@ syscall_handler (struct intr_frame *f UNUSED) { // check esp CHECK_ESP_AND_MAYBE_EXIT (0); - int syscall_number = INTR_ESP (0, int); + int syscall_number = *INTR_ESP (0, int); switch (syscall_number) { case 0: @@ -205,35 +205,35 @@ syscall_handler (struct intr_frame *f UNUSED) break; case 1: // exit - exit (INTR_ESP (1, int)); + exit (*INTR_ESP (1, int)); break; case 2: // exec - f->eax = exec (INTR_ESP (1, char *)); + f->eax = exec (*INTR_ESP (1, char *)); break; case 3: // wait - f->eax = wait (INTR_ESP (1, tid_t)); + f->eax = wait (*INTR_ESP (1, tid_t)); break; case 4: // create - f->eax = create (INTR_ESP (1, char *), INTR_ESP (2, off_t)); + f->eax = create (*INTR_ESP (1, char *), *INTR_ESP (2, off_t)); break; case 6: // open - f->eax = open (INTR_ESP (1, char *)); + f->eax = open (*INTR_ESP (1, char *)); break; case 8: // read - f->eax = read (INTR_ESP (1, int), INTR_ESP (2, void *), INTR_ESP (3, unsigned)); + f->eax = read (*INTR_ESP (1, int), *INTR_ESP (2, void *), *INTR_ESP (3, unsigned)); break; case 9: // write - f->eax = write (INTR_ESP (1, int), INTR_ESP (2, const void *), INTR_ESP (3, unsigned)); + f->eax = write (*INTR_ESP (1, int), *INTR_ESP (2, const void *), *INTR_ESP (3, unsigned)); break; case 12: // close - close (INTR_ESP (1, int)); + close (*INTR_ESP (1, int)); break; default: printf ("kernel: unknown syscall '%d'\n", syscall_number); -- cgit v1.2.1