blob: 93f5e9f578ebc1d0ff9a9b484137b0e8d619aa08 [file] [log] [blame]
Vy Nguyend5007512020-07-14 17:37:04 -04001/*
2 * Copyright (C) 2019 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// Prevent tests from being compiled with glibc because thread_properties.h
30// only exists in Bionic.
31#if defined(__BIONIC__)
32
33#include <sys/thread_properties.h>
34
35#include <dlfcn.h>
36#include <stdio.h>
37#include <unistd.h> // for gettid
38
39// Helper binary to use TLS-related functions in thread_properties
40
41// Tests __get_static_tls_bound.
42void test_static_tls_bounds() {
43 void* start_addr;
44 void* end_addr;
45
46 __libc_get_static_tls_bounds(reinterpret_cast<void**>(&start_addr),
47 reinterpret_cast<void**>(&end_addr));
48 printf("done_get_static_tls_bounds\n");
49}
50
51// Tests iterate_dynamic tls chunks.
52// Export a var from the shared so.
53__thread char large_tls_var[4 * 1024 * 1024];
54void test_iter_tls() {
55 void* lib = dlopen("libtest_elftls_dynamic.so", RTLD_LOCAL | RTLD_NOW);
56
57 int i = 0;
58 auto cb = [&](void* dtls_begin, void* dtls_end, size_t dso_id, void* arg) {
59 printf("iterate_cb i = %d\n", i++);
60 };
61 __libc_iterate_dynamic_tls(gettid(), cb, nullptr);
62 printf("done_iterate_dynamic_tls\n");
63}
64
65int main() {
66 test_static_tls_bounds();
67 test_iter_tls();
68 return 0;
69}
70
71#else
72int main() {
73 return 0;
74}
75#endif // __BIONIC__