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:
Andrew Boie 2018-03-26 17:07:33 -07:00 committed by Anas Nashif
commit 12e6aadcb0
2 changed files with 50 additions and 4 deletions

View file

@ -16,6 +16,18 @@
* that need to call into the kernel as system calls
*/
#ifdef CONFIG_NEWLIB_LIBC
/* syscall generation ignores preprocessor, ensure this is defined to ensure
* we don't have compile errors
*/
#define _MLIBC_RESTRICT
__syscall int _zephyr_read(char *buf, int nbytes);
__syscall int _zephyr_write(char *buf, int nbytes);
#else
/* Minimal libc */
__syscall int _zephyr_fputc(int c, FILE *stream);
@ -23,6 +35,8 @@ __syscall int _zephyr_fputc(int c, FILE *stream);
__syscall size_t _zephyr_fwrite(const void *_MLIBC_RESTRICT ptr, size_t size,
size_t nitems, FILE *_MLIBC_RESTRICT stream);
#endif /* CONFIG_NEWLIB_LIBC */
#include <syscalls/libc-hooks.h>
#endif /* ZEPHYR_LIBC_HOOKS_H */