From 5bbe7a03c08b236e20631c0ec05f303338d273c3 Mon Sep 17 00:00:00 2001 From: sBubshait Date: Fri, 8 Nov 2024 15:12:08 +0000 Subject: [PATCH] Add in syscall hash helper functions for open_file struct: fd_hash and fd_less, w/ E --- src/userprog/syscall.c | 23 +++++++++++++++++++++++ src/userprog/syscall.h | 5 +++++ 2 files changed, 28 insertions(+) diff --git a/src/userprog/syscall.c b/src/userprog/syscall.c index 98c9dd4..555b940 100644 --- a/src/userprog/syscall.c +++ b/src/userprog/syscall.c @@ -13,6 +13,13 @@ static struct lock filesys_lock; +struct open_file + { + int fd; /* File Descriptor / Identifier */ + struct file *file; /* Pointer to the associated file */ + struct hash_elem elem; /* elem for a hash table */ + }; + static void syscall_handler (struct intr_frame *); /* A syscall_function is a function that receives up to 3 arguments, the @@ -239,6 +246,22 @@ syscall_close (int fd UNUSED) //TODO } +unsigned +fd_hash (const struct hash_elem *element, void *aux UNUSED) +{ + return hash_int (hash_entry (element, struct open_file, elem)->fd); +} + +bool +fd_less (const struct hash_elem *a_, const struct hash_elem *b_, + void *aux UNUSED) +{ + struct open_file *a = hash_entry (a_, struct open_file, elem); + struct open_file *b = hash_entry (b_, struct open_file, elem); + + return a->fd < b->fd; +} + /* Validates if a block of memory starting at PTR and of size SIZE bytes is fully contained within user virtual memory. Kills the thread (by calling thread_exit) if the memory is invalid. Otherwise, returns the PTR given. diff --git a/src/userprog/syscall.h b/src/userprog/syscall.h index 702a6c7..9563059 100644 --- a/src/userprog/syscall.h +++ b/src/userprog/syscall.h @@ -1,8 +1,13 @@ #ifndef USERPROG_SYSCALL_H #define USERPROG_SYSCALL_H +#include + typedef int pid_t; void syscall_init (void); +unsigned fd_hash (const struct hash_elem *element, void *aux); +bool fd_less (const struct hash_elem *a, const struct hash_elem *b, void *aux); + #endif /* userprog/syscall.h */