Skip to content

Commit 4fc00ca

Browse files
keith-packardnashif
authored andcommitted
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 <[email protected]>
1 parent f14e9e4 commit 4fc00ca

File tree

4 files changed

+22
-6
lines changed

4 files changed

+22
-6
lines changed

include/zephyr/kernel/thread.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ struct _mem_domain_info {
169169

170170
#ifdef CONFIG_THREAD_USERSPACE_LOCAL_DATA
171171
struct _thread_userspace_local_data {
172-
#if defined(CONFIG_ERRNO) && !defined(CONFIG_ERRNO_IN_TLS)
172+
#if defined(CONFIG_ERRNO) && !defined(CONFIG_ERRNO_IN_TLS) && !defined(CONFIG_LIBC_ERRNO)
173173
int errno_var;
174174
#endif
175175
};
@@ -274,7 +274,7 @@ struct k_thread {
274274
struct _thread_userspace_local_data *userspace_local_data;
275275
#endif
276276

277-
#if defined(CONFIG_ERRNO) && !defined(CONFIG_ERRNO_IN_TLS)
277+
#if defined(CONFIG_ERRNO) && !defined(CONFIG_ERRNO_IN_TLS) && !defined(CONFIG_LIBC_ERRNO)
278278
#ifndef CONFIG_USERSPACE
279279
/** per-thread errno variable */
280280
int errno_var;

include/zephyr/sys/errno_private.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,15 @@ extern "C" {
1717
* and kernel.h
1818
*/
1919

20-
#ifdef CONFIG_ERRNO_IN_TLS
20+
#ifdef CONFIG_LIBC_ERRNO
21+
#include <errno.h>
22+
23+
static inline int *z_errno(void)
24+
{
25+
return &errno;
26+
}
27+
28+
#elif defined(CONFIG_ERRNO_IN_TLS)
2129
extern __thread int z_errno_var;
2230

2331
static inline int *z_errno(void)
@@ -41,7 +49,7 @@ __syscall int *z_errno(void);
4149
}
4250
#endif
4351

44-
#ifndef CONFIG_ERRNO_IN_TLS
52+
#if !defined(CONFIG_ERRNO_IN_TLS) && !defined(CONFIG_LIBC_ERRNO)
4553
#include <syscalls/errno_private.h>
4654
#endif /* CONFIG_ERRNO_IN_TLS */
4755

kernel/Kconfig

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,12 @@ config THREAD_USERSPACE_LOCAL_DATA
204204
depends on USERSPACE
205205
default y if ERRNO && !ERRNO_IN_TLS
206206

207+
config LIBC_ERRNO
208+
bool
209+
help
210+
Use external libc errno, not the internal one. This eliminates any
211+
locally allocated errno storage and usage.
212+
207213
config ERRNO
208214
bool "Errno support"
209215
default y
@@ -215,7 +221,7 @@ config ERRNO
215221

216222
config ERRNO_IN_TLS
217223
bool "Store errno in thread local storage (TLS)"
218-
depends on ERRNO && THREAD_LOCAL_STORAGE
224+
depends on ERRNO && THREAD_LOCAL_STORAGE && !LIBC_ERRNO
219225
default y
220226
help
221227
Use thread local storage to store errno instead of storing it in

kernel/errno.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ const int _k_neg_eagain = -EAGAIN;
2424

2525
#ifdef CONFIG_ERRNO
2626

27-
#ifdef CONFIG_ERRNO_IN_TLS
27+
#if defined(CONFIG_LIBC_ERRNO)
28+
/* nothing needed here */
29+
#elif defined(CONFIG_ERRNO_IN_TLS)
2830
__thread int z_errno_var;
2931
#else
3032

0 commit comments

Comments
 (0)