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

Merge branch 'Alex/exit-system-call' into 'feature/system-calls'

Alex/exit system call

See merge request !12
parents de64b806 2eb8004c
No related branches found
No related tags found
2 merge requests!22Merge Feature/system calls,!12Alex/exit system call
...@@ -10,3 +10,4 @@ examples/libc.a ...@@ -10,3 +10,4 @@ examples/libc.a
examples/my examples/my
# Visual Studio folder # Visual Studio folder
/.vs /.vs
/CppProperties.json
...@@ -3,7 +3,7 @@ SRCDIR = .. ...@@ -3,7 +3,7 @@ SRCDIR = ..
# Test programs to compile, and a list of sources for each. # Test programs to compile, and a list of sources for each.
# To add a new test, put its name on the PROGS list # To add a new test, put its name on the PROGS list
# and then add a name_SRC line that lists its source files. # and then add a name_SRC line that lists its source files.
PROGS = cat cmp cp echo halt hex-dump ls mcat mcp mkdir pwd rm shell \ PROGS = cat cmp cp echo exit halt hex-dump ls mcat mcp mkdir pwd rm shell \
bubsort insult lineup matmult recursor my touch bubsort insult lineup matmult recursor my touch
# Should work from project 2 onward. # Should work from project 2 onward.
...@@ -11,6 +11,7 @@ cat_SRC = cat.c ...@@ -11,6 +11,7 @@ cat_SRC = cat.c
cmp_SRC = cmp.c cmp_SRC = cmp.c
cp_SRC = cp.c cp_SRC = cp.c
echo_SRC = echo.c echo_SRC = echo.c
exit_SRC = exit.c
halt_SRC = halt.c halt_SRC = halt.c
hex-dump_SRC = hex-dump.c hex-dump_SRC = hex-dump.c
insult_SRC = insult.c insult_SRC = insult.c
......
/* exit.c
Simple program to test whether running a user program works.
Invokes the exit syscall to test if it works */
#include <syscall.h>
int
main (void)
{
exit (5);
/* not reached */
}
...@@ -72,7 +72,7 @@ syscall_handler (struct intr_frame *f UNUSED) ...@@ -72,7 +72,7 @@ syscall_handler (struct intr_frame *f UNUSED)
break; break;
default: default:
printf ("WARNING: Invalid Syscall (%d)\n", syscall_number); printf ("WARNING: Invalid Syscall (%d)\n", syscall_number);
thread_exit ();
} }
// TODO: remove this call to exit as we don't want all syscalls to make the thread exit // TODO: remove this call to exit as we don't want all syscalls to make the thread exit
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 "system_calls.h"
#include "threads/interrupt.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) { void syscall_exit(struct intr_frame *f) {
(void*)0; 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
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment