diff --git a/src/threads/thread.c b/src/threads/thread.c index 74ac41e..1fcbc01 100644 --- a/src/threads/thread.c +++ b/src/threads/thread.c @@ -688,6 +688,7 @@ init_thread (struct thread *t, const char *name, int nice, int priority, t->recent_cpu = recent_cpu; t->priority = t->base_priority; + t->fd_counter = MINIMUM_USER_FD; t->exit_status = -1; list_init (&t->child_results); diff --git a/src/threads/thread.h b/src/threads/thread.h index 33a5485..c18500b 100644 --- a/src/threads/thread.h +++ b/src/threads/thread.h @@ -32,6 +32,9 @@ typedef int tid_t; #define NICE_DEFAULT 0 /* Default niceness. */ #define NICE_MAX 20 /* Highest niceness. */ +/* File Descriptors. */ +#define MINIMUM_USER_FD 2 /* Minimum file descriptor for user programs. */ + /* A process result, synchronised between parent and child. */ struct process_result { @@ -137,7 +140,9 @@ struct thread #ifdef USERPROG /* Owned by userprog/process.c. */ uint32_t *pagedir; /* Page directory. */ - struct hash open_files; /* Hash Table of FD -> Struct File */ + unsigned int fd_counter; /* File descriptor counter for thread's + open files. */ + struct hash open_files; /* Hash Table of FD -> Struct File. */ #endif /* Owned by thread.c. */ diff --git a/src/userprog/syscall.c b/src/userprog/syscall.c index 1759bf1..015ebb7 100644 --- a/src/userprog/syscall.c +++ b/src/userprog/syscall.c @@ -16,8 +16,6 @@ #define MAX_SYSCALL_ARGS 3 #define EXIT_FAILURE -1 -static unsigned fd_counter = MIN_USER_FD; - struct open_file { int fd; /* File Descriptor / Identifier */ @@ -224,7 +222,7 @@ syscall_open (const char *file) } /* Populate the above struct, with a unique FD and the current open file */ - file_info->fd = fd_counter++; + file_info->fd = thread_current ()->fd_counter++; file_info->file = ptr; /* Add the new FD->file mapping to the hashtable for the current thread */ diff --git a/src/userprog/syscall.h b/src/userprog/syscall.h index 681a8fb..b1ec52d 100644 --- a/src/userprog/syscall.h +++ b/src/userprog/syscall.h @@ -4,8 +4,6 @@ #include #include "threads/synch.h" -#define MIN_USER_FD 2 - typedef int pid_t; struct lock filesys_lock;