sycall: conform to POSIX

This commit is contained in:
Felix Kopp 2021-01-07 12:29:45 +01:00
parent 22c07fb544
commit 4a3e33dc05
No known key found for this signature in database
GPG key ID: C478BA0A85F75728
5 changed files with 14 additions and 15 deletions
arch/at91sam3x8e
include
kernel/fs
lib

View file

@ -39,8 +39,8 @@ syscall:
mov r12, r3 /* arg3 */ mov r12, r3 /* arg3 */
mov r2, r12 mov r2, r12
pop {r3} pop {r4}
mov r12, r3 mov r12, r4
/* stack params begin at 12 bytes offset because we already pushed three registers */ /* stack params begin at 12 bytes offset because we already pushed three registers */
ldr r3, [sp, #12] /* arg4 */ ldr r3, [sp, #12] /* arg4 */

View file

@ -27,8 +27,8 @@ extern const int (*sys_table[NSYSCALLS])(sysarg_t arg1, sysarg_t arg2, sysarg_t
/* catchall handler that returns -ENOSYS */ /* catchall handler that returns -ENOSYS */
int sys_stub(void); int sys_stub(void);
int sys_read(int fd, 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, size_t off); int sys_write(int fd, const void *buf, size_t len);
/* /*
* Copyright (c) 2020 Felix Kopp <sandtler@sandtler.club> * Copyright (c) 2020 Felix Kopp <sandtler@sandtler.club>

View file

@ -5,7 +5,7 @@
#include <stdint.h> #include <stdint.h>
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); ssize_t write(int fildes, const void *buf, size_t nbyte);
/* /*

View file

@ -10,25 +10,25 @@
#include <stddef.h> #include <stddef.h>
#include <toolchain.h> #include <toolchain.h>
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; ssize_t ret;
void *copy; void *copy;
if (fd != 1) /* we only support stdout (serial console) right now ... */ if (fd != 1) /* we only support stdout (serial console) right now */
return -ENOTSUP; return -EBADF;
if (off != 0) /* ... and the serial console doesn't support seeking */
return -ESPIPE;
copy = malloc(len); copy = malloc(len);
if (copy == NULL) if (copy == NULL)
return -ENOMEM; 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 */ /* TODO: reschedule if blocking */
ret = serial_write(serial_default_interface, copy, (size_t)ret); ret = serial_write(serial_default_interface, copy, (size_t)ret);
return ret; free(copy);
return 0x42424242;
} }
/* /*

View file

@ -8,10 +8,9 @@
#include <toolchain.h> #include <toolchain.h>
#include <unistd.h> #include <unistd.h>
__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, return syscall(SYSCALL_READ, (sysarg_t)fildes, (sysarg_t)buf, (sysarg_t)nbyte, 0, 0, 0);
(sysarg_t)offset, 0, 0);
} }
__shared ssize_t write(int fildes, const void *buf, size_t nbyte) __shared ssize_t write(int fildes, const void *buf, size_t nbyte)