blob: 724f8965d140ebb1f5078080319aa79cc3a148cc [file] [log] [blame]
The Android Open Source Project1dc9e472009-03-03 19:28:35 -08001/*
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 */
Elliott Hughes2a0b8732013-10-08 18:50:24 -070028
29#ifndef __BIONIC_PRIVATE_BIONIC_TLS_H_
30#define __BIONIC_PRIVATE_BIONIC_TLS_H_
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080031
32#include <sys/cdefs.h>
Elliott Hughes18876212013-12-12 11:02:41 -080033#include <sys/limits.h>
Christopher Ferris03eebcb2014-06-13 13:57:51 -070034#include "bionic_macros.h"
Elliott Hughes2a0b8732013-10-08 18:50:24 -070035#include "__get_tls.h"
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080036
37__BEGIN_DECLS
38
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 **/
49
Elliott Hughesb30aff42014-05-28 19:35:33 +000050// Well-known TLS slots. What data goes in which slot is arbitrary unless otherwise noted.
Elliott Hughes44b53ad2013-02-11 20:18:47 +000051enum {
Elliott Hughesb30aff42014-05-28 19:35:33 +000052 TLS_SLOT_SELF = 0, // The kernel requires this specific slot for x86.
Elliott Hughes44b53ad2013-02-11 20:18:47 +000053 TLS_SLOT_THREAD_ID,
54 TLS_SLOT_ERRNO,
Elliott Hughes3e898472013-02-12 16:40:24 +000055
Elliott Hughesb30aff42014-05-28 19:35:33 +000056 // These two aren't used by bionic itself, but allow the graphics code to
57 // access TLS directly rather than using the pthread API.
Elliott Hughes44b53ad2013-02-11 20:18:47 +000058 TLS_SLOT_OPENGL_API = 3,
59 TLS_SLOT_OPENGL = 4,
Elliott Hughes3e898472013-02-12 16:40:24 +000060
Elliott Hughesb30aff42014-05-28 19:35:33 +000061 // 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.
Elliott Hughes3e898472013-02-12 16:40:24 +000065 TLS_SLOT_BIONIC_PREINIT = TLS_SLOT_OPENGL_API,
66
Elliott Hughesb30aff42014-05-28 19:35:33 +000067 TLS_SLOT_STACK_GUARD = 5, // GCC requires this specific slot for x86.
Elliott Hughes44b53ad2013-02-11 20:18:47 +000068 TLS_SLOT_DLERROR,
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080069
Yabin Cui5e2bd712015-02-20 16:15:33 -080070 BIONIC_TLS_SLOTS // Must come last!
Elliott Hughes44b53ad2013-02-11 20:18:47 +000071};
Elliott Hughes5419b942012-10-16 15:54:46 -070072
Elliott Hughes3e898472013-02-12 16:40:24 +000073/*
Yabin Cui5e2bd712015-02-20 16:15:33 -080074 * Bionic uses some pthread keys internally. All pthread keys used internally
75 * should be created in constructors.
76 * We need to manually maintain the count of pthread keys used internally, but
77 * pthread_test should fail if we forget.
78 * Following are current pthread keys used internally by libc:
Yabin Cui6c238f22014-12-11 20:50:41 -080079 * basename libc (GLOBAL_INIT_THREAD_LOCAL_BUFFER)
80 * dirname libc (GLOBAL_INIT_THREAD_LOCAL_BUFFER)
Yabin Cui4a2891d2015-03-04 16:53:23 -080081 * uselocale libc (BIONIC_PTHREAD_KEY_WITH_CONSTRUCTOR)
Yabin Cui6c238f22014-12-11 20:50:41 -080082 * 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)
Elliott Hughes7874f1d2014-12-18 13:36:25 -080088 * passwd libc (GLOBAL_INIT_THREAD_LOCAL_BUFFER)
89 * group libc (GLOBAL_INIT_THREAD_LOCAL_BUFFER)
Yabin Cui4a2891d2015-03-04 16:53:23 -080090 * _res_key libc (BIONIC_PTHREAD_KEY_WITH_CONSTRUCTOR)
Yabin Cui5e2bd712015-02-20 16:15:33 -080091 */
92
93#define LIBC_PTHREAD_KEY_RESERVED_COUNT 12
94
95#if defined(USE_JEMALLOC)
96/* Following are current pthread keys used internally by jemalloc:
Yabin Cui6c238f22014-12-11 20:50:41 -080097 * je_thread_allocated_tsd jemalloc
98 * je_arenas_tsd jemalloc
99 * je_tcache_tsd jemalloc
100 * je_tcache_enabled_tsd jemalloc
101 * je_quarantine_tsd jemalloc
David 'Digit' Turneref0bd182009-07-17 17:55:01 +0200102 */
Yabin Cui5e2bd712015-02-20 16:15:33 -0800103#define JEMALLOC_PTHREAD_KEY_RESERVED_COUNT 5
104#define BIONIC_PTHREAD_KEY_RESERVED_COUNT (LIBC_PTHREAD_KEY_RESERVED_COUNT + JEMALLOC_PTHREAD_KEY_RESERVED_COUNT)
Christopher Ferris72bbd422014-05-08 11:14:03 -0700105#else
Yabin Cui5e2bd712015-02-20 16:15:33 -0800106#define BIONIC_PTHREAD_KEY_RESERVED_COUNT LIBC_PTHREAD_KEY_RESERVED_COUNT
Christopher Ferris72bbd422014-05-08 11:14:03 -0700107#endif
108
Elliott Hughes18876212013-12-12 11:02:41 -0800109/*
Yabin Cui5e2bd712015-02-20 16:15:33 -0800110 * Maximum number of pthread keys allocated.
111 * This includes pthread keys used internally and externally.
Elliott Hughes18876212013-12-12 11:02:41 -0800112 */
Yabin Cui5e2bd712015-02-20 16:15:33 -0800113#define BIONIC_PTHREAD_KEY_COUNT (BIONIC_PTHREAD_KEY_RESERVED_COUNT + PTHREAD_KEYS_MAX)
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800114
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800115__END_DECLS
116
Elliott Hughesd3920b32013-02-07 18:39:34 -0800117#if defined(__cplusplus)
Bernhard Rosenkraenzeredad1e12013-09-18 23:37:00 +0200118class KernelArgumentBlock;
Elliott Hughesce532722013-03-15 16:31:09 -0700119extern __LIBC_HIDDEN__ void __libc_init_tls(KernelArgumentBlock& args);
Elliott Hughesd3920b32013-02-07 18:39:34 -0800120#endif
121
Elliott Hughes2a0b8732013-10-08 18:50:24 -0700122#endif /* __BIONIC_PRIVATE_BIONIC_TLS_H_ */