am ac045c32: am f83148af: am 0c17099a: Merge "Fix __errno for LP64 and clean up __get_tls."
* commit 'ac045c32d067d61cb48370eaa10118e827ebf586': Fix __errno for LP64 and clean up __get_tls.
This commit is contained in:
commit
c528d938aa
@ -186,6 +186,7 @@ ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),arm mips x86))
|
|||||||
libc_common_src_files += \
|
libc_common_src_files += \
|
||||||
bionic/fcntl.c \
|
bionic/fcntl.c \
|
||||||
bionic/fstatfs.c \
|
bionic/fstatfs.c \
|
||||||
|
bionic/__get_tls.cpp \
|
||||||
bionic/lseek64.c \
|
bionic/lseek64.c \
|
||||||
bionic/sigsuspend.c \
|
bionic/sigsuspend.c \
|
||||||
bionic/statfs.c \
|
bionic/statfs.c \
|
||||||
@ -218,7 +219,7 @@ libc_bionic_src_files := \
|
|||||||
bionic/assert.cpp \
|
bionic/assert.cpp \
|
||||||
bionic/brk.cpp \
|
bionic/brk.cpp \
|
||||||
bionic/dirent.cpp \
|
bionic/dirent.cpp \
|
||||||
bionic/__errno.c \
|
bionic/__errno.cpp \
|
||||||
bionic/eventfd_read.cpp \
|
bionic/eventfd_read.cpp \
|
||||||
bionic/eventfd_write.cpp \
|
bionic/eventfd_write.cpp \
|
||||||
bionic/futimens.cpp \
|
bionic/futimens.cpp \
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
_LIBC_ARCH_COMMON_SRC_FILES := \
|
_LIBC_ARCH_COMMON_SRC_FILES := \
|
||||||
arch-mips/bionic/__get_sp.S \
|
arch-mips/bionic/__get_sp.S \
|
||||||
arch-mips/bionic/__get_tls.c \
|
|
||||||
arch-mips/bionic/__set_tls.c \
|
arch-mips/bionic/__set_tls.c \
|
||||||
arch-mips/bionic/_exit_with_stack_teardown.S \
|
arch-mips/bionic/_exit_with_stack_teardown.S \
|
||||||
arch-mips/bionic/_setjmp.S \
|
arch-mips/bionic/_setjmp.S \
|
||||||
|
@ -1,37 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2008 The Android Open Source Project
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions
|
|
||||||
* are met:
|
|
||||||
* * Redistributions of source code must retain the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer.
|
|
||||||
* * Redistributions in binary form must reproduce the above copyright
|
|
||||||
* notice, this list of conditions and the following disclaimer in
|
|
||||||
* the documentation and/or other materials provided with the
|
|
||||||
* distribution.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
||||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
||||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
||||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
||||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
||||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
||||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
||||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
|
||||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
||||||
* SUCH DAMAGE.
|
|
||||||
*/
|
|
||||||
/* see the implementation of __set_tls and pthread.c to understand this
|
|
||||||
* code. Basically, the content of gs:[0] always is a pointer to the base
|
|
||||||
* address of the tls region
|
|
||||||
*/
|
|
||||||
void* __get_tls(void)
|
|
||||||
{
|
|
||||||
void* tls;
|
|
||||||
asm ( " movl %%gs:0, %0" : "=r"(tls) );
|
|
||||||
return tls;
|
|
||||||
}
|
|
@ -3,7 +3,6 @@ _LIBC_ARCH_COMMON_SRC_FILES := \
|
|||||||
arch-x86/bionic/_exit_with_stack_teardown.S \
|
arch-x86/bionic/_exit_with_stack_teardown.S \
|
||||||
arch-x86/bionic/futex_x86.S \
|
arch-x86/bionic/futex_x86.S \
|
||||||
arch-x86/bionic/__get_sp.S \
|
arch-x86/bionic/__get_sp.S \
|
||||||
arch-x86/bionic/__get_tls.c \
|
|
||||||
arch-x86/bionic/_setjmp.S \
|
arch-x86/bionic/_setjmp.S \
|
||||||
arch-x86/bionic/setjmp.S \
|
arch-x86/bionic/setjmp.S \
|
||||||
arch-x86/bionic/__set_tls.c \
|
arch-x86/bionic/__set_tls.c \
|
||||||
|
@ -3,7 +3,6 @@ _LIBC_ARCH_COMMON_SRC_FILES := \
|
|||||||
arch-x86_64/bionic/_exit_with_stack_teardown.S \
|
arch-x86_64/bionic/_exit_with_stack_teardown.S \
|
||||||
arch-x86_64/bionic/futex_x86_64.S \
|
arch-x86_64/bionic/futex_x86_64.S \
|
||||||
arch-x86_64/bionic/__get_sp.S \
|
arch-x86_64/bionic/__get_sp.S \
|
||||||
arch-x86_64/bionic/__get_tls.c \
|
|
||||||
arch-x86_64/bionic/__rt_sigreturn.S \
|
arch-x86_64/bionic/__rt_sigreturn.S \
|
||||||
arch-x86_64/bionic/_setjmp.S \
|
arch-x86_64/bionic/_setjmp.S \
|
||||||
arch-x86_64/bionic/setjmp.S \
|
arch-x86_64/bionic/setjmp.S \
|
||||||
|
@ -25,10 +25,11 @@
|
|||||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <bionic_tls.h>
|
#include <bionic_tls.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
volatile int* __errno( void )
|
volatile int* __errno() {
|
||||||
{
|
return reinterpret_cast<int*>(&(__get_tls()[TLS_SLOT_ERRNO]));
|
||||||
return &((volatile int*)__get_tls())[TLS_SLOT_ERRNO];
|
|
||||||
}
|
}
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2013 The Android Open Source Project
|
* Copyright (C) 2008 The Android Open Source Project
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@ -26,8 +26,7 @@
|
|||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void* __get_tls(void) {
|
extern "C" void** __get_tls() {
|
||||||
void* tls;
|
#include "private/__get_tls.h"
|
||||||
asm ("mov %%fs:0, %0" : "=r"(tls));
|
return __get_tls();
|
||||||
return tls;
|
|
||||||
}
|
}
|
@ -65,7 +65,7 @@ extern "C" {
|
|||||||
// as soon as the shared library is loaded.
|
// as soon as the shared library is loaded.
|
||||||
__attribute__((constructor)) static void __libc_preinit() {
|
__attribute__((constructor)) static void __libc_preinit() {
|
||||||
// Read the kernel argument block pointer from TLS.
|
// Read the kernel argument block pointer from TLS.
|
||||||
void* tls = const_cast<void*>(__get_tls());
|
void** tls = __get_tls();
|
||||||
KernelArgumentBlock** args_slot = &reinterpret_cast<KernelArgumentBlock**>(tls)[TLS_SLOT_BIONIC_PREINIT];
|
KernelArgumentBlock** args_slot = &reinterpret_cast<KernelArgumentBlock**>(tls)[TLS_SLOT_BIONIC_PREINIT];
|
||||||
KernelArgumentBlock* args = *args_slot;
|
KernelArgumentBlock* args = *args_slot;
|
||||||
|
|
||||||
|
@ -50,6 +50,8 @@ extern "C" int __pthread_clone(void* (*fn)(void*), void* child_stack, int flags,
|
|||||||
|
|
||||||
extern "C" void ATTRIBUTES _thread_created_hook(pid_t thread_id);
|
extern "C" void ATTRIBUTES _thread_created_hook(pid_t thread_id);
|
||||||
|
|
||||||
|
extern "C" int __set_tls(void* ptr);
|
||||||
|
|
||||||
static const int kPthreadInitFailed = 1;
|
static const int kPthreadInitFailed = 1;
|
||||||
|
|
||||||
static pthread_mutex_t gPthreadStackCreationLock = PTHREAD_MUTEX_INITIALIZER;
|
static pthread_mutex_t gPthreadStackCreationLock = PTHREAD_MUTEX_INITIALIZER;
|
||||||
|
@ -64,6 +64,5 @@ __LIBC_ABI_PRIVATE__ void _pthread_internal_add(pthread_internal_t* thread) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
__LIBC_ABI_PRIVATE__ pthread_internal_t* __get_thread(void) {
|
__LIBC_ABI_PRIVATE__ pthread_internal_t* __get_thread(void) {
|
||||||
void** tls = reinterpret_cast<void**>(const_cast<void*>(__get_tls()));
|
return reinterpret_cast<pthread_internal_t*>(__get_tls()[TLS_SLOT_THREAD_ID]);
|
||||||
return reinterpret_cast<pthread_internal_t*>(tls[TLS_SLOT_THREAD_ID]);
|
|
||||||
}
|
}
|
||||||
|
@ -133,7 +133,7 @@ class ScopedTlsMapAccess {
|
|||||||
// from this thread's TLS area. This must call the destructor of all keys
|
// from this thread's TLS area. This must call the destructor of all keys
|
||||||
// that have a non-NULL data value and a non-NULL destructor.
|
// that have a non-NULL data value and a non-NULL destructor.
|
||||||
void CleanAll() {
|
void CleanAll() {
|
||||||
void** tls = (void**)__get_tls();
|
void** tls = __get_tls();
|
||||||
|
|
||||||
// Because destructors can do funky things like deleting/creating other
|
// Because destructors can do funky things like deleting/creating other
|
||||||
// keys, we need to implement this in a loop.
|
// keys, we need to implement this in a loop.
|
||||||
@ -239,8 +239,7 @@ void* pthread_getspecific(pthread_key_t key) {
|
|||||||
// to check that the key is properly allocated. If the key was not
|
// to check that the key is properly allocated. If the key was not
|
||||||
// allocated, the value read from the TLS should always be NULL
|
// allocated, the value read from the TLS should always be NULL
|
||||||
// due to pthread_key_delete() clearing the values for all threads.
|
// due to pthread_key_delete() clearing the values for all threads.
|
||||||
uintptr_t address = reinterpret_cast<volatile uintptr_t*>(__get_tls())[key];
|
return __get_tls()[key];
|
||||||
return reinterpret_cast<void*>(address);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int pthread_setspecific(pthread_key_t key, const void* ptr) {
|
int pthread_setspecific(pthread_key_t key, const void* ptr) {
|
||||||
@ -250,6 +249,6 @@ int pthread_setspecific(pthread_key_t key, const void* ptr) {
|
|||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
reinterpret_cast<volatile uintptr_t*>(__get_tls())[key] = reinterpret_cast<uintptr_t>(ptr);
|
__get_tls()[key] = const_cast<void*>(ptr);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -25,13 +25,36 @@
|
|||||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
void* __get_tls(void)
|
|
||||||
{
|
#ifndef __BIONIC_PRIVATE_GET_TLS_H_
|
||||||
register void *tls asm("v1");
|
#define __BIONIC_PRIVATE_GET_TLS_H_
|
||||||
asm (".set push\n\t"
|
|
||||||
".set mips32r2\n\t"
|
#if defined(__arm__)
|
||||||
"rdhwr %0,$29\n\t"
|
# define __get_tls() \
|
||||||
".set pop"
|
({ void** __val; \
|
||||||
: "=r"(tls));
|
__asm__("mrc p15, 0, %0, c13, c0, 3" : "=r"(__val)); \
|
||||||
return tls;
|
__val; })
|
||||||
}
|
#elif defined(__mips__)
|
||||||
|
# define __get_tls() \
|
||||||
|
/* On mips32r1, this goes via a kernel illegal instruction trap that's optimized for v1. */ \
|
||||||
|
({ register void** __val asm("v1"); \
|
||||||
|
__asm__(".set push\n" \
|
||||||
|
".set mips32r2\n" \
|
||||||
|
"rdhwr %0,$29\n" \
|
||||||
|
".set pop\n" : "=r"(__val)); \
|
||||||
|
__val; })
|
||||||
|
#elif defined(__i386__)
|
||||||
|
# define __get_tls() \
|
||||||
|
({ void** __val; \
|
||||||
|
__asm__("movl %%gs:0, %0" : "=r"(__val)); \
|
||||||
|
__val; })
|
||||||
|
#elif defined(__x86_64__)
|
||||||
|
# define __get_tls() \
|
||||||
|
({ void** __val; \
|
||||||
|
__asm__("mov %%fs:0, %0" : "=r"(__val)); \
|
||||||
|
__val; })
|
||||||
|
#else
|
||||||
|
#error unsupported architecture
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* __BIONIC_PRIVATE_GET_TLS_H_ */
|
@ -25,10 +25,12 @@
|
|||||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
#ifndef _SYS_TLS_H
|
|
||||||
#define _SYS_TLS_H
|
#ifndef __BIONIC_PRIVATE_BIONIC_TLS_H_
|
||||||
|
#define __BIONIC_PRIVATE_BIONIC_TLS_H_
|
||||||
|
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
|
#include "__get_tls.h"
|
||||||
|
|
||||||
__BEGIN_DECLS
|
__BEGIN_DECLS
|
||||||
|
|
||||||
@ -83,39 +85,6 @@ enum {
|
|||||||
#define BIONIC_ALIGN(x, a) (((x) + (a - 1)) & ~(a - 1))
|
#define BIONIC_ALIGN(x, a) (((x) + (a - 1)) & ~(a - 1))
|
||||||
#define BIONIC_TLS_SLOTS BIONIC_ALIGN(128 + TLS_SLOT_FIRST_USER_SLOT + GLOBAL_INIT_THREAD_LOCAL_BUFFER_COUNT, 4)
|
#define BIONIC_TLS_SLOTS BIONIC_ALIGN(128 + TLS_SLOT_FIRST_USER_SLOT + GLOBAL_INIT_THREAD_LOCAL_BUFFER_COUNT, 4)
|
||||||
|
|
||||||
/* syscall only, do not call directly */
|
|
||||||
extern int __set_tls(void* ptr);
|
|
||||||
|
|
||||||
/* get the TLS */
|
|
||||||
#if defined(__arm__)
|
|
||||||
# define __get_tls() \
|
|
||||||
({ unsigned int __val; \
|
|
||||||
asm ("mrc p15, 0, %0, c13, c0, 3" : "=r"(__val)); \
|
|
||||||
(volatile void*) __val; })
|
|
||||||
#elif defined(__mips__)
|
|
||||||
# define __get_tls() \
|
|
||||||
/* On mips32r1, this goes via a kernel illegal instruction trap that's optimized for v1. */ \
|
|
||||||
({ register unsigned int __val asm("v1"); \
|
|
||||||
asm (" .set push\n" \
|
|
||||||
" .set mips32r2\n" \
|
|
||||||
" rdhwr %0,$29\n" \
|
|
||||||
" .set pop\n" : "=r"(__val)); \
|
|
||||||
(volatile void*) __val; })
|
|
||||||
#elif defined(__i386__)
|
|
||||||
# define __get_tls() \
|
|
||||||
({ void* __val; \
|
|
||||||
asm ("movl %%gs:0, %0" : "=r"(__val)); \
|
|
||||||
(volatile void*) __val; })
|
|
||||||
|
|
||||||
#elif defined(__x86_64__)
|
|
||||||
# define __get_tls() \
|
|
||||||
({ void* __val; \
|
|
||||||
asm ("mov %%fs:0, %0" : "=r"(__val)); \
|
|
||||||
(volatile void*) __val; })
|
|
||||||
#else
|
|
||||||
#error unsupported architecture
|
|
||||||
#endif
|
|
||||||
|
|
||||||
__END_DECLS
|
__END_DECLS
|
||||||
|
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
@ -123,4 +92,4 @@ class KernelArgumentBlock;
|
|||||||
extern __LIBC_HIDDEN__ void __libc_init_tls(KernelArgumentBlock& args);
|
extern __LIBC_HIDDEN__ void __libc_init_tls(KernelArgumentBlock& args);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* _SYS_TLS_H */
|
#endif /* __BIONIC_PRIVATE_BIONIC_TLS_H_ */
|
||||||
|
@ -31,8 +31,7 @@
|
|||||||
static pthread_mutex_t gDlMutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER;
|
static pthread_mutex_t gDlMutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER;
|
||||||
|
|
||||||
static const char* __bionic_set_dlerror(char* new_value) {
|
static const char* __bionic_set_dlerror(char* new_value) {
|
||||||
void* tls = const_cast<void*>(__get_tls());
|
char** dlerror_slot = &reinterpret_cast<char**>(__get_tls())[TLS_SLOT_DLERROR];
|
||||||
char** dlerror_slot = &reinterpret_cast<char**>(tls)[TLS_SLOT_DLERROR];
|
|
||||||
|
|
||||||
const char* old_value = *dlerror_slot;
|
const char* old_value = *dlerror_slot;
|
||||||
*dlerror_slot = new_value;
|
*dlerror_slot = new_value;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user