lib: newlib: add read/write syscalls
The read/write implementations call directly into the console drivers using the hook mechanism, causing faults if invoked from user mode. Add system calls for read() and write() such that we do a privilege elevation first. Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
This commit is contained in:
parent
bc94cc1832
commit
12e6aadcb0
2 changed files with 50 additions and 4 deletions
|
@ -12,6 +12,8 @@
|
|||
#include <misc/util.h>
|
||||
#include <kernel_internal.h>
|
||||
#include <misc/errno_private.h>
|
||||
#include <misc/libc-hooks.h>
|
||||
#include <syscall_handler.h>
|
||||
|
||||
#define USED_RAM_END_ADDR POINTER_TO_UINT(&_end)
|
||||
|
||||
|
@ -76,8 +78,7 @@ void __stdin_hook_install(unsigned char (*hook)(void))
|
|||
_stdin_hook = hook;
|
||||
}
|
||||
|
||||
#ifndef CONFIG_POSIX_FS
|
||||
int _read(int fd, char *buf, int nbytes)
|
||||
int _impl__zephyr_read(char *buf, int nbytes)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
|
@ -90,9 +91,16 @@ int _read(int fd, char *buf, int nbytes)
|
|||
}
|
||||
return i;
|
||||
}
|
||||
FUNC_ALIAS(_read, read, int);
|
||||
|
||||
int _write(int fd, char *buf, int nbytes)
|
||||
#ifdef CONFIG_USERSPACE
|
||||
Z_SYSCALL_HANDLER(_zephyr_read, buf, nbytes)
|
||||
{
|
||||
Z_OOPS(Z_SYSCALL_MEMORY_WRITE(buf, nbytes));
|
||||
return _impl__zephyr_read((char *)buf, nbytes);
|
||||
}
|
||||
#endif
|
||||
|
||||
int _impl__zephyr_write(char *buf, int nbytes)
|
||||
{
|
||||
int i;
|
||||
|
||||
|
@ -104,6 +112,30 @@ int _write(int fd, char *buf, int nbytes)
|
|||
}
|
||||
return nbytes;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_USERSPACE
|
||||
Z_SYSCALL_HANDLER(_zephyr_write, buf, nbytes)
|
||||
{
|
||||
Z_OOPS(Z_SYSCALL_MEMORY_READ(buf, nbytes));
|
||||
return _impl__zephyr_write((char *)buf, nbytes);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_POSIX_FS
|
||||
int _read(int fd, char *buf, int nbytes)
|
||||
{
|
||||
ARG_UNUSED(fd);
|
||||
|
||||
return _zephyr_read(buf, nbytes);
|
||||
}
|
||||
FUNC_ALIAS(_read, read, int);
|
||||
|
||||
int _write(int fd, char *buf, int nbytes)
|
||||
{
|
||||
ARG_UNUSED(fd);
|
||||
|
||||
return _zephyr_write(buf, nbytes);
|
||||
}
|
||||
FUNC_ALIAS(_write, write, int);
|
||||
|
||||
int _open(const char *name, int mode)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue