Update syscall.c to allow mmap and unmap system calls through helper handler functions for each

This commit is contained in:
sBubshait
2024-12-04 15:31:53 +00:00
parent 6b0f708d8f
commit 67f16cb2a6

View File

@@ -11,11 +11,13 @@
#include "threads/synch.h" #include "threads/synch.h"
#include "userprog/process.h" #include "userprog/process.h"
#include "userprog/pagedir.h" #include "userprog/pagedir.h"
#include "vm/mmap.h"
#include <stdio.h> #include <stdio.h>
#include <syscall-nr.h> #include <syscall-nr.h>
#define MAX_SYSCALL_ARGS 3 #define MAX_SYSCALL_ARGS 3
#define EXIT_FAILURE -1 #define EXIT_FAILURE -1
#define MMAP_FAILURE -1
struct open_file struct open_file
{ {
@@ -45,6 +47,8 @@ static int syscall_write (int fd, const void *buffer, unsigned size);
static void syscall_seek (int fd, unsigned position); static void syscall_seek (int fd, unsigned position);
static unsigned syscall_tell (int fd); static unsigned syscall_tell (int fd);
static void syscall_close (int fd); static void syscall_close (int fd);
static mapid_t syscall_mmap (int fd, void *addr);
static void syscall_munmap (mapid_t mapping);
static struct open_file *fd_get_file (int fd); static struct open_file *fd_get_file (int fd);
static void validate_user_pointer (const void *start, size_t size, bool write); static void validate_user_pointer (const void *start, size_t size, bool write);
@@ -74,6 +78,8 @@ static const struct syscall_arguments syscall_lookup[] =
[SYS_SEEK] = {(syscall_function) syscall_seek, 2}, [SYS_SEEK] = {(syscall_function) syscall_seek, 2},
[SYS_TELL] = {(syscall_function) syscall_tell, 1}, [SYS_TELL] = {(syscall_function) syscall_tell, 1},
[SYS_CLOSE] = {(syscall_function) syscall_close, 1}, [SYS_CLOSE] = {(syscall_function) syscall_close, 1},
[SYS_MMAP] = {(syscall_function) syscall_mmap, 2},
[SYS_MUNMAP] = {(syscall_function) syscall_munmap, 1}
}; };
/* The number of syscall functions (i.e, number of elements) within the /* The number of syscall functions (i.e, number of elements) within the
@@ -394,6 +400,20 @@ syscall_close (int fd)
} }
} }
/* Handles the syscall for memory mapping a file. */
static mapid_t
syscall_mmap (int fd, void *addr)
{
return MMAP_FAILURE;
}
/* Handles the syscall for unmapping a memory mapped file. */
static void
syscall_munmap (mapid_t mapping UNUSED)
{
}
/* Hashing function needed for the open_file table. Returns a hash for an entry, /* Hashing function needed for the open_file table. Returns a hash for an entry,
based on its FD. */ based on its FD. */
unsigned unsigned