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:
parent
ee6d38a770
commit
923c38f7cd
|
@ -19,6 +19,9 @@
|
||||||
#include <util/list.h>
|
#include <util/list.h>
|
||||||
#include <libc/allocator.h>
|
#include <libc/allocator.h>
|
||||||
|
|
||||||
|
/* Genode-internal includes */
|
||||||
|
#include <base/internal/unmanaged_singleton.h>
|
||||||
|
|
||||||
/* libc includes */
|
/* libc includes */
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
@ -588,13 +591,11 @@ extern "C" {
|
||||||
/*
|
/*
|
||||||
* We create a pthread object associated to the main thread's Thread
|
* We create a pthread object associated to the main thread's Thread
|
||||||
* object. We ensure the pthread object does never get deleted by
|
* object. We ensure the pthread object does never get deleted by
|
||||||
* allocating it in heap via new(). Otherwise, the static destruction
|
* allocating it as unmanaged_singleton. Otherwise, the static
|
||||||
* of the pthread object would also destruct the 'Thread' of the main
|
* destruction of the pthread object would also destruct the 'Thread'
|
||||||
* thread.
|
* of the main thread.
|
||||||
*/
|
*/
|
||||||
Libc::Allocator alloc { };
|
return unmanaged_singleton<pthread>(*Thread::myself());
|
||||||
static pthread *main = new (alloc) pthread(*Thread::myself());
|
|
||||||
return main;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user