From 9c372c36c179d84a38404559f8293ab50d7aad44 Mon Sep 17 00:00:00 2001 From: Sebastian Sumpf Date: Wed, 11 Dec 2019 15:42:46 +0100 Subject: [PATCH] libc: thread local errno support Store errno in pthread objects, return member upon call to '__error()'. This became necessary in order to make errno thread-safe. Note, any call to libc code from a non-pthread (beside the first entrypoint) is not supported. issue #3568 --- repos/libports/src/lib/libc/errno.cc | 4 ++-- repos/libports/src/lib/libc/internal/pthread.h | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/repos/libports/src/lib/libc/errno.cc b/repos/libports/src/lib/libc/errno.cc index 806107683..63cbf0022 100644 --- a/repos/libports/src/lib/libc/errno.cc +++ b/repos/libports/src/lib/libc/errno.cc @@ -13,9 +13,9 @@ * under the terms of the GNU Affero General Public License version 3. */ -static int private_errno; +#include extern "C" int *__error(void) { - return &private_errno; + return &pthread_self()->thread_local_errno; } diff --git a/repos/libports/src/lib/libc/internal/pthread.h b/repos/libports/src/lib/libc/internal/pthread.h index 674020c28..e5b9616f8 100644 --- a/repos/libports/src/lib/libc/internal/pthread.h +++ b/repos/libports/src/lib/libc/internal/pthread.h @@ -180,6 +180,8 @@ struct Libc::Pthread : Noncopyable, Thread::Tls::Base public: + int thread_local_errno = 0; + /** * Constructor for threads created via 'pthread_create' */