Vy Nguyen | d500751 | 2020-07-14 17:37:04 -0400 | [diff] [blame] | 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 | */ |
zijunzhao | 70586d6 | 2023-06-02 00:41:29 +0000 | [diff] [blame^] | 53 | void __libc_get_static_tls_bounds(void* _Nonnull * _Nonnull __static_tls_begin, |
| 54 | void* _Nonnull * _Nonnull __static_tls_end) __INTRODUCED_IN(31); |
Vy Nguyen | d500751 | 2020-07-14 17:37:04 -0400 | [diff] [blame] | 55 | |
| 56 | |
| 57 | /** |
| 58 | * Registers callback to be called right before the thread is dead. |
| 59 | * The callbacks are chained, they are called in the order opposite to the order |
| 60 | * they were registered. |
| 61 | * |
| 62 | * The callbacks must be registered only before any threads were created. |
| 63 | * No signals may arrive during the calls to these callbacks. |
| 64 | * The callbacks may not access the thread's dynamic TLS because they will have |
| 65 | * been freed by the time these callbacks are invoked. |
| 66 | * |
| 67 | * Available since API level 31. |
| 68 | */ |
zijunzhao | 70586d6 | 2023-06-02 00:41:29 +0000 | [diff] [blame^] | 69 | void __libc_register_thread_exit_callback(void (* _Nonnull __cb)(void)) __INTRODUCED_IN(31); |
Vy Nguyen | d500751 | 2020-07-14 17:37:04 -0400 | [diff] [blame] | 70 | |
| 71 | /** |
| 72 | * Iterates over all dynamic TLS chunks for the given thread. |
| 73 | * The thread should have been suspended. It is undefined-behaviour if there is concurrent |
| 74 | * modification of the target thread's dynamic TLS. |
| 75 | * |
| 76 | * Available since API level 31. |
| 77 | */ |
| 78 | void __libc_iterate_dynamic_tls(pid_t __tid, |
zijunzhao | 70586d6 | 2023-06-02 00:41:29 +0000 | [diff] [blame^] | 79 | void (* _Nonnull __cb)(void* _Nonnull __dynamic_tls_begin, |
| 80 | void* _Nonnull __dynamic_tls_end, |
Vy Nguyen | d500751 | 2020-07-14 17:37:04 -0400 | [diff] [blame] | 81 | size_t __dso_id, |
zijunzhao | 70586d6 | 2023-06-02 00:41:29 +0000 | [diff] [blame^] | 82 | void* _Nullable __arg), |
| 83 | void* _Nullable __arg) __INTRODUCED_IN(31); |
Vy Nguyen | d500751 | 2020-07-14 17:37:04 -0400 | [diff] [blame] | 84 | |
| 85 | /** |
| 86 | * Register on_creation and on_destruction callbacks, which will be called after a dynamic |
| 87 | * TLS creation and before a dynamic TLS destruction, respectively. |
| 88 | * |
| 89 | * Available since API level 31. |
| 90 | */ |
| 91 | void __libc_register_dynamic_tls_listeners( |
zijunzhao | 70586d6 | 2023-06-02 00:41:29 +0000 | [diff] [blame^] | 92 | void (* _Nonnull __on_creation)(void* _Nonnull __dynamic_tls_begin, |
| 93 | void* _Nonnull __dynamic_tls_end), |
| 94 | void (* _Nonnull __on_destruction)(void* _Nonnull __dynamic_tls_begin, |
| 95 | void* _Nonnull __dynamic_tls_end)) __INTRODUCED_IN(31); |
Vy Nguyen | d500751 | 2020-07-14 17:37:04 -0400 | [diff] [blame] | 96 | |
| 97 | __END_DECLS |