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
This commit is contained in:
Sebastian Sumpf 2019-12-11 15:42:46 +01:00 committed by Christian Helmuth
parent 9767c4db0e
commit 9c372c36c1
2 changed files with 4 additions and 2 deletions

View File

@ -13,9 +13,9 @@
* under the terms of the GNU Affero General Public License version 3.
*/
static int private_errno;
#include <internal/pthread.h>
extern "C" int *__error(void)
{
return &private_errno;
return &pthread_self()->thread_local_errno;
}

View File

@ -180,6 +180,8 @@ struct Libc::Pthread : Noncopyable, Thread::Tls::Base
public:
int thread_local_errno = 0;
/**
* Constructor for threads created via 'pthread_create'
*/