Merge "Update Android.bp"
diff --git a/libc/bionic/pthread_internal.cpp b/libc/bionic/pthread_internal.cpp
index 1967ccf..8946f79 100644
--- a/libc/bionic/pthread_internal.cpp
+++ b/libc/bionic/pthread_internal.cpp
@@ -81,6 +81,12 @@
pthread_internal_t* __pthread_internal_find(pthread_t thread_id) {
pthread_internal_t* thread = reinterpret_cast<pthread_internal_t*>(thread_id);
+
+ // check if thread is pthread_self() before acquiring the lock
+ if (thread == __get_thread()) {
+ return thread;
+ }
+
ScopedPthreadMutexLocker locker(&g_thread_list_lock);
for (pthread_internal_t* t = g_thread_list; t != NULL; t = t->next) {
diff --git a/tests/stdio_test.cpp b/tests/stdio_test.cpp
index 2912be4..79a86ad 100644
--- a/tests/stdio_test.cpp
+++ b/tests/stdio_test.cpp
@@ -534,6 +534,25 @@
freelocale(cloc);
}
+static void* snprintf_small_stack_fn(void*) {
+ // Make life (realistically) hard for ourselves by allocating our own buffer for the result.
+ char buf[PATH_MAX];
+ snprintf(buf, sizeof(buf), "/proc/%d", getpid());
+ return nullptr;
+}
+
+TEST(STDIO_TEST, snprintf_small_stack) {
+ // Is it safe to call snprintf on a thread with a small stack?
+ // (The snprintf implementation puts some pretty large buffers on the stack.)
+ pthread_attr_t a;
+ ASSERT_EQ(0, pthread_attr_init(&a));
+ ASSERT_EQ(0, pthread_attr_setstacksize(&a, PTHREAD_STACK_MIN));
+
+ pthread_t t;
+ ASSERT_EQ(0, pthread_create(&t, &a, snprintf_small_stack_fn, nullptr));
+ ASSERT_EQ(0, pthread_join(t, nullptr));
+}
+
TEST(STDIO_TEST, fprintf_failures_7229520) {
// http://b/7229520
FILE* fp;
diff --git a/tests/time_test.cpp b/tests/time_test.cpp
index ec1b549..6cdabd2 100644
--- a/tests/time_test.cpp
+++ b/tests/time_test.cpp
@@ -59,19 +59,13 @@
// Is it safe to call tzload on a thread with a small stack?
// http://b/14313703
// https://code.google.com/p/android/issues/detail?id=61130
- pthread_attr_t attributes;
- ASSERT_EQ(0, pthread_attr_init(&attributes));
-#if defined(__BIONIC__)
- ASSERT_EQ(0, pthread_attr_setstacksize(&attributes, PTHREAD_STACK_MIN));
-#else
- // PTHREAD_STACK_MIN not currently in the host GCC sysroot.
- ASSERT_EQ(0, pthread_attr_setstacksize(&attributes, 4 * getpagesize()));
-#endif
+ pthread_attr_t a;
+ ASSERT_EQ(0, pthread_attr_init(&a));
+ ASSERT_EQ(0, pthread_attr_setstacksize(&a, PTHREAD_STACK_MIN));
pthread_t t;
- ASSERT_EQ(0, pthread_create(&t, &attributes, gmtime_no_stack_overflow_14313703_fn, NULL));
- void* result;
- ASSERT_EQ(0, pthread_join(t, &result));
+ ASSERT_EQ(0, pthread_create(&t, &a, gmtime_no_stack_overflow_14313703_fn, NULL));
+ ASSERT_EQ(0, pthread_join(t, nullptr));
}
TEST(time, mktime_empty_TZ) {