Make pthread_attr_getstack__main_thread test native-bridge friendly
Detect stack mappings based on a pointer to the stack instead of
relying on "[stack]" label. This does not change the test but
makes it native-bridge friendly. In translated environment native
bridge implementation may have a separate stack for the guest code.
Bug: http://b/30443561
Test: bionic-unit-tests --gtest_filter=pthread*
Change-Id: Ic98a3b74b43ec63c7b37821a1f86525d32efd459
diff --git a/tests/pthread_test.cpp b/tests/pthread_test.cpp
index 9ecb10c..fb982f2 100644
--- a/tests/pthread_test.cpp
+++ b/tests/pthread_test.cpp
@@ -1378,18 +1378,23 @@
EXPECT_EQ(stack_size, stack_size2);
#if defined(__BIONIC__)
- // What does /proc/self/maps' [stack] line say?
+ // Find stack in /proc/self/maps using a pointer to the stack.
+ //
+ // We do not use "[stack]" label because in native-bridge environment it is not
+ // guaranteed to point to the right stack. A native bridge implementation may
+ // keep separate stack for the guest code.
void* maps_stack_hi = NULL;
std::vector<map_record> maps;
ASSERT_TRUE(Maps::parse_maps(&maps));
+ uintptr_t stack_address = reinterpret_cast<uintptr_t>(&maps_stack_hi);
for (const auto& map : maps) {
- if (map.pathname == "[stack]") {
+ if (map.addr_start <= stack_address && map.addr_end > stack_address){
maps_stack_hi = reinterpret_cast<void*>(map.addr_end);
break;
}
}
- // The high address of the /proc/self/maps [stack] region should equal stack_base + stack_size.
+ // The high address of the /proc/self/maps stack region should equal stack_base + stack_size.
// Remember that the stack grows down (and is mapped in on demand), so the low address of the
// region isn't very interesting.
EXPECT_EQ(maps_stack_hi, reinterpret_cast<uint8_t*>(stack_base) + stack_size);