From 4a3e33dc050ca20b396b9ec50f8adc45fc7241e5 Mon Sep 17 00:00:00 2001 From: Felix Kopp Date: Thu, 7 Jan 2021 12:29:45 +0100 Subject: [PATCH] sycall: conform to POSIX --- arch/at91sam3x8e/syscall.S | 4 ++-- include/ardix/syscall.h | 4 ++-- include/unistd.h | 2 +- kernel/fs/write.c | 14 +++++++------- lib/unistd.c | 5 ++--- 5 files changed, 14 insertions(+), 15 deletions(-) diff --git a/arch/at91sam3x8e/syscall.S b/arch/at91sam3x8e/syscall.S index f8ff04a..611ed72 100644 --- a/arch/at91sam3x8e/syscall.S +++ b/arch/at91sam3x8e/syscall.S @@ -39,8 +39,8 @@ syscall: mov r12, r3 /* arg3 */ mov r2, r12 - pop {r3} - mov r12, r3 + pop {r4} + mov r12, r4 /* stack params begin at 12 bytes offset because we already pushed three registers */ ldr r3, [sp, #12] /* arg4 */ diff --git a/include/ardix/syscall.h b/include/ardix/syscall.h index 6eace83..53e28e4 100644 --- a/include/ardix/syscall.h +++ b/include/ardix/syscall.h @@ -27,8 +27,8 @@ extern const int (*sys_table[NSYSCALLS])(sysarg_t arg1, sysarg_t arg2, sysarg_t /* catchall handler that returns -ENOSYS */ int sys_stub(void); -int sys_read(int fd, void *buf, size_t len, size_t off); -int sys_write(int fd, const void *buf, size_t len, size_t off); +int sys_read(int fd, void *buf, size_t len); +int sys_write(int fd, const void *buf, size_t len); /* * Copyright (c) 2020 Felix Kopp diff --git a/include/unistd.h b/include/unistd.h index 9af63b6..28579e8 100644 --- a/include/unistd.h +++ b/include/unistd.h @@ -5,7 +5,7 @@ #include -ssize_t pwrite(int fildes, const void *buf, size_t nbyte, off_t offset); +ssize_t read(int fildes, void *buf, size_t nbyte); ssize_t write(int fildes, const void *buf, size_t nbyte); /* diff --git a/kernel/fs/write.c b/kernel/fs/write.c index e258ab6..4f1c28c 100644 --- a/kernel/fs/write.c +++ b/kernel/fs/write.c @@ -10,25 +10,25 @@ #include #include -ssize_t sys_write(int fd, __user const void *buf, size_t len, size_t off) +ssize_t sys_write(int fd, __user const void *buf, size_t len) { ssize_t ret; void *copy; - if (fd != 1) /* we only support stdout (serial console) right now ... */ - return -ENOTSUP; - if (off != 0) /* ... and the serial console doesn't support seeking */ - return -ESPIPE; + if (fd != 1) /* we only support stdout (serial console) right now */ + return -EBADF; copy = malloc(len); if (copy == NULL) return -ENOMEM; - ret = (ssize_t)copy_from_user(copy, buf, (size_t)len); + ret = (ssize_t)copy_from_user(copy, buf, len); /* TODO: reschedule if blocking */ ret = serial_write(serial_default_interface, copy, (size_t)ret); - return ret; + free(copy); + + return 0x42424242; } /* diff --git a/lib/unistd.c b/lib/unistd.c index 6426ab3..0c840c8 100644 --- a/lib/unistd.c +++ b/lib/unistd.c @@ -8,10 +8,9 @@ #include #include -__shared ssize_t pwrite(int fildes, const void *buf, size_t nbyte, off_t offset) +__shared ssize_t read(int fildes, void *buf, size_t nbyte) { - return syscall(SYSCALL_WRITE, (sysarg_t)fildes, (sysarg_t)buf, (sysarg_t)nbyte, - (sysarg_t)offset, 0, 0); + return syscall(SYSCALL_READ, (sysarg_t)fildes, (sysarg_t)buf, (sysarg_t)nbyte, 0, 0, 0); } __shared ssize_t write(int fildes, const void *buf, size_t nbyte)