summaryrefslogtreecommitdiff
path: root/src/kernel/syscalls.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/kernel/syscalls.c')
-rw-r--r--src/kernel/syscalls.c31
1 files changed, 16 insertions, 15 deletions
diff --git a/src/kernel/syscalls.c b/src/kernel/syscalls.c
index 3383a13..533ebca 100644
--- a/src/kernel/syscalls.c
+++ b/src/kernel/syscalls.c
@@ -2,6 +2,7 @@
#include <kernel/mem.h>
#include <kernel/panic.h>
#include <kernel/proc.h>
+#include <kernel/types.h>
#include <kernel/vfs/path.h>
#include <shared/syscalls.h>
#include <stdint.h>
@@ -25,9 +26,9 @@ _Noreturn static void await_finish(struct process *dead, struct process *listene
}
-_Noreturn void _syscall_exit(const char *msg, size_t len) {
+_Noreturn void _syscall_exit(const user_ptr msg, size_t len) {
process_current->state = PS_DEAD;
- process_current->saved_addr = (void*)msg; // discard const
+ process_current->saved_addr = msg;
process_current->saved_len = len;
if (process_current->parent->state == PS_WAITS4CHILDDEATH)
@@ -40,7 +41,7 @@ _Noreturn void _syscall_exit(const char *msg, size_t len) {
process_switch_any();
}
-int _syscall_await(char *buf, int len) {
+int _syscall_await(user_ptr buf, int len) {
process_current->state = PS_WAITS4CHILDDEATH;
process_current->saved_addr = buf;
process_current->saved_len = len;
@@ -65,7 +66,7 @@ int _syscall_fork(void) {
return 1;
}
-fd_t _syscall_fs_open(const char *path, int len) {
+fd_t _syscall_fs_open(const user_ptr path, int len) {
struct virt_iter iter;
struct vfs_mount *mount = process_current->mount;
static char buffer[PATH_MAX]; // holds the path
@@ -73,7 +74,7 @@ fd_t _syscall_fs_open(const char *path, int len) {
if (len > PATH_MAX) return -1;
// copy the path to the kernel
- virt_iter_new(&iter, (void*)path, len, process_current->pages, true, false);
+ virt_iter_new(&iter, path, len, process_current->pages, true, false);
while (virt_iter_next(&iter))
memcpy(buffer + iter.prior, iter.frag, iter.frag_len);
if (iter.error) return -1;
@@ -99,7 +100,7 @@ fd_t _syscall_fs_open(const char *path, int len) {
return -1;
}
-int _syscall_mount(const char *path, int len, fd_t fd) {
+int _syscall_mount(const user_ptr path, int len, fd_t fd) {
struct virt_iter iter;
struct vfs_mount *mount;
char *path_buf;
@@ -108,7 +109,7 @@ int _syscall_mount(const char *path, int len, fd_t fd) {
// copy the path to the kernel
path_buf = kmalloc(len);
- virt_iter_new(&iter, (void*)path, len, process_current->pages, true, false);
+ virt_iter_new(&iter, path, len, process_current->pages, true, false);
while (virt_iter_next(&iter))
memcpy(path_buf + iter.prior, iter.frag, iter.frag_len);
if (iter.error) goto fail;
@@ -130,12 +131,12 @@ fail:
return -1;
}
-int _syscall_fd_read(fd_t fd, char *buf, int len) {
+int _syscall_fd_read(fd_t fd, user_ptr buf, int len) {
if (fd < 0 || fd >= FD_MAX) return -1;
return fdop_dispatch(FDOP_READ, &process_current->fds[fd], buf, len);
}
-int _syscall_fd_write(fd_t fd, char *buf, int len) {
+int _syscall_fd_write(fd_t fd, user_ptr buf, int len) {
if (fd < 0 || fd >= FD_MAX) return -1;
return fdop_dispatch(FDOP_WRITE, &process_current->fds[fd], buf, len);
}
@@ -148,19 +149,19 @@ int _syscall_fd_close(fd_t fd) {
int syscall_handler(int num, int a, int b, int c) {
switch (num) {
case _SYSCALL_EXIT:
- _syscall_exit((void*)a, b);
+ _syscall_exit(a, b);
case _SYSCALL_AWAIT:
- return _syscall_await((void*)a, b);
+ return _syscall_await(a, b);
case _SYSCALL_FORK:
return _syscall_fork();
case _SYSCALL_FS_OPEN:
- return _syscall_fs_open((void*)a, b);
+ return _syscall_fs_open(a, b);
case _SYSCALL_MOUNT:
- return _syscall_mount((void*)a, b, c);
+ return _syscall_mount(a, b, c);
case _SYSCALL_FD_READ:
- return _syscall_fd_read(a, (void*)b, c);
+ return _syscall_fd_read(a, b, c);
case _SYSCALL_FD_WRITE:
- return _syscall_fd_write(a, (void*)b, c);
+ return _syscall_fd_write(a, b, c);
case _SYSCALL_FD_CLOSE:
return _syscall_fd_close(a);
default: