2009-03-04 04:28:35 +01:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
#ifndef _SYS_TLS_H
|
|
|
|
#define _SYS_TLS_H
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
|
|
|
|
__BEGIN_DECLS
|
|
|
|
|
|
|
|
/** WARNING WARNING WARNING
|
|
|
|
**
|
|
|
|
** This header file is *NOT* part of the public Bionic ABI/API
|
|
|
|
** and should not be used/included by user-serviceable parts of
|
|
|
|
** the system (e.g. applications).
|
|
|
|
**
|
|
|
|
** It is only provided here for the benefit of the system dynamic
|
|
|
|
** linker and the OpenGL sub-system (which needs to access the
|
|
|
|
** pre-allocated slot directly for performance reason).
|
|
|
|
**/
|
|
|
|
|
2012-10-25 03:37:21 +02:00
|
|
|
/* Well-known TLS slots. What data goes in which slot is arbitrary unless otherwise noted. */
|
2013-02-11 21:18:47 +01:00
|
|
|
enum {
|
|
|
|
TLS_SLOT_SELF = 0, /* The kernel requires this specific slot for x86. */
|
|
|
|
TLS_SLOT_THREAD_ID,
|
|
|
|
TLS_SLOT_ERRNO,
|
2013-02-12 17:40:24 +01:00
|
|
|
|
|
|
|
/* These two aren't used by bionic itself, but allow the graphics code to
|
|
|
|
* access TLS directly rather than using the pthread API. */
|
2013-02-11 21:18:47 +01:00
|
|
|
TLS_SLOT_OPENGL_API = 3,
|
|
|
|
TLS_SLOT_OPENGL = 4,
|
2013-02-12 17:40:24 +01:00
|
|
|
|
|
|
|
/* This slot is only used to pass information from the dynamic linker to
|
|
|
|
* libc.so when the C library is loaded in to memory. The C runtime init
|
|
|
|
* function will then clear it. Since its use is extremely temporary,
|
|
|
|
* we reuse an existing location that isn't needed during libc startup. */
|
|
|
|
TLS_SLOT_BIONIC_PREINIT = TLS_SLOT_OPENGL_API,
|
|
|
|
|
2013-02-11 21:18:47 +01:00
|
|
|
TLS_SLOT_STACK_GUARD = 5, /* GCC requires this specific slot for x86. */
|
|
|
|
TLS_SLOT_DLERROR,
|
2009-03-04 04:28:35 +01:00
|
|
|
|
2013-02-11 21:18:47 +01:00
|
|
|
TLS_SLOT_FIRST_USER_SLOT /* Must come last! */
|
|
|
|
};
|
2012-10-17 00:54:46 +02:00
|
|
|
|
2013-02-12 17:40:24 +01:00
|
|
|
/*
|
|
|
|
* Maximum number of elements in the TLS array.
|
|
|
|
* POSIX says this must be at least 128, but Android has traditionally had only 64, minus those
|
|
|
|
* ones used internally by bionic itself.
|
|
|
|
* There are two kinds of slot used internally by bionic --- there are the well-known slots
|
|
|
|
* enumerated above, and then there are those that are allocated during startup by calls to
|
|
|
|
* pthread_key_create; grep for GLOBAL_INIT_THREAD_LOCAL_BUFFER to find those. We need to manually
|
|
|
|
* maintain that second number, but pthread_test will fail if we forget.
|
2009-07-17 17:55:01 +02:00
|
|
|
*/
|
2013-02-12 17:40:24 +01:00
|
|
|
#define GLOBAL_INIT_THREAD_LOCAL_BUFFER_COUNT 4
|
|
|
|
#define BIONIC_TLS_SLOTS 64
|
2009-03-04 04:28:35 +01:00
|
|
|
|
|
|
|
/* syscall only, do not call directly */
|
2013-02-13 06:56:42 +01:00
|
|
|
extern int __set_tls(void* ptr);
|
2009-03-04 04:28:35 +01:00
|
|
|
|
|
|
|
/* get the TLS */
|
2013-02-13 06:56:42 +01:00
|
|
|
#if defined(__arm__)
|
|
|
|
# define __get_tls() \
|
2009-09-18 22:35:05 +02:00
|
|
|
({ register unsigned int __val asm("r0"); \
|
|
|
|
asm ("mrc p15, 0, r0, c13, c0, 3" : "=r"(__val) ); \
|
|
|
|
(volatile void*)__val; })
|
2012-08-03 02:47:37 +02:00
|
|
|
#elif defined(__mips__)
|
2013-02-13 06:56:42 +01:00
|
|
|
# define __get_tls() \
|
2012-08-03 02:47:37 +02:00
|
|
|
({ 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; })
|
2013-02-13 06:56:42 +01:00
|
|
|
#elif defined(__i386__)
|
|
|
|
# define __get_tls() \
|
|
|
|
({ register void* __val; \
|
|
|
|
asm ("movl %%gs:0, %0" : "=r"(__val)); \
|
|
|
|
(volatile void*) __val; })
|
2012-08-03 02:47:37 +02:00
|
|
|
#else
|
2013-02-13 06:56:42 +01:00
|
|
|
#error unsupported architecture
|
2012-08-03 02:47:37 +02:00
|
|
|
#endif
|
2009-03-04 04:28:35 +01:00
|
|
|
|
|
|
|
/* return the stack base and size, used by our malloc debugger */
|
2013-02-13 06:56:42 +01:00
|
|
|
extern void* __get_stack_base(int* p_stack_size);
|
2009-03-04 04:28:35 +01:00
|
|
|
|
|
|
|
__END_DECLS
|
|
|
|
|
2013-02-08 03:39:34 +01:00
|
|
|
#if defined(__cplusplus)
|
|
|
|
struct KernelArgumentBlock;
|
|
|
|
extern void __libc_init_tls(KernelArgumentBlock& args);
|
|
|
|
#endif
|
|
|
|
|
2009-03-04 04:28:35 +01:00
|
|
|
#endif /* _SYS_TLS_H */
|