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.
|
|
|
|
*/
|
2013-10-09 03:50:24 +02:00
|
|
|
|
|
|
|
#ifndef __BIONIC_PRIVATE_BIONIC_TLS_H_
|
|
|
|
#define __BIONIC_PRIVATE_BIONIC_TLS_H_
|
2009-03-04 04:28:35 +01:00
|
|
|
|
2017-02-22 21:19:05 +01:00
|
|
|
#include <locale.h>
|
|
|
|
#include <mntent.h>
|
|
|
|
#include <stdio.h>
|
2009-03-04 04:28:35 +01:00
|
|
|
#include <sys/cdefs.h>
|
2017-02-22 21:19:05 +01:00
|
|
|
#include <sys/param.h>
|
2016-03-04 20:53:09 +01:00
|
|
|
|
2014-06-13 22:57:51 +02:00
|
|
|
#include "bionic_macros.h"
|
2013-10-09 03:50:24 +02:00
|
|
|
#include "__get_tls.h"
|
2017-02-22 21:19:05 +01:00
|
|
|
#include "grp_pwd.h"
|
2009-03-04 04:28:35 +01:00
|
|
|
|
|
|
|
__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).
|
|
|
|
**/
|
|
|
|
|
2014-05-28 21:35:33 +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 {
|
2014-05-28 21:35:33 +02:00
|
|
|
TLS_SLOT_SELF = 0, // The kernel requires this specific slot for x86.
|
2013-02-11 21:18:47 +01:00
|
|
|
TLS_SLOT_THREAD_ID,
|
|
|
|
TLS_SLOT_ERRNO,
|
2013-02-12 17:40:24 +01:00
|
|
|
|
2014-05-28 21:35:33 +02: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
|
|
|
|
2014-05-28 21:35:33 +02: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.
|
2013-02-12 17:40:24 +01:00
|
|
|
TLS_SLOT_BIONIC_PREINIT = TLS_SLOT_OPENGL_API,
|
|
|
|
|
2014-05-28 21:35:33 +02:00
|
|
|
TLS_SLOT_STACK_GUARD = 5, // GCC requires this specific slot for x86.
|
2013-02-11 21:18:47 +01:00
|
|
|
TLS_SLOT_DLERROR,
|
2009-03-04 04:28:35 +01:00
|
|
|
|
2015-07-29 04:53:54 +02:00
|
|
|
// Fast storage for Thread::Current() in ART.
|
|
|
|
TLS_SLOT_ART_THREAD_SELF,
|
|
|
|
|
2015-08-19 00:09:00 +02:00
|
|
|
// Lets TSAN avoid using pthread_getspecific for finding the current thread
|
|
|
|
// state.
|
|
|
|
TLS_SLOT_TSAN,
|
|
|
|
|
2015-02-21 01:15:33 +01:00
|
|
|
BIONIC_TLS_SLOTS // Must come last!
|
2013-02-11 21:18:47 +01:00
|
|
|
};
|
2012-10-17 00:54:46 +02:00
|
|
|
|
2017-02-22 21:19:05 +01:00
|
|
|
// ~3 pages.
|
|
|
|
struct bionic_tls {
|
|
|
|
locale_t locale;
|
|
|
|
|
|
|
|
char basename_buf[MAXPATHLEN];
|
|
|
|
char dirname_buf[MAXPATHLEN];
|
|
|
|
|
|
|
|
mntent mntent_buf;
|
|
|
|
char mntent_strings[BUFSIZ];
|
|
|
|
|
|
|
|
char ptsname_buf[32];
|
|
|
|
char ttyname_buf[64];
|
|
|
|
|
|
|
|
char strerror_buf[NL_TEXTMAX];
|
|
|
|
char strsignal_buf[NL_TEXTMAX];
|
|
|
|
|
|
|
|
group_state_t group;
|
|
|
|
passwd_state_t passwd;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define BIONIC_TLS_SIZE (BIONIC_ALIGN(sizeof(bionic_tls), PAGE_SIZE))
|
|
|
|
|
2013-02-12 17:40:24 +01:00
|
|
|
/*
|
2015-02-21 01:15:33 +01:00
|
|
|
* Bionic uses some pthread keys internally. All pthread keys used internally
|
2015-03-31 19:56:58 +02:00
|
|
|
* should be created in constructors, except for keys that may be used in or
|
|
|
|
* before constructors.
|
|
|
|
*
|
2015-02-21 01:15:33 +01:00
|
|
|
* We need to manually maintain the count of pthread keys used internally, but
|
|
|
|
* pthread_test should fail if we forget.
|
2015-03-31 19:56:58 +02:00
|
|
|
*
|
|
|
|
* These are the pthread keys currently used internally by libc:
|
|
|
|
* _res_key libc (constructor in BSD code)
|
2015-02-21 01:15:33 +01:00
|
|
|
*/
|
|
|
|
|
2017-02-22 21:19:05 +01:00
|
|
|
#define LIBC_PTHREAD_KEY_RESERVED_COUNT 1
|
2015-02-21 01:15:33 +01:00
|
|
|
|
2015-04-16 01:34:57 +02:00
|
|
|
/* Internally, jemalloc uses a single key for per thread data. */
|
|
|
|
#define JEMALLOC_PTHREAD_KEY_RESERVED_COUNT 1
|
2015-02-21 01:15:33 +01:00
|
|
|
#define BIONIC_PTHREAD_KEY_RESERVED_COUNT (LIBC_PTHREAD_KEY_RESERVED_COUNT + JEMALLOC_PTHREAD_KEY_RESERVED_COUNT)
|
2014-05-08 20:14:03 +02:00
|
|
|
|
2013-07-30 01:51:45 +02:00
|
|
|
/*
|
2015-02-21 01:15:33 +01:00
|
|
|
* Maximum number of pthread keys allocated.
|
|
|
|
* This includes pthread keys used internally and externally.
|
2013-07-30 01:51:45 +02:00
|
|
|
*/
|
2015-02-21 01:15:33 +01:00
|
|
|
#define BIONIC_PTHREAD_KEY_COUNT (BIONIC_PTHREAD_KEY_RESERVED_COUNT + PTHREAD_KEYS_MAX)
|
2009-03-04 04:28:35 +01:00
|
|
|
|
|
|
|
__END_DECLS
|
|
|
|
|
2013-02-08 03:39:34 +01:00
|
|
|
#if defined(__cplusplus)
|
2013-09-18 23:37:00 +02:00
|
|
|
class KernelArgumentBlock;
|
2016-03-04 20:53:09 +01:00
|
|
|
extern void __libc_init_main_thread(KernelArgumentBlock&);
|
2013-02-08 03:39:34 +01:00
|
|
|
#endif
|
|
|
|
|
2013-10-09 03:50:24 +02:00
|
|
|
#endif /* __BIONIC_PRIVATE_BIONIC_TLS_H_ */
|