Skip to content
Snippets Groups Projects
Commit d9759b9a authored by ja3-saxby's avatar ja3-saxby
Browse files

Merge branch 'Alex/27-implement-open-system-call' into 'feature/system-calls'

Alex/27 implement open system call

See merge request !15
parents 59a052cd 22450d19
No related branches found
No related tags found
2 merge requests!22Merge Feature/system calls,!15Alex/27 implement open system call
......@@ -64,6 +64,7 @@ userprog_SRC += userprog/gdt.c # GDT initialization.
userprog_SRC += userprog/tss.c # TSS management.
userprog_SRC += userprog/syscall_exec.c
userprog_SRC += userprog/syscall_exit.c
userprog_SRC += userprog/syscall_open.c
userprog_SRC += userprog/syscall_halt.c
userprog_SRC += userprog/syscall_wait.c
userprog_SRC += userprog/syscall_create.c
......
......@@ -58,6 +58,9 @@ syscall_handler (struct intr_frame *f UNUSED)
case SYSCALL_HALT:
syscall_halt(f);
break;
case SYSCALL_EXIT:
syscall_exit(f);
break;
case SYSCALL_EXEC:
syscall_exec(f);
break;
......@@ -70,6 +73,9 @@ syscall_handler (struct intr_frame *f UNUSED)
case SYSCALL_WRITE:
syscall_write(f);
break;
case SYSCALL_OPEN:
syscall_open(f);
break;
default:
printf ("WARNING: Invalid Syscall (%d)\n", syscall_number);
thread_exit ();
......
/*
* Terminates the current user program, returning status to the kernel. If the
* Process’s parent waits for it (see below), this is the status that will be
* Returned. Conventionally, a status of 0 indicates success and nonzero values
* Indicate errors.
*
* Authored by Alex Stratford
*/
#include "system_calls.h"
#include "threads/interrupt.h" // Dependency for intr_frame struct
#include "threads/thread.h" // Dependency for thread struct
void syscall_exit(struct intr_frame *f) {
struct thread *current_thread = thread_current(); // Sets current thread
// pop off first int argument from interrupt frame
int exit_code = *((int*)f->esp + 1);
current_thread->exit_code = exit_code; // Returns exit code to kernel
thread_exit(); // Exiting current thread
}
/*
* Opens the file called file. Returns a nonnegative integer handle called a
* "file descriptor" (fd), or -1 if the file could not be opened.
*
* Authored by Alex Stratford
*/
#include "system_calls.h"
#include <stddef.h> // Dependency for NULL
#include "threads/interrupt.h" // Dependency for intr_frame struct
#include "filesys/file.h" // Dependency for and file struct
#include "filesys/filesys.h" // Dependency for filesys_open
void syscall_open(struct intr_frame *f) {
// pop off first int argument from interrupt frame
char* file_name = (void*)(*(int*)f->esp + 1);
// Described in filesys.h, opens the file
struct file *file = filesys_open(file_name);
if (file == NULL) { // Checking if file is empty or non-existent
f->eax = -1; // Returning a failure state
return;
}
// Described in system_calls.h, get a new file descriptor
int file_descriptor = associate_new_file_descriptor(file);
if (file_descriptor == -1) {
f->eax = -1; // Returning a failure state
return;
}
f->eax = file_descriptor; // Returning the file descriptor
}
......@@ -7,6 +7,14 @@
*/
void syscall_halt(struct intr_frame *f);
/*
* Terminates the current user program, returning status to the kernel. If the
* process's parent waits for it (see below), this is the status that will be
* returned. Conventionally, a status of 0 indicates success and nonzero
* values indicate errors.
*/
void syscall_exit(struct intr_frame *f);
/*
* Runs the executable whose name is given in cmd_line, passing any given
* arguments, and returns the new process's program id (pid). Must return pid
......@@ -36,9 +44,10 @@ void syscall_create(struct intr_frame *f);
void syscall_write(struct intr_frame *f);
/*
* NOTE: There are more system calls implemented by Pintos but we are not
* implementing them because the assignment brief does not ask of it.
* Opens the file called file. Returns a nonnegative integer handle called a
* "file descriptor" (fd), or -1 if the file could not be opened.
*/
void syscall_open(struct intr_frame *f);
/*
* special additional stuff for handling file descriptors because they're annoying
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment