blob: ff13fdb32d2e1823c3eaaf9afa23e9779b33c758 [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 Hughes2a0b8732013-10-08 18:50:24 -070033#include "__get_tls.h"
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080034
35__BEGIN_DECLS
36
37/** WARNING WARNING WARNING
38 **
39 ** This header file is *NOT* part of the public Bionic ABI/API
40 ** and should not be used/included by user-serviceable parts of
41 ** the system (e.g. applications).
42 **
43 ** It is only provided here for the benefit of the system dynamic
44 ** linker and the OpenGL sub-system (which needs to access the
45 ** pre-allocated slot directly for performance reason).
46 **/
47
Elliott Hughesad88a082012-10-24 18:37:21 -070048/* Well-known TLS slots. What data goes in which slot is arbitrary unless otherwise noted. */
Elliott Hughes44b53ad2013-02-11 20:18:47 +000049enum {
50 TLS_SLOT_SELF = 0, /* The kernel requires this specific slot for x86. */
51 TLS_SLOT_THREAD_ID,
52 TLS_SLOT_ERRNO,
Elliott Hughes3e898472013-02-12 16:40:24 +000053
Elliott Hughes877ec6d2013-11-15 17:40:18 -080054 /* This slot in the child's TLS is used to synchronize the parent and child
55 * during thread initialization. The child finishes with this mutex before
56 * running any code that can set errno, so we can reuse the errno slot. */
Elliott Hughes70b24b12013-11-15 11:51:07 -080057 TLS_SLOT_START_MUTEX = TLS_SLOT_ERRNO,
58
Elliott Hughes3e898472013-02-12 16:40:24 +000059 /* These two aren't used by bionic itself, but allow the graphics code to
60 * access TLS directly rather than using the pthread API. */
Elliott Hughes44b53ad2013-02-11 20:18:47 +000061 TLS_SLOT_OPENGL_API = 3,
62 TLS_SLOT_OPENGL = 4,
Elliott Hughes3e898472013-02-12 16:40:24 +000063
64 /* This slot is only used to pass information from the dynamic linker to
65 * libc.so when the C library is loaded in to memory. The C runtime init
66 * function will then clear it. Since its use is extremely temporary,
67 * we reuse an existing location that isn't needed during libc startup. */
68 TLS_SLOT_BIONIC_PREINIT = TLS_SLOT_OPENGL_API,
69
Elliott Hughes44b53ad2013-02-11 20:18:47 +000070 TLS_SLOT_STACK_GUARD = 5, /* GCC requires this specific slot for x86. */
71 TLS_SLOT_DLERROR,
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080072
Elliott Hughes44b53ad2013-02-11 20:18:47 +000073 TLS_SLOT_FIRST_USER_SLOT /* Must come last! */
74};
Elliott Hughes5419b942012-10-16 15:54:46 -070075
Elliott Hughes3e898472013-02-12 16:40:24 +000076/*
77 * Maximum number of elements in the TLS array.
78 * POSIX says this must be at least 128, but Android has traditionally had only 64, minus those
79 * ones used internally by bionic itself.
80 * There are two kinds of slot used internally by bionic --- there are the well-known slots
81 * enumerated above, and then there are those that are allocated during startup by calls to
82 * pthread_key_create; grep for GLOBAL_INIT_THREAD_LOCAL_BUFFER to find those. We need to manually
83 * maintain that second number, but pthread_test will fail if we forget.
David 'Digit' Turneref0bd182009-07-17 17:55:01 +020084 */
Elliott Hughes3e898472013-02-12 16:40:24 +000085#define GLOBAL_INIT_THREAD_LOCAL_BUFFER_COUNT 4
Elliott Hughesc03e1e72013-07-29 16:51:45 -070086/*
87 * This is PTHREAD_KEYS_MAX + TLS_SLOT_FIRST_USER_SLOT + GLOBAL_INIT_THREAD_LOCAL_BUFFER_COUNT
88 * rounded up to maintain stack alignment.
89 */
90#define BIONIC_ALIGN(x, a) (((x) + (a - 1)) & ~(a - 1))
91#define BIONIC_TLS_SLOTS BIONIC_ALIGN(128 + TLS_SLOT_FIRST_USER_SLOT + GLOBAL_INIT_THREAD_LOCAL_BUFFER_COUNT, 4)
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080092
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080093__END_DECLS
94
Elliott Hughesd3920b32013-02-07 18:39:34 -080095#if defined(__cplusplus)
Bernhard Rosenkraenzeredad1e12013-09-18 23:37:00 +020096class KernelArgumentBlock;
Elliott Hughesce532722013-03-15 16:31:09 -070097extern __LIBC_HIDDEN__ void __libc_init_tls(KernelArgumentBlock& args);
Elliott Hughesd3920b32013-02-07 18:39:34 -080098#endif
99
Elliott Hughes2a0b8732013-10-08 18:50:24 -0700100#endif /* __BIONIC_PRIVATE_BIONIC_TLS_H_ */