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
This commit is contained in:
Norman Feske 2020-03-13 21:40:43 +01:00
parent ee6d38a770
commit 923c38f7cd
1 changed files with 7 additions and 6 deletions

View File

@ -19,6 +19,9 @@
#include <util/list.h>
#include <libc/allocator.h>
/* Genode-internal includes */
#include <base/internal/unmanaged_singleton.h>
/* libc includes */
#include <errno.h>
#include <pthread.h>
@ -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<pthread>(*Thread::myself());
}