Add __libc_add_main_thread and mark it weak
This complements __libc_init_main_thread in setting up main thread
under native bridge.
Test: run_tests
Bug: 77877742
Change-Id: I53efab66f285a1b9f0ab36d44386fa1e2621e4ba
(cherry picked from commit 4c9504aa6cb4dad5142056d5e46bcb8409fd476d)
diff --git a/libc/bionic/libc_init_common.cpp b/libc/bionic/libc_init_common.cpp
index c22f571..2396c36 100644
--- a/libc/bionic/libc_init_common.cpp
+++ b/libc/bionic/libc_init_common.cpp
@@ -46,6 +46,7 @@
#include "private/KernelArgumentBlock.h"
#include "private/WriteProtected.h"
#include "private/bionic_auxv.h"
+#include "private/bionic_defs.h"
#include "private/bionic_globals.h"
#include "private/bionic_tls.h"
#include "private/thread_private.h"
@@ -107,6 +108,13 @@
_thread_arc4_lock();
}
+__BIONIC_WEAK_FOR_NATIVE_BRIDGE
+void __libc_add_main_thread() {
+ // Get the main thread from TLS and add it to the thread list.
+ pthread_internal_t* main_thread = __get_thread();
+ __pthread_internal_add(main_thread);
+}
+
void __libc_init_common(KernelArgumentBlock& args) {
// Initialize various globals.
environ = args.envp;
@@ -118,9 +126,7 @@
__check_max_thread_id();
#endif
- // Get the main thread from TLS and add it to the thread list.
- pthread_internal_t* main_thread = __get_thread();
- __pthread_internal_add(main_thread);
+ __libc_add_main_thread();
// Register atfork handlers to take and release the arc4random lock.
pthread_atfork(arc4random_fork_handler, _thread_arc4_unlock, _thread_arc4_unlock);