[lib][libc] Make errno thread safe using TLS APIs

Before this change, errno was "completely un-threadsafe" as the comment
states.

This changes errno to be threadsafe by making errno a thread local
variable.
This commit is contained in:
Matt Schulte
2025-07-10 14:07:35 -07:00
committed by Travis Geiselbrecht
parent 2d567e437d
commit e51cf68c3c
2 changed files with 3 additions and 5 deletions

View File

@@ -57,6 +57,7 @@ enum thread_tls_list {
#ifdef WITH_LIB_LKUSER
TLS_ENTRY_LKUSER,
#endif
TLS_ENTRY_ERRNO,
MAX_TLS_ENTRY
};

View File

@@ -7,12 +7,9 @@
*/
#include <errno.h>
/* completely un-threadsafe implementation of errno */
/* TODO: pull from kernel TLS or some other thread local storage */
static int _errno;
#include <kernel/thread.h>
int *__geterrno(void) {
return &_errno;
return (int*)tls_get(TLS_ENTRY_ERRNO);
}