From 36733fc4c10854766cca3b617aae61149895e4b2 Mon Sep 17 00:00:00 2001 From: Yabin Cui Date: Tue, 29 Mar 2016 12:25:12 -0700 Subject: [PATCH] Check current pid at libc initialization for 32-bit build. Although there is a test pthread.pthread_mutex_owner_tid_limit to check pid_max, but bionic-unit-tests hangs before reaching that test. So abort at libc initialization if not able to reach the test when running bionic-unit-tests32. It is more friendly for debugging. Bug: 24016357 Change-Id: Ia70c2e36fd8a3a040d41ea5722c7b48a6134e102 --- libc/bionic/libc_init_common.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/libc/bionic/libc_init_common.cpp b/libc/bionic/libc_init_common.cpp index c2a5feda0..24e044227 100644 --- a/libc/bionic/libc_init_common.cpp +++ b/libc/bionic/libc_init_common.cpp @@ -83,6 +83,15 @@ void __libc_init_globals(KernelArgumentBlock& args) { }); } +#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; @@ -90,6 +99,10 @@ void __libc_init_common(KernelArgumentBlock& args) { __progname = args.argv[0] ? args.argv[0] : ""; __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);