xref: /aosp_15_r20/bionic/libc/include/sys/thread_properties.h (revision 8d67ca893c1523eb926b9080dbe4e2ffd2a27ba1)
1 /*
2  * Copyright (C) 2020 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 
29 #pragma once
30 
31 /**
32  * @file thread_properties.h
33  * @brief Thread properties API.
34  *
35  * https://sourceware.org/glibc/wiki/ThreadPropertiesAPI
36  * API for querying various properties of the current thread, used mostly by
37  * the sanitizers.
38  *
39  * Available since API level 31.
40  *
41  */
42 
43 #include <sys/cdefs.h>
44 #include <unistd.h>
45 
46 __BEGIN_DECLS
47 
48 /**
49  * Gets the bounds of static TLS for the current thread.
50  *
51  * Available since API level 31.
52  */
53 
54 #if __BIONIC_AVAILABILITY_GUARD(31)
55 void __libc_get_static_tls_bounds(void* _Nonnull * _Nonnull __static_tls_begin,
56                                   void* _Nonnull * _Nonnull __static_tls_end) __INTRODUCED_IN(31);
57 
58 
59 /**
60  * Registers callback to be called right before the thread is dead.
61  * The callbacks are chained, they are called in the order opposite to the order
62  * they were registered.
63  *
64  * The callbacks must be registered only before any threads were created.
65  * No signals may arrive during the calls to these callbacks.
66  * The callbacks may not access the thread's dynamic TLS because they will have
67  * been freed by the time these callbacks are invoked.
68  *
69  * Available since API level 31.
70  */
71 void __libc_register_thread_exit_callback(void (* _Nonnull __cb)(void)) __INTRODUCED_IN(31);
72 
73 /**
74  * Iterates over all dynamic TLS chunks for the given thread.
75  * The thread should have been suspended. It is undefined-behaviour if there is concurrent
76  * modification of the target thread's dynamic TLS.
77  *
78  * Available since API level 31.
79  */
80 void __libc_iterate_dynamic_tls(pid_t __tid,
81                                 void (* _Nonnull __cb)(void* _Nonnull __dynamic_tls_begin,
82                                              void* _Nonnull __dynamic_tls_end,
83                                              size_t __dso_id,
84                                              void* _Nullable __arg),
85                                 void* _Nullable __arg) __INTRODUCED_IN(31);
86 
87 /**
88  * Register on_creation and on_destruction callbacks, which will be called after a dynamic
89  * TLS creation and before a dynamic TLS destruction, respectively.
90  *
91  * Available since API level 31.
92  */
93 void __libc_register_dynamic_tls_listeners(
94     void (* _Nonnull __on_creation)(void* _Nonnull __dynamic_tls_begin,
95                           void* _Nonnull __dynamic_tls_end),
96     void (* _Nonnull __on_destruction)(void* _Nonnull __dynamic_tls_begin,
97                              void* _Nonnull __dynamic_tls_end)) __INTRODUCED_IN(31);
98 #endif /* __BIONIC_AVAILABILITY_GUARD(31) */
99 
100 
101 __END_DECLS
102