diff options
| author | Meco Man <[email protected]> | 2021-09-27 06:51:40 -0400 |
|---|---|---|
| committer | Meco Man <[email protected]> | 2021-09-27 06:51:40 -0400 |
| commit | 86bb54fde6f3ed59050d724a7e98defd7c4f47a9 (patch) | |
| tree | 60a05ee95a35859cc1fd55c5cff2b083d686445c /components/libc/compilers/armlibc | |
| parent | c8c632512aa6c87211871fe0a85e77b72d4ebe06 (diff) | |
[libc][syscalls] 在标准输入输出前加校验,反正在libc初始化之前调用printf出问题
Diffstat (limited to 'components/libc/compilers/armlibc')
| -rw-r--r-- | components/libc/compilers/armlibc/syscalls.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/components/libc/compilers/armlibc/syscalls.c b/components/libc/compilers/armlibc/syscalls.c index d942bdb984..a3ba57a280 100644 --- a/components/libc/compilers/armlibc/syscalls.c +++ b/components/libc/compilers/armlibc/syscalls.c @@ -25,6 +25,10 @@ #include <dfs_posix.h> #endif +#define DBG_TAG "armlibc.syscalls" +#define DBG_LVL DBG_INFO +#include <rtdbg.h> + #ifdef __CLANG_ARM __asm(".global __use_no_semihosting\n\t"); #else @@ -146,6 +150,11 @@ int _sys_read(FILEHANDLE fh, unsigned char *buf, unsigned len, int mode) if (fh == STDIN) { #ifdef RT_USING_POSIX + if (libc_stdio_get_console() < 0) + { + LOG_E("invoke standard output before initializing libc"); + return -1; + } size = read(STDIN_FILENO, buf, len); return len - size; #else @@ -186,6 +195,11 @@ int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode) return 0; #else #ifdef RT_USING_POSIX + if (libc_stdio_get_console() < 0) + { + LOG_E("invoke standard input before initializing libc"); + return -1; + } size = write(STDOUT_FILENO, buf, len); return len - size; #else |
