From ef67c6ad9ff46574076efd2e6cda52e20874e4aa Mon Sep 17 00:00:00 2001 From: Claudio Maggioni Date: Mon, 25 May 2020 21:18:53 +0200 Subject: [PATCH] I am fed up with this --- pintos-env/pintos/userprog/syscall.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/pintos-env/pintos/userprog/syscall.c b/pintos-env/pintos/userprog/syscall.c index 2d12b76..64c5dc4 100755 --- a/pintos-env/pintos/userprog/syscall.c +++ b/pintos-env/pintos/userprog/syscall.c @@ -125,7 +125,6 @@ int sys_open(const char* file) { fd->fd = next_fd++; //printf("Hash put: %x %d\n", file_opened, fd->fd); hash_insert(&fd_table, &fd->elem); - lock_release (&filesys_lock); return fd->fd; } @@ -134,7 +133,9 @@ int sys_filesize(int fd) { lock_acquire (&filesys_lock); struct fd_item i; i.fd = fd; - struct fd_item* file_d = hash_entry(hash_find(&fd_table, &i.elem), struct fd_item, elem); + struct hash_elem* h = hash_find(&fd_table, &i.elem); + if (h == NULL) sys_exit(-1); + struct fd_item* file_d = hash_entry(h, struct fd_item, elem); if(file_d == NULL) { lock_release (&filesys_lock); @@ -150,7 +151,9 @@ void sys_seek(int fd, unsigned position) { lock_acquire (&filesys_lock); struct fd_item i; i.fd = fd; - struct fd_item* file_d = hash_entry(hash_find(&fd_table, &i.elem), struct fd_item, elem); + struct hash_elem* h = hash_find(&fd_table, &i.elem); + if (h == NULL) sys_exit(-1); + struct fd_item* file_d = hash_entry(h, struct fd_item, elem); if(file_d && file_d->file) { file_seek(file_d->file, position); @@ -165,7 +168,9 @@ unsigned sys_tell(int fd) { lock_acquire (&filesys_lock); struct fd_item i; i.fd = fd; - struct fd_item* file_d = hash_entry(hash_find(&fd_table, &i.elem), struct fd_item, elem); + struct hash_elem* h = hash_find(&fd_table, &i.elem); + if (h == NULL) sys_exit(-1); + struct fd_item* file_d = hash_entry(h, struct fd_item, elem); unsigned ret; if(file_d && file_d->file) {