am adebbfc9: am 7f1e2068: Merge "Fix alignment error for pthread_internal_t/pthread stack."

* commit 'adebbfc994e56b53e0c8ae420373b6ee57a9d4d3':
  Fix alignment error for pthread_internal_t/pthread stack.
This commit is contained in:
Yabin Cui 2015-03-23 23:24:18 +00:00 committed by Android Git Automerger
commit d1fe16f448
2 changed files with 7 additions and 6 deletions

View File

@ -162,15 +162,16 @@ static int __allocate_thread(pthread_attr_t* attr, pthread_internal_t** threadp,
} }
// Mapped space(or user allocated stack) is used for: // Mapped space(or user allocated stack) is used for:
// thread_internal_t // pthread_internal_t
// thread stack (including guard page) // thread stack (including guard page)
stack_top -= sizeof(pthread_internal_t);
// To safely access the pthread_internal_t and thread stack, we need to find a 16-byte aligned boundary.
stack_top = reinterpret_cast<uint8_t*>(
(reinterpret_cast<uintptr_t>(stack_top) - sizeof(pthread_internal_t)) & ~0xf);
pthread_internal_t* thread = reinterpret_cast<pthread_internal_t*>(stack_top); pthread_internal_t* thread = reinterpret_cast<pthread_internal_t*>(stack_top);
attr->stack_size = stack_top - reinterpret_cast<uint8_t*>(attr->stack_base); attr->stack_size = stack_top - reinterpret_cast<uint8_t*>(attr->stack_base);
// No need to check stack_top alignment. The size of pthread_internal_t is 16-bytes aligned,
// and user allocated stack is guaranteed by pthread_attr_setstack.
thread->mmap_size = mmap_size; thread->mmap_size = mmap_size;
thread->attr = *attr; thread->attr = *attr;
__init_tls(thread); __init_tls(thread);

View File

@ -103,7 +103,7 @@ struct pthread_internal_t {
*/ */
#define __BIONIC_DLERROR_BUFFER_SIZE 512 #define __BIONIC_DLERROR_BUFFER_SIZE 512
char dlerror_buffer[__BIONIC_DLERROR_BUFFER_SIZE]; char dlerror_buffer[__BIONIC_DLERROR_BUFFER_SIZE];
} __attribute__((aligned(16))); // Align it as thread stack top below it should be aligned. };
__LIBC_HIDDEN__ int __init_thread(pthread_internal_t* thread, bool add_to_thread_list); __LIBC_HIDDEN__ int __init_thread(pthread_internal_t* thread, bool add_to_thread_list);
__LIBC_HIDDEN__ void __init_tls(pthread_internal_t* thread); __LIBC_HIDDEN__ void __init_tls(pthread_internal_t* thread);