From 923c38f7cd1c62b3a48028cc1314eaa60ec2cfd0 Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Fri, 13 Mar 2020 21:40:43 +0100 Subject: [PATCH] libc: allocate errno of main thread statically The thread-local errno instance for the main thread must not be allocated on the application heap because it must survive 'execve'. Fixes #3701 --- repos/libports/src/lib/libc/pthread.cc | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/repos/libports/src/lib/libc/pthread.cc b/repos/libports/src/lib/libc/pthread.cc index 02161722c..37b03c0e1 100644 --- a/repos/libports/src/lib/libc/pthread.cc +++ b/repos/libports/src/lib/libc/pthread.cc @@ -19,6 +19,9 @@ #include #include +/* Genode-internal includes */ +#include + /* libc includes */ #include #include @@ -588,13 +591,11 @@ extern "C" { /* * We create a pthread object associated to the main thread's Thread * object. We ensure the pthread object does never get deleted by - * allocating it in heap via new(). Otherwise, the static destruction - * of the pthread object would also destruct the 'Thread' of the main - * thread. + * allocating it as unmanaged_singleton. Otherwise, the static + * destruction of the pthread object would also destruct the 'Thread' + * of the main thread. */ - Libc::Allocator alloc { }; - static pthread *main = new (alloc) pthread(*Thread::myself()); - return main; + return unmanaged_singleton(*Thread::myself()); }