Refactor stack growth #57

Merged
sb3923 merged 17 commits from vm/stack-growth/saleh into vm/virtual-memory/saleh 2024-12-05 00:53:35 +00:00
26 changed files with 279 additions and 704 deletions
Showing only changes of commit 44f6a85163 - Show all commits

View File

@@ -11,6 +11,7 @@
#include "userprog/process.h"
#include "userprog/pagedir.h"
#include <stdio.h>
#include <stdbool.h>
#include <syscall-nr.h>
static struct lock filesys_lock;
@@ -47,6 +48,8 @@ static void syscall_close (int fd);
static struct open_file *fd_get_file (int fd);
static void *validate_user_pointer (const void *ptr, size_t size);
static int get_user (const uint8_t *);
static bool put_user (uint8_t *, uint8_t);
/* A struct defining a syscall_function pointer along with its arity. */
typedef struct
@@ -415,3 +418,29 @@ validate_user_pointer (const void *ptr, size_t size)
return (void *) ptr;
}
/* PROVIDED BY SPEC.
Reads a byte at user virtual address UADDR.
UADDR must be below PHYS_BASE.
Returns the byte value if successful, -1 if a segfault occurred. */
static int
get_user (const uint8_t *uaddr)
{
int result;
asm ("movl $1f, %0; movzbl %1, %0; 1:" : "=&a"(result) : "m"(*uaddr));
return result;
}
/* PROVIDED BY SPEC.
Writes BYTE to user address UDST.
UDST must be below PHYS_BASE.
Returns true if successful, false if a segfault occurred. */
static bool
put_user (uint8_t *udst, uint8_t byte)
{
int error_code;
asm ("movl $1f, %0; movb %b2, %1; 1:"
: "=&a"(error_code), "=m"(*udst)
: "q"(byte));
return error_code != -1;
}