Update thread and syscall to use local fd counter instead global one, preventing overflow
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
@@ -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. */
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -4,8 +4,6 @@
|
||||
#include <hash.h>
|
||||
#include "threads/synch.h"
|
||||
|
||||
#define MIN_USER_FD 2
|
||||
|
||||
typedef int pid_t;
|
||||
|
||||
struct lock filesys_lock;
|
||||
|
||||
Reference in New Issue
Block a user