blob: b6214ee686a18783157c7cd9b8e8789100464022 [file] [log] [blame]
Vy Nguyend5007512020-07-14 17:37:04 -04001/*
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 */
Dan Albert02ce4012024-10-25 19:13:49 +000053
54#if __BIONIC_AVAILABILITY_GUARD(31)
zijunzhao70586d62023-06-02 00:41:29 +000055void __libc_get_static_tls_bounds(void* _Nonnull * _Nonnull __static_tls_begin,
56 void* _Nonnull * _Nonnull __static_tls_end) __INTRODUCED_IN(31);
Vy Nguyend5007512020-07-14 17:37:04 -040057
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 */
zijunzhao70586d62023-06-02 00:41:29 +000071void __libc_register_thread_exit_callback(void (* _Nonnull __cb)(void)) __INTRODUCED_IN(31);
Vy Nguyend5007512020-07-14 17:37:04 -040072
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 */
80void __libc_iterate_dynamic_tls(pid_t __tid,
zijunzhao70586d62023-06-02 00:41:29 +000081 void (* _Nonnull __cb)(void* _Nonnull __dynamic_tls_begin,
82 void* _Nonnull __dynamic_tls_end,
Vy Nguyend5007512020-07-14 17:37:04 -040083 size_t __dso_id,
zijunzhao70586d62023-06-02 00:41:29 +000084 void* _Nullable __arg),
85 void* _Nullable __arg) __INTRODUCED_IN(31);
Vy Nguyend5007512020-07-14 17:37:04 -040086
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 */
93void __libc_register_dynamic_tls_listeners(
zijunzhao70586d62023-06-02 00:41:29 +000094 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);
Dan Albert02ce4012024-10-25 19:13:49 +000098#endif /* __BIONIC_AVAILABILITY_GUARD(31) */
99
Vy Nguyend5007512020-07-14 17:37:04 -0400100
101__END_DECLS