kernel: Allow Zephyr to use libc's internal errno

For a library which already provides a multi-thread aware errno, use
that instead of creating our own internal value.

Signed-off-by: Keith Packard <keithp@keithp.com>
This commit is contained in:
Keith Packard 2022-04-06 15:53:39 -07:00 committed by Anas Nashif
commit 4fc00cae7a
4 changed files with 22 additions and 6 deletions

View file

@ -169,7 +169,7 @@ struct _mem_domain_info {
#ifdef CONFIG_THREAD_USERSPACE_LOCAL_DATA #ifdef CONFIG_THREAD_USERSPACE_LOCAL_DATA
struct _thread_userspace_local_data { struct _thread_userspace_local_data {
#if defined(CONFIG_ERRNO) && !defined(CONFIG_ERRNO_IN_TLS) #if defined(CONFIG_ERRNO) && !defined(CONFIG_ERRNO_IN_TLS) && !defined(CONFIG_LIBC_ERRNO)
int errno_var; int errno_var;
#endif #endif
}; };
@ -274,7 +274,7 @@ struct k_thread {
struct _thread_userspace_local_data *userspace_local_data; struct _thread_userspace_local_data *userspace_local_data;
#endif #endif
#if defined(CONFIG_ERRNO) && !defined(CONFIG_ERRNO_IN_TLS) #if defined(CONFIG_ERRNO) && !defined(CONFIG_ERRNO_IN_TLS) && !defined(CONFIG_LIBC_ERRNO)
#ifndef CONFIG_USERSPACE #ifndef CONFIG_USERSPACE
/** per-thread errno variable */ /** per-thread errno variable */
int errno_var; int errno_var;

View file

@ -17,7 +17,15 @@ extern "C" {
* and kernel.h * and kernel.h
*/ */
#ifdef CONFIG_ERRNO_IN_TLS #ifdef CONFIG_LIBC_ERRNO
#include <errno.h>
static inline int *z_errno(void)
{
return &errno;
}
#elif defined(CONFIG_ERRNO_IN_TLS)
extern __thread int z_errno_var; extern __thread int z_errno_var;
static inline int *z_errno(void) static inline int *z_errno(void)
@ -41,7 +49,7 @@ __syscall int *z_errno(void);
} }
#endif #endif
#ifndef CONFIG_ERRNO_IN_TLS #if !defined(CONFIG_ERRNO_IN_TLS) && !defined(CONFIG_LIBC_ERRNO)
#include <syscalls/errno_private.h> #include <syscalls/errno_private.h>
#endif /* CONFIG_ERRNO_IN_TLS */ #endif /* CONFIG_ERRNO_IN_TLS */

View file

@ -204,6 +204,12 @@ config THREAD_USERSPACE_LOCAL_DATA
depends on USERSPACE depends on USERSPACE
default y if ERRNO && !ERRNO_IN_TLS default y if ERRNO && !ERRNO_IN_TLS
config LIBC_ERRNO
bool
help
Use external libc errno, not the internal one. This eliminates any
locally allocated errno storage and usage.
config ERRNO config ERRNO
bool "Errno support" bool "Errno support"
default y default y
@ -215,7 +221,7 @@ config ERRNO
config ERRNO_IN_TLS config ERRNO_IN_TLS
bool "Store errno in thread local storage (TLS)" bool "Store errno in thread local storage (TLS)"
depends on ERRNO && THREAD_LOCAL_STORAGE depends on ERRNO && THREAD_LOCAL_STORAGE && !LIBC_ERRNO
default y default y
help help
Use thread local storage to store errno instead of storing it in Use thread local storage to store errno instead of storing it in

View file

@ -24,7 +24,9 @@ const int _k_neg_eagain = -EAGAIN;
#ifdef CONFIG_ERRNO #ifdef CONFIG_ERRNO
#ifdef CONFIG_ERRNO_IN_TLS #if defined(CONFIG_LIBC_ERRNO)
/* nothing needed here */
#elif defined(CONFIG_ERRNO_IN_TLS)
__thread int z_errno_var; __thread int z_errno_var;
#else #else