From 606407998352cf40b8d21a8d621e2a57d0b291f0 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Mon, 14 Aug 2023 18:17:06 -0400 Subject: [PATCH 1/2] [rtdef] support POSIX compatible errno --- include/rtdef.h | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/include/rtdef.h b/include/rtdef.h index 972bc78b6ab..eabbf009ad8 100644 --- a/include/rtdef.h +++ b/include/rtdef.h @@ -68,6 +68,7 @@ #include #if !RT_USING_LIBC_ISO_ONLY #include +#include #if defined(RT_USING_SIGNALS) || defined(RT_USING_SMART) #include #endif /* defined(RT_USING_SIGNALS) || defined(RT_USING_SMART) */ @@ -396,27 +397,44 @@ typedef int (*init_fn_t)(void); #endif /** - * @addtogroup Error + * @addtogroup Error Code */ /**@{*/ /* RT-Thread error code definitions */ +#if defined(RT_USING_LIBC) && !RT_USING_LIBC_ISO_ONLY +/* POSIX error code compatible */ +#define RT_EOK 0 /**< There is no error */ +#define RT_ERROR 255 /**< A generic/unknown error happens */ +#define RT_ETIMEOUT ETIMEDOUT /**< Timed out */ +#define RT_EFULL ENOSPC /**< The resource is full */ +#define RT_EEMPTY ENODATA /**< The resource is empty */ +#define RT_ENOMEM ENOMEM /**< No memory */ +#define RT_ENOSYS ENOSYS /**< Function not implemented */ +#define RT_EBUSY EBUSY /**< Busy */ +#define RT_EIO EIO /**< IO error */ +#define RT_EINTR EINTR /**< Interrupted system call */ +#define RT_EINVAL EINVAL /**< Invalid argument */ +#define RT_ENOENT ENOENT /**< No entry */ +#define RT_ENOSPC ENOSPC /**< No space left */ +#define RT_EPERM EPERM /**< Operation not permitted */ +#else #define RT_EOK 0 /**< There is no error */ -#define RT_ERROR 1 /**< A generic error happens */ +#define RT_ERROR 1 /**< A generic/unknown error happens */ #define RT_ETIMEOUT 2 /**< Timed out */ #define RT_EFULL 3 /**< The resource is full */ #define RT_EEMPTY 4 /**< The resource is empty */ #define RT_ENOMEM 5 /**< No memory */ -#define RT_ENOSYS 6 /**< No system */ +#define RT_ENOSYS 6 /**< Function not implemented */ #define RT_EBUSY 7 /**< Busy */ #define RT_EIO 8 /**< IO error */ #define RT_EINTR 9 /**< Interrupted system call */ #define RT_EINVAL 10 /**< Invalid argument */ -#define RT_ETRAP 11 /**< Trap event */ -#define RT_ENOENT 12 /**< No entry */ -#define RT_ENOSPC 13 /**< No space left */ -#define RT_EPERM 14 /**< Operation not permitted */ +#define RT_ENOENT 11 /**< No entry */ +#define RT_ENOSPC 12 /**< No space left */ +#define RT_EPERM 13 /**< Operation not permitted */ +#endif /* defined(RT_USING_LIBC) && !RT_USING_LIBC_ISO_ONLY */ /**@}*/ From 37b8b626776b247a9328ec341136d1de4e4c6cee Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Tue, 19 Sep 2023 01:50:22 -0400 Subject: [PATCH 2/2] [picolibc] fix the errno declaration conflict /home/runner/work/rt-thread/rt-thread/components/libc/compilers/picolibc/syscall.c:13:5: error: conflicting types for 'pico_get_errno' int pico_get_errno(void) ^ /opt/LLVMEmbeddedToolchainForArm-16.0.0-Linux-x86_64/bin/../lib/clang-runtimes/arm-none-eabi/armv7em_hard_fpv4_sp_d16/include/sys/errno.h:59:6: note: previous declaration is here int *__PICOLIBC_ERRNO_FUNCTION(void); --- components/libc/compilers/picolibc/syscall.c | 26 +++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/components/libc/compilers/picolibc/syscall.c b/components/libc/compilers/picolibc/syscall.c index ba496c68648..c2e45624f9f 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 */