diff --git a/components/libc/compilers/picolibc/syscall.c b/components/libc/compilers/picolibc/syscall.c index ba496c6864..c2e45624f9 100644 --- a/components/libc/compilers/picolibc/syscall.c +++ b/components/libc/compilers/picolibc/syscall.c @@ -9,13 +9,31 @@ */ #include +#include -int pico_get_errno(void) +/* global errno */ +static volatile int __pico_errno; + +int *pico_get_errno(void) { - return rt_get_errno(); + rt_thread_t tid = RT_NULL; + + if (rt_interrupt_get_nest() != 0) + { + /* it's in interrupt context */ + return &__pico_errno; + } + + tid = rt_thread_self(); + if (tid == RT_NULL) + { + return &__pico_errno; + } + + return &tid->error; } -#ifdef RT_USING_HEAP /* Memory routine */ +#ifdef RT_USING_HEAP void *malloc(size_t n) { return rt_malloc(n); @@ -39,4 +57,4 @@ void free(void *rmem) rt_free(rmem); } RTM_EXPORT(free); -#endif +#endif /* RT_USING_HEAP */