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/newlib | |
| parent | c8c632512aa6c87211871fe0a85e77b72d4ebe06 (diff) | |
[libc][syscalls] 在标准输入输出前加校验,反正在libc初始化之前调用printf出问题
Diffstat (limited to 'components/libc/compilers/newlib')
| -rw-r--r-- | components/libc/compilers/newlib/syscalls.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/components/libc/compilers/newlib/syscalls.c b/components/libc/compilers/newlib/syscalls.c index aeb4d123e7..d46a264408 100644 --- a/components/libc/compilers/newlib/syscalls.c +++ b/components/libc/compilers/newlib/syscalls.c @@ -26,6 +26,10 @@ #include <dlmodule.h> #endif +#define DBG_TAG "newlib.syscalls" +#define DBG_LVL DBG_INFO +#include <rtdbg.h> + /* Reentrant versions of system calls. */ #ifndef _REENT_ONLY @@ -155,7 +159,11 @@ _ssize_t _read_r(struct _reent *ptr, int fd, void *buf, size_t nbytes) return -1; #else _ssize_t rc; - + if (libc_stdio_get_console() < 0 && fd == STDIN_FILENO) + { + LOG_E("invoke standard input before initializing libc"); + return -1; + } rc = read(fd, buf, nbytes); return rc; #endif @@ -227,7 +235,11 @@ _ssize_t _write_r(struct _reent *ptr, int fd, const void *buf, size_t nbytes) #endif /*RT_USING_DEVICE*/ #else _ssize_t rc; - + if (libc_stdio_get_console() < 0 && fd == STDOUT_FILENO) + { + LOG_E("invoke standard output before initializing libc"); + return -1; + } rc = write(fd, buf, nbytes); return rc; #endif |
