aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Waterman <waterman@eecs.berkeley.edu>2014-02-04 15:29:06 -0800
committerAndrew Waterman <waterman@eecs.berkeley.edu>2014-02-04 15:29:06 -0800
commitf1f8dbbed01d67a3cb64a17c73078d124c33d2ab (patch)
tree77181fb45946e2a5883b87d09d65d08439186672
parentac88604e8850779c33ec888ccc8399604fb2677c (diff)
downloadpk-f1f8dbbed01d67a3cb64a17c73078d124c33d2ab.zip
pk-f1f8dbbed01d67a3cb64a17c73078d124c33d2ab.tar.gz
pk-f1f8dbbed01d67a3cb64a17c73078d124c33d2ab.tar.bz2
Abandon MIPS convention for indicating syscall errors in register a3
-rw-r--r--pk/elf.c9
-rw-r--r--pk/encoding.h53
-rw-r--r--pk/file.c31
-rw-r--r--pk/file.h14
-rw-r--r--pk/frontend.c4
-rw-r--r--pk/frontend.h4
-rw-r--r--pk/handlers.c8
-rw-r--r--pk/init.c4
-rw-r--r--pk/syscall.c97
-rw-r--r--pk/syscall.h11
-rw-r--r--pk/vm.c32
-rw-r--r--pk/vm.h8
12 files changed, 154 insertions, 121 deletions
diff --git a/pk/elf.c b/pk/elf.c
index 607d7ea..79ee756 100644
--- a/pk/elf.c
+++ b/pk/elf.c
@@ -10,13 +10,12 @@
void load_elf(const char* fn, elf_info* info)
{
- sysret_t ret = file_open(fn, O_RDONLY, 0);
- file_t* file = (file_t*)ret.result;
- if (ret.result == -1)
+ file_t* file = file_open(fn, O_RDONLY, 0);
+ if (IS_ERR_VALUE(file))
goto fail;
Elf64_Ehdr eh64;
- ssize_t ehdr_size = file_pread(file, &eh64, sizeof(eh64), 0).result;
+ ssize_t ehdr_size = file_pread(file, &eh64, sizeof(eh64), 0);
if (ehdr_size < (ssize_t)sizeof(eh64) ||
!(eh64.e_ident[0] == '\177' && eh64.e_ident[1] == 'E' &&
eh64.e_ident[2] == 'L' && eh64.e_ident[3] == 'F'))
@@ -28,7 +27,7 @@ void load_elf(const char* fn, elf_info* info)
if (info->phdr_top - phdr_size < info->stack_bottom) \
goto fail; \
info->phdr = info->phdr_top - phdr_size; \
- ssize_t ret = file_pread(file, (void*)info->phdr, phdr_size, eh->e_phoff).result; \
+ ssize_t ret = file_pread(file, (void*)info->phdr, phdr_size, eh->e_phoff); \
if (ret < (ssize_t)phdr_size) goto fail; \
info->entry = eh->e_entry; \
info->phnum = eh->e_phnum; \
diff --git a/pk/encoding.h b/pk/encoding.h
index 711ef7b..4ee6e68 100644
--- a/pk/encoding.h
+++ b/pk/encoding.h
@@ -26,19 +26,6 @@
#define IMPL_SPIKE 1
#define IMPL_ROCKET 2
-#define CAUSE_MISALIGNED_FETCH 0
-#define CAUSE_FAULT_FETCH 1
-#define CAUSE_ILLEGAL_INSTRUCTION 2
-#define CAUSE_PRIVILEGED_INSTRUCTION 3
-#define CAUSE_FP_DISABLED 4
-#define CAUSE_SYSCALL 6
-#define CAUSE_BREAKPOINT 7
-#define CAUSE_MISALIGNED_LOAD 8
-#define CAUSE_MISALIGNED_STORE 9
-#define CAUSE_FAULT_LOAD 10
-#define CAUSE_FAULT_STORE 11
-#define CAUSE_ACCELERATOR_DISABLED 12
-
// page table entry (PTE) fields
#define PTE_V 0x001 // Entry is a page Table descriptor
#define PTE_T 0x002 // Entry is a page Table, not a terminal node
@@ -438,6 +425,18 @@
#define CSR_CYCLE 0xc00
#define CSR_TIME 0xc01
#define CSR_INSTRET 0xc02
+#define CAUSE_MISALIGNED_FETCH 0x0
+#define CAUSE_FAULT_FETCH 0x1
+#define CAUSE_ILLEGAL_INSTRUCTION 0x2
+#define CAUSE_PRIVILEGED_INSTRUCTION 0x3
+#define CAUSE_FP_DISABLED 0x4
+#define CAUSE_SYSCALL 0x6
+#define CAUSE_BREAKPOINT 0x7
+#define CAUSE_MISALIGNED_LOAD 0x8
+#define CAUSE_MISALIGNED_STORE 0x9
+#define CAUSE_FAULT_LOAD 0xa
+#define CAUSE_FAULT_STORE 0xb
+#define CAUSE_ACCELERATOR_DISABLED 0xc
#endif
#ifdef DECLARE_INSN
DECLARE_INSN(fmv_s_x, MATCH_FMV_S_X, MASK_FMV_S_X)
@@ -624,3 +623,31 @@ DECLARE_CSR(cycle, CSR_CYCLE)
DECLARE_CSR(time, CSR_TIME)
DECLARE_CSR(instret, CSR_INSTRET)
#endif
+#ifdef DECLARE_CAUSE
+DECLARE_CAUSE("fflags", CAUSE_FFLAGS)
+DECLARE_CAUSE("frm", CAUSE_FRM)
+DECLARE_CAUSE("fcsr", CAUSE_FCSR)
+DECLARE_CAUSE("sup0", CAUSE_SUP0)
+DECLARE_CAUSE("sup1", CAUSE_SUP1)
+DECLARE_CAUSE("epc", CAUSE_EPC)
+DECLARE_CAUSE("badvaddr", CAUSE_BADVADDR)
+DECLARE_CAUSE("ptbr", CAUSE_PTBR)
+DECLARE_CAUSE("asid", CAUSE_ASID)
+DECLARE_CAUSE("count", CAUSE_COUNT)
+DECLARE_CAUSE("compare", CAUSE_COMPARE)
+DECLARE_CAUSE("evec", CAUSE_EVEC)
+DECLARE_CAUSE("cause", CAUSE_CAUSE)
+DECLARE_CAUSE("status", CAUSE_STATUS)
+DECLARE_CAUSE("hartid", CAUSE_HARTID)
+DECLARE_CAUSE("impl", CAUSE_IMPL)
+DECLARE_CAUSE("fatc", CAUSE_FATC)
+DECLARE_CAUSE("send_ipi", CAUSE_SEND_IPI)
+DECLARE_CAUSE("clear_ipi", CAUSE_CLEAR_IPI)
+DECLARE_CAUSE("stats", CAUSE_STATS)
+DECLARE_CAUSE("reset", CAUSE_RESET)
+DECLARE_CAUSE("tohost", CAUSE_TOHOST)
+DECLARE_CAUSE("fromhost", CAUSE_FROMHOST)
+DECLARE_CAUSE("cycle", CAUSE_CYCLE)
+DECLARE_CAUSE("time", CAUSE_TIME)
+DECLARE_CAUSE("instret", CAUSE_INSTRET)
+#endif
diff --git a/pk/file.c b/pk/file.c
index ca6d1e5..6c3ecda 100644
--- a/pk/file.c
+++ b/pk/file.c
@@ -83,23 +83,24 @@ file_t* file_get(int fd)
return f;
}
-sysret_t file_open(const char* fn, int flags, int mode)
+file_t* file_open(const char* fn, int flags, int mode)
{
file_t* f = file_get_free();
- if(!f)
- return (sysret_t){-1,ENOMEM};
+ if (f == NULL)
+ return ERR_PTR(-ENOMEM);
size_t fn_size = strlen(fn)+1;
- sysret_t ret = frontend_syscall(SYS_open, (long)fn, fn_size, flags, mode);
- if(ret.result != -1)
+ long ret = frontend_syscall(SYS_open, (long)fn, fn_size, flags, mode);
+ if (ret >= 0)
{
- f->kfd = ret.result;
- ret.result = (long)f;
+ f->kfd = ret;
+ return f;
}
else
+ {
file_decref(f);
-
- return ret;
+ return ERR_PTR(ret);
+ }
}
int fd_close(int fd)
@@ -115,37 +116,37 @@ int fd_close(int fd)
return 0;
}
-sysret_t file_read(file_t* f, void* buf, size_t size)
+ssize_t file_read(file_t* f, void* buf, size_t size)
{
populate_mapping(buf, size, PROT_WRITE);
return frontend_syscall(SYS_read, f->kfd, (uintptr_t)buf, size, 0);
}
-sysret_t file_pread(file_t* f, void* buf, size_t size, off_t offset)
+ssize_t file_pread(file_t* f, void* buf, size_t size, off_t offset)
{
populate_mapping(buf, size, PROT_WRITE);
return frontend_syscall(SYS_pread, f->kfd, (uintptr_t)buf, size, offset);
}
-sysret_t file_write(file_t* f, const void* buf, size_t size)
+ssize_t file_write(file_t* f, const void* buf, size_t size)
{
populate_mapping(buf, size, PROT_READ);
return frontend_syscall(SYS_write, f->kfd, (uintptr_t)buf, size, 0);
}
-sysret_t file_pwrite(file_t* f, const void* buf, size_t size, off_t offset)
+ssize_t file_pwrite(file_t* f, const void* buf, size_t size, off_t offset)
{
populate_mapping(buf, size, PROT_READ);
return frontend_syscall(SYS_pwrite, f->kfd, (uintptr_t)buf, size, offset);
}
-sysret_t file_stat(file_t* f, struct stat* s)
+int file_stat(file_t* f, struct stat* s)
{
populate_mapping(s, sizeof(*s), PROT_WRITE);
return frontend_syscall(SYS_fstat, f->kfd, (uintptr_t)s, 0, 0);
}
-sysret_t file_lseek(file_t* f, size_t ptr, int dir)
+ssize_t file_lseek(file_t* f, size_t ptr, int dir)
{
return frontend_syscall(SYS_lseek, f->kfd, ptr, dir, 0);
}
diff --git a/pk/file.h b/pk/file.h
index 42f47fc..88338e6 100644
--- a/pk/file.h
+++ b/pk/file.h
@@ -16,17 +16,17 @@ typedef struct file
extern file_t *stdin, *stdout, *stderr;
file_t* file_get(int fd);
-sysret_t file_open(const char* fn, int flags, int mode);
+file_t* file_open(const char* fn, int flags, int mode);
void file_decref(file_t*);
void file_incref(file_t*);
int file_dup(file_t*);
-sysret_t file_pwrite(file_t* f, const void* buf, size_t n, off_t off);
-sysret_t file_pread(file_t* f, void* buf, size_t n, off_t off);
-sysret_t file_write(file_t* f, const void* buf, size_t n);
-sysret_t file_read(file_t* f, void* buf, size_t n);
-sysret_t file_stat(file_t* f, struct stat* s);
-sysret_t file_lseek(file_t* f, size_t ptr, int dir);
+ssize_t file_pwrite(file_t* f, const void* buf, size_t n, off_t off);
+ssize_t file_pread(file_t* f, void* buf, size_t n, off_t off);
+ssize_t file_write(file_t* f, const void* buf, size_t n);
+ssize_t file_read(file_t* f, void* buf, size_t n);
+ssize_t file_lseek(file_t* f, size_t ptr, int dir);
+int file_stat(file_t* f, struct stat* s);
int fd_close(int fd);
void file_init();
diff --git a/pk/frontend.c b/pk/frontend.c
index 3452b23..77d71a6 100644
--- a/pk/frontend.c
+++ b/pk/frontend.c
@@ -5,7 +5,7 @@
#include "frontend.h"
#include <stdint.h>
-sysret_t frontend_syscall(long n, long a0, long a1, long a2, long a3)
+long frontend_syscall(long n, long a0, long a1, long a2, long a3)
{
static volatile uint64_t magic_mem[8];
@@ -25,7 +25,7 @@ sysret_t frontend_syscall(long n, long a0, long a1, long a2, long a3)
mb();
- sysret_t ret = {magic_mem[0],magic_mem[1]};
+ long ret = magic_mem[0];
spinlock_unlock(&lock);
return ret;
diff --git a/pk/frontend.h b/pk/frontend.h
index a3bc4de..9610234 100644
--- a/pk/frontend.h
+++ b/pk/frontend.h
@@ -3,8 +3,6 @@
#ifndef _RISCV_FRONTEND_H
#define _RISCV_FRONTEND_H
-#include <machine/syscall.h>
-
-sysret_t frontend_syscall(long n, long a0, long a1, long a2, long a3);
+long frontend_syscall(long n, long a0, long a1, long a2, long a3);
#endif
diff --git a/pk/handlers.c b/pk/handlers.c
index 2c50ae6..94a4127 100644
--- a/pk/handlers.c
+++ b/pk/handlers.c
@@ -109,12 +109,8 @@ void handle_fault_store(trapframe_t* tf)
static void handle_syscall(trapframe_t* tf)
{
- sysret_t ret = syscall(tf->gpr[18], tf->gpr[19], tf->gpr[20], tf->gpr[21],
- tf->gpr[22], tf->gpr[23], tf->gpr[16]);
-
- tf->gpr[16] = ret.result;
- tf->gpr[21] = ret.err;
-
+ tf->gpr[16] = syscall(tf->gpr[18], tf->gpr[19], tf->gpr[20], tf->gpr[21],
+ tf->gpr[22], tf->gpr[23], tf->gpr[16]);
tf->epc += 4;
}
diff --git a/pk/init.c b/pk/init.c
index 848da65..d6974f7 100644
--- a/pk/init.c
+++ b/pk/init.c
@@ -54,8 +54,8 @@ static void user_init()
size_t stack_top = current.stack_top;
struct args* args = (struct args*)(stack_top - argc_argv_size);
populate_mapping(args, argc_argv_size, PROT_WRITE);
- sysret_t r = frontend_syscall(SYS_getmainvars, (long)args, argc_argv_size, 0, 0);
- kassert(r.result == 0);
+ long r = frontend_syscall(SYS_getmainvars, (long)args, argc_argv_size, 0, 0);
+ kassert(r == 0);
// argv[0] is the proxy kernel itself. skip it and any flags.
unsigned a0 = 1;
diff --git a/pk/syscall.c b/pk/syscall.c
index 044cc78..6d58be0 100644
--- a/pk/syscall.c
+++ b/pk/syscall.c
@@ -8,7 +8,7 @@
#include <string.h>
#include <errno.h>
-typedef sysret_t (*syscall_t)(long, long, long, long, long, long, long);
+typedef long (*syscall_t)(long, long, long, long, long, long, long);
#define long_bytes (4 + 4*current.elf64)
#define get_long(base, i) ({ long res; \
@@ -30,9 +30,9 @@ void sys_exit(int code)
while (1);
}
-sysret_t sys_read(int fd, char* buf, size_t n)
+ssize_t sys_read(int fd, char* buf, size_t n)
{
- sysret_t r = {-1,EBADF};
+ ssize_t r = -EBADF;
file_t* f = file_get(fd);
if (f)
@@ -44,9 +44,9 @@ sysret_t sys_read(int fd, char* buf, size_t n)
return r;
}
-sysret_t sys_write(int fd, const char* buf, size_t n)
+ssize_t sys_write(int fd, const char* buf, size_t n)
{
- sysret_t r = {-1,EBADF};
+ ssize_t r = -EBADF;
file_t* f = file_get(fd);
if (f)
@@ -58,27 +58,30 @@ sysret_t sys_write(int fd, const char* buf, size_t n)
return r;
}
-sysret_t sys_open(const char* name, int flags, int mode)
+int sys_open(const char* name, int flags, int mode)
{
- sysret_t ret = file_open(name, flags, mode);
- if(ret.result == -1)
- return ret;
+ file_t* file = file_open(name, flags, mode);
+ if (IS_ERR_VALUE(file))
+ return PTR_ERR(file);
- if((ret.result = file_dup((file_t*)ret.result)) == -1)
- ret.err = ENOMEM;
+ int fd = file_dup(file);
+ if (fd < 0)
+ return -ENOMEM;
- return ret;
+ return fd;
}
-sysret_t sys_close(int fd)
+int sys_close(int fd)
{
int ret = fd_close(fd);
- return (sysret_t){ret, ret & EBADF};
+ if (ret < 0)
+ return -EBADF;
+ return ret;
}
-sysret_t sys_fstat(int fd, void* st)
+int sys_fstat(int fd, void* st)
{
- sysret_t r = {-1,EBADF};
+ int r = -EBADF;
file_t* f = file_get(fd);
if (f)
@@ -90,9 +93,9 @@ sysret_t sys_fstat(int fd, void* st)
return r;
}
-sysret_t sys_lseek(int fd, size_t ptr, int dir)
+ssize_t sys_lseek(int fd, size_t ptr, int dir)
{
- sysret_t r = {-1,EBADF};
+ ssize_t r = -EBADF;
file_t* f = file_get(fd);
if (f)
@@ -104,21 +107,21 @@ sysret_t sys_lseek(int fd, size_t ptr, int dir)
return r;
}
-sysret_t sys_stat(const char* name, void* st)
+long sys_stat(const char* name, void* st)
{
size_t name_size = strlen(name)+1;
populate_mapping(st, sizeof(struct stat), PROT_WRITE);
return frontend_syscall(SYS_stat, (uintptr_t)name, name_size, (uintptr_t)st, 0);
}
-sysret_t sys_lstat(const char* name, void* st)
+long sys_lstat(const char* name, void* st)
{
size_t name_size = strlen(name)+1;
populate_mapping(st, sizeof(struct stat), PROT_WRITE);
return frontend_syscall(SYS_lstat, (uintptr_t)name, name_size, (uintptr_t)st, 0);
}
-sysret_t sys_link(const char* old_name, const char* new_name)
+long sys_link(const char* old_name, const char* new_name)
{
size_t old_size = strlen(old_name)+1;
size_t new_size = strlen(new_name)+1;
@@ -126,18 +129,18 @@ sysret_t sys_link(const char* old_name, const char* new_name)
(uintptr_t)new_name, new_size);
}
-sysret_t sys_unlink(const char* name, size_t len)
+long sys_unlink(const char* name, size_t len)
{
size_t name_size = strlen(name)+1;
return frontend_syscall(SYS_unlink, (uintptr_t)name, name_size, 0, 0);
}
-sysret_t sys_brk(size_t pos)
+size_t sys_brk(size_t pos)
{
return do_brk(pos);
}
-sysret_t sys_uname(void* buf)
+int sys_uname(void* buf)
{
const int sz = 65;
strcpy(buf + 0*sz, "Proxy Kernel");
@@ -146,30 +149,30 @@ sysret_t sys_uname(void* buf)
strcpy(buf + 3*sz, "");
strcpy(buf + 4*sz, "");
strcpy(buf + 5*sz, "");
- return (sysret_t){0,0};
+ return 0;
}
-sysret_t sys_getuid()
+int sys_getuid()
{
- return (sysret_t){0,0};
+ return 0;
}
-sysret_t sys_mmap(uintptr_t addr, size_t length, int prot, int flags, int fd, off_t offset)
+uintptr_t sys_mmap(uintptr_t addr, size_t length, int prot, int flags, int fd, off_t offset)
{
return do_mmap(addr, length, prot, flags, fd, offset);
}
-sysret_t sys_munmap(uintptr_t addr, size_t length)
+int sys_munmap(uintptr_t addr, size_t length)
{
return do_munmap(addr, length);
}
-sysret_t sys_mremap(uintptr_t addr, size_t old_size, size_t new_size, int flags)
+uintptr_t sys_mremap(uintptr_t addr, size_t old_size, size_t new_size, int flags)
{
return do_mremap(addr, old_size, new_size, flags);
}
-sysret_t sys_rt_sigaction(int sig, const void* act, void* oact, size_t sssz)
+int sys_rt_sigaction(int sig, const void* act, void* oact, size_t sssz)
{
if (oact)
{
@@ -178,21 +181,21 @@ sysret_t sys_rt_sigaction(int sig, const void* act, void* oact, size_t sssz)
memset(oact, 0, sz);
}
- return (sysret_t){0, 0};
+ return 0;
}
-sysret_t sys_time(void* loc)
+long sys_time(void* loc)
{
- uintptr_t t = rdcycle();
+ uintptr_t t = rdcycle() / CLOCK_FREQ;
if (loc)
{
populate_mapping(loc, long_bytes, PROT_WRITE);
- put_long(loc, 0, t / CLOCK_FREQ);
+ put_long(loc, 0, t);
}
- return (sysret_t){t, 0};
+ return t;
}
-sysret_t sys_times(void* restrict loc)
+int sys_times(void* restrict loc)
{
populate_mapping(loc, 4*long_bytes, PROT_WRITE);
@@ -203,10 +206,10 @@ sysret_t sys_times(void* restrict loc)
put_long(loc, 2, 0);
put_long(loc, 3, 0);
- return (sysret_t){0, 0};
+ return 0;
}
-sysret_t sys_gettimeofday(long* loc)
+int sys_gettimeofday(long* loc)
{
populate_mapping(loc, 2*long_bytes, PROT_WRITE);
@@ -214,25 +217,25 @@ sysret_t sys_gettimeofday(long* loc)
put_long(loc, 0, t/CLOCK_FREQ);
put_long(loc, 1, (t % CLOCK_FREQ) / (CLOCK_FREQ / 1000000));
- return (sysret_t){0, 0};
+ return 0;
}
-sysret_t sys_writev(int fd, const void* iov, int cnt)
+ssize_t sys_writev(int fd, const void* iov, int cnt)
{
populate_mapping(iov, cnt*2*long_bytes, PROT_READ);
ssize_t ret = 0;
for (int i = 0; i < cnt; i++)
{
- sysret_t r = sys_write(fd, (void*)get_long(iov, 2*i), get_long(iov, 2*i+1));
- if (r.result < 0)
+ ssize_t r = sys_write(fd, (void*)get_long(iov, 2*i), get_long(iov, 2*i+1));
+ if (r < 0)
return r;
- ret += r.result;
+ ret += r;
}
- return (sysret_t){ret, 0};
+ return ret;
}
-sysret_t syscall(long a0, long a1, long a2, long a3, long a4, long a5, long n)
+long syscall(long a0, long a1, long a2, long a3, long a4, long a5, long n)
{
const static void* syscall_table[] = {
[SYS_exit] = sys_exit,
@@ -266,6 +269,6 @@ sysret_t syscall(long a0, long a1, long a2, long a3, long a4, long a5, long n)
if(n >= ARRAY_SIZE(syscall_table) || !syscall_table[n])
panic("bad syscall #%ld!",n);
- sysret_t r = ((syscall_t)syscall_table[n])(a0, a1, a2, a3, a4, a5, n);
+ long r = ((syscall_t)syscall_table[n])(a0, a1, a2, a3, a4, a5, n);
return r;
}
diff --git a/pk/syscall.h b/pk/syscall.h
index f759e83..fcb3423 100644
--- a/pk/syscall.h
+++ b/pk/syscall.h
@@ -1,6 +1,15 @@
// See LICENSE for license details.
+#ifndef _PK_SYSCALL_H
+#define _PK_SYSCALL_H
+
#include <machine/syscall.h>
+#define IS_ERR_VALUE(x) ((unsigned long)(x) >= (unsigned long)-4096)
+#define ERR_PTR(x) ((void*)(long)(x))
+#define PTR_ERR(x) ((long)(x))
+
void sys_exit(int code) __attribute__((noreturn));
-sysret_t syscall(long a0, long a1, long a2, long a3, long a4, long a5, long n);
+long syscall(long a0, long a1, long a2, long a3, long a4, long a5, long n);
+
+#endif
diff --git a/pk/vm.c b/pk/vm.c
index 6f02930..6a3dd3b 100644
--- a/pk/vm.c
+++ b/pk/vm.c
@@ -177,7 +177,7 @@ static int __handle_page_fault(uintptr_t vaddr, int prot)
if (v->file)
{
size_t flen = MIN(RISCV_PGSIZE, v->length - (vaddr - v->addr));
- kassert(flen == file_pread(v->file, (void*)vaddr, flen, vaddr - v->addr + v->offset).result);
+ kassert(flen == file_pread(v->file, (void*)vaddr, flen, vaddr - v->addr + v->offset));
if (flen < RISCV_PGSIZE)
memset((void*)vaddr + flen, 0, RISCV_PGSIZE - flen);
}
@@ -259,27 +259,27 @@ fail_vmr:
return (uintptr_t)-1;
}
-sysret_t do_munmap(uintptr_t addr, size_t length)
+int do_munmap(uintptr_t addr, size_t length)
{
if ((addr & (RISCV_PGSIZE-1)) || addr < current.user_min ||
addr + length > current.stack_top || addr + length < addr)
- return (sysret_t){-1, EINVAL};
+ return -EINVAL;
spinlock_lock(&vm_lock);
__do_munmap(addr, length);
spinlock_unlock(&vm_lock);
- return (sysret_t){0, 0};
+ return 0;
}
-sysret_t do_mmap(uintptr_t addr, size_t length, int prot, int flags, int fd, off_t offset)
+uintptr_t do_mmap(uintptr_t addr, size_t length, int prot, int flags, int fd, off_t offset)
{
if (!(flags & MAP_PRIVATE) || length == 0 || (offset & (RISCV_PGSIZE-1)))
- return (sysret_t){-1, EINVAL};
+ return -EINVAL;
file_t* f = NULL;
if (!(flags & MAP_ANONYMOUS) && (f = file_get(fd)) == NULL)
- return (sysret_t){-1, EBADF};
+ return -EBADF;
spinlock_lock(&vm_lock);
addr = __do_mmap(addr, length, prot, flags, f, offset);
@@ -288,12 +288,12 @@ sysret_t do_mmap(uintptr_t addr, size_t length, int prot, int flags, int fd, off
spinlock_unlock(&vm_lock);
if (f) file_decref(f);
- return (sysret_t){addr, 0};
+ return addr;
}
-size_t __do_brk(size_t addr)
+uintptr_t __do_brk(size_t addr)
{
- size_t newbrk = addr;
+ uintptr_t newbrk = addr;
if (addr < current.brk_min)
newbrk = current.brk_min;
else if (addr > current.brk_max)
@@ -302,7 +302,7 @@ size_t __do_brk(size_t addr)
if (current.brk == 0)
current.brk = ROUNDUP(current.brk_min, RISCV_PGSIZE);
- size_t newbrk_page = ROUNDUP(newbrk, RISCV_PGSIZE);
+ uintptr_t newbrk_page = ROUNDUP(newbrk, RISCV_PGSIZE);
if (current.brk > newbrk_page)
__do_munmap(newbrk_page, current.brk - newbrk_page);
else if (current.brk < newbrk_page)
@@ -312,21 +312,21 @@ size_t __do_brk(size_t addr)
return newbrk;
}
-sysret_t do_brk(size_t addr)
+uintptr_t do_brk(size_t addr)
{
spinlock_lock(&vm_lock);
addr = __do_brk(addr);
spinlock_unlock(&vm_lock);
- return (sysret_t){addr, 0};
+ return addr;
}
-sysret_t do_mremap(uintptr_t addr, size_t old_size, size_t new_size, int flags)
+uintptr_t do_mremap(uintptr_t addr, size_t old_size, size_t new_size, int flags)
{
uintptr_t res = -1;
if (((addr | old_size | new_size) & (RISCV_PGSIZE-1)) ||
(flags & MREMAP_FIXED))
- return (sysret_t){-1, EINVAL};
+ return -EINVAL;
spinlock_lock(&vm_lock);
for (size_t i = 0; i < MAX_VMR; i++)
@@ -346,7 +346,7 @@ sysret_t do_mremap(uintptr_t addr, size_t old_size, size_t new_size, int flags)
}
spinlock_unlock(&vm_lock);
- return (sysret_t){res, 0};
+ return res;
}
static void __map_kernel_range(uintptr_t paddr, size_t len, int prot)
diff --git a/pk/vm.h b/pk/vm.h
index 8f5e55f..cdd4f77 100644
--- a/pk/vm.h
+++ b/pk/vm.h
@@ -21,9 +21,9 @@ void vm_init();
int handle_page_fault(uintptr_t vaddr, int prot);
void populate_mapping(const void* start, size_t size, int prot);
uintptr_t __do_mmap(uintptr_t addr, size_t length, int prot, int flags, file_t* file, off_t offset);
-sysret_t do_mmap(uintptr_t addr, size_t length, int prot, int flags, int fd, off_t offset);
-sysret_t do_munmap(uintptr_t addr, size_t length);
-sysret_t do_mremap(uintptr_t addr, size_t old_size, size_t new_size, int flags);
-sysret_t do_brk(uintptr_t addr);
+uintptr_t do_mmap(uintptr_t addr, size_t length, int prot, int flags, int fd, off_t offset);
+int do_munmap(uintptr_t addr, size_t length);
+uintptr_t do_mremap(uintptr_t addr, size_t old_size, size_t new_size, int flags);
+uintptr_t do_brk(uintptr_t addr);
#endif