Merge "Check current pid at libc initialization for 32-bit build."
diff --git a/libc/bionic/libc_init_common.cpp b/libc/bionic/libc_init_common.cpp
index 1796109..0c9e87b 100644
--- a/libc/bionic/libc_init_common.cpp
+++ b/libc/bionic/libc_init_common.cpp
@@ -99,6 +99,15 @@
});
}
+#if !defined(__LP64__)
+static void __check_max_thread_id() {
+ if (gettid() > 65535) {
+ __libc_fatal("Limited by the size of pthread_mutex_t, 32 bit bionic libc only accepts "
+ "pid <= 65535, but current pid is %d", gettid());
+ }
+}
+#endif
+
void __libc_init_common(KernelArgumentBlock& args) {
// Initialize various globals.
environ = args.envp;
@@ -106,6 +115,10 @@
__progname = args.argv[0] ? args.argv[0] : "<unknown>";
__abort_message_ptr = args.abort_message_ptr;
+#if !defined(__LP64__)
+ __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);