]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - android-sdk/platform-bionic.git/blob - libc/private/bionic_tls.h
Ensure <fcntl.h> defines the S_* constants from <sys/stat.h>.
[android-sdk/platform-bionic.git] / libc / private / bionic_tls.h
1 /*
2  * Copyright (C) 2008 The Android Open Source Project
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *  * Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  *  * Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in
12  *    the documentation and/or other materials provided with the
13  *    distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  */
29 #ifndef __BIONIC_PRIVATE_BIONIC_TLS_H_
30 #define __BIONIC_PRIVATE_BIONIC_TLS_H_
32 #include <sys/cdefs.h>
33 #include <sys/limits.h>
34 #include "bionic_macros.h"
35 #include "__get_tls.h"
37 __BEGIN_DECLS
39 /** WARNING WARNING WARNING
40  **
41  ** This header file is *NOT* part of the public Bionic ABI/API
42  ** and should not be used/included by user-serviceable parts of
43  ** the system (e.g. applications).
44  **
45  ** It is only provided here for the benefit of the system dynamic
46  ** linker and the OpenGL sub-system (which needs to access the
47  ** pre-allocated slot directly for performance reason).
48  **/
50 // Well-known TLS slots. What data goes in which slot is arbitrary unless otherwise noted.
51 enum {
52   TLS_SLOT_SELF = 0, // The kernel requires this specific slot for x86.
53   TLS_SLOT_THREAD_ID,
54   TLS_SLOT_ERRNO,
56   // These two aren't used by bionic itself, but allow the graphics code to
57   // access TLS directly rather than using the pthread API.
58   TLS_SLOT_OPENGL_API = 3,
59   TLS_SLOT_OPENGL = 4,
61   // This slot is only used to pass information from the dynamic linker to
62   // libc.so when the C library is loaded in to memory. The C runtime init
63   // function will then clear it. Since its use is extremely temporary,
64   // we reuse an existing location that isn't needed during libc startup.
65   TLS_SLOT_BIONIC_PREINIT = TLS_SLOT_OPENGL_API,
67   TLS_SLOT_STACK_GUARD = 5, // GCC requires this specific slot for x86.
68   TLS_SLOT_DLERROR,
70   TLS_SLOT_FIRST_USER_SLOT // Must come last!
71 };
73 /*
74  * There are two kinds of slot used internally by bionic --- there are the well-known slots
75  * enumerated above, and then there are those that are allocated during startup by calls to
76  * pthread_key_create; grep for GLOBAL_INIT_THREAD_LOCAL_BUFFER to find those. We need to manually
77  * maintain that second number, but pthread_test will fail if we forget.
78  * Following are current pthread keys used internally:
79  *  basename               libc (GLOBAL_INIT_THREAD_LOCAL_BUFFER)
80  *  dirname                libc (GLOBAL_INIT_THREAD_LOCAL_BUFFER)
81  *  uselocale              libc
82  *  getmntent_mntent       libc (GLOBAL_INIT_THREAD_LOCAL_BUFFER)
83  *  getmntent_strings      libc (GLOBAL_INIT_THREAD_LOCAL_BUFFER)
84  *  ptsname                libc (GLOBAL_INIT_THREAD_LOCAL_BUFFER)
85  *  ttyname                libc (GLOBAL_INIT_THREAD_LOCAL_BUFFER)
86  *  strerror               libc (GLOBAL_INIT_THREAD_LOCAL_BUFFER)
87  *  strsignal              libc (GLOBAL_INIT_THREAD_LOCAL_BUFFER)
88  *  stubs                  libc (GLOBAL_INIT_THREAD_LOCAL_BUFFER)
89  *  _res_key               libc
90  * je_thread_allocated_tsd jemalloc
91  * je_arenas_tsd           jemalloc
92  * je_tcache_tsd           jemalloc
93  * je_tcache_enabled_tsd   jemalloc
94  * je_quarantine_tsd       jemalloc
95  *
96  */
98 #define LIBC_TLS_RESERVED_SLOTS 11
100 #if defined(USE_JEMALLOC)
101 /* jemalloc uses 5 keys for itself. */
102 #define BIONIC_TLS_RESERVED_SLOTS (LIBC_TLS_RESERVED_SLOTS + 5)
103 #else
104 #define BIONIC_TLS_RESERVED_SLOTS LIBC_TLS_RESERVED_SLOTS
105 #endif
107 /*
108  * Maximum number of elements in the TLS array.
109  * This includes space for pthread keys and our own internal slots.
110  */
111 #define BIONIC_TLS_SLOTS (PTHREAD_KEYS_MAX + TLS_SLOT_FIRST_USER_SLOT + BIONIC_TLS_RESERVED_SLOTS)
113 __END_DECLS
115 #if defined(__cplusplus)
116 class KernelArgumentBlock;
117 extern __LIBC_HIDDEN__ void __libc_init_tls(KernelArgumentBlock& args);
118 #endif
120 #endif /* __BIONIC_PRIVATE_BIONIC_TLS_H_ */