blob: d59f1c36ba6fdbd635ccaf7a59da0c33bdf6852d [file] [log] [blame]
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -07001/*
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 */
28#ifndef _SYS_TLS_H
29#define _SYS_TLS_H
30
31#include <sys/cdefs.h>
32
33__BEGIN_DECLS
34
35/* maximum number of elements in the TLS array */
36#define BIONIC_TLS_SLOTS 64
37
38/* note that slot 0, called TLS_SLOT_SELF must point to itself.
39 * this is required to implement thread-local storage with the x86
40 * Linux kernel, that reads the TLS from fs:[0], where 'fs' is a
41 * thread-specific segment descriptor...
42 */
43
44/* Well known TLS slots */
45#define TLS_SLOT_SELF 0
46#define TLS_SLOT_THREAD_ID 1
47#define TLS_SLOT_ERRNO 2
48
49#define TLS_SLOT_OPENGL_API 3
50#define TLS_SLOT_OPENGL 4
51
52/* small technical note: it is not possible to call pthread_setspecific
53 * on keys that are <= TLS_SLOT_MAX_WELL_KNOWN, which is why it is set to
54 * TLS_SLOT_ERRNO.
55 *
56 * later slots like TLS_SLOT_OPENGL are pre-allocated through the use of
57 * TLS_DEFAULT_ALLOC_MAP. this means that there is no need to use
58 * pthread_key_create() to initialize them. on the other hand, there is
59 * no destructor associated to them (we might need to implement this later)
60 */
61#define TLS_SLOT_MAX_WELL_KNOWN TLS_SLOT_ERRNO
62
63#define TLS_DEFAULT_ALLOC_MAP 0x0000001F
64
65/* set the Thread Local Storage, must contain at least BIONIC_TLS_SLOTS pointers */
66extern void __init_tls(void** tls, void* thread_info);
67
68/* syscall only, do not call directly */
69extern int __set_tls(void *ptr);
70
71/* get the TLS */
72#ifdef __arm__
73# define __get_tls() ( *((volatile void **) 0xffff0ff0) )
74#else
75extern void* __get_tls( void );
76#endif
77
78/* return the stack base and size, used by our malloc debugger */
79extern void* __get_stack_base(int *p_stack_size);
80
81__END_DECLS
82
83#endif /* _SYS_TLS_H */