Vy Nguyen | d500751 | 2020-07-14 17:37:04 -0400 | [diff] [blame] | 1 | /* |
| 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 <stdio.h> |
| 34 | #include <sys/thread_properties.h> |
| 35 | |
| 36 | // Helper binary for testing thread_exit_cb registration. |
| 37 | |
| 38 | void exit_cb_1() { |
| 39 | printf("exit_cb_1 called "); |
| 40 | } |
| 41 | |
| 42 | void exit_cb_2() { |
| 43 | printf("exit_cb_2 called "); |
| 44 | } |
| 45 | |
| 46 | void exit_cb_3() { |
| 47 | printf("exit_cb_3 called"); |
| 48 | } |
| 49 | |
| 50 | void test_register_thread_exit_cb() { |
| 51 | // Register the exit-cb in reverse order (3,2,1) |
| 52 | // so that they'd be called in 1,2,3 order. |
| 53 | __libc_register_thread_exit_callback(&exit_cb_3); |
| 54 | __libc_register_thread_exit_callback(&exit_cb_2); |
| 55 | __libc_register_thread_exit_callback(&exit_cb_1); |
| 56 | } |
| 57 | |
| 58 | int main() { |
| 59 | test_register_thread_exit_cb(); |
| 60 | return 0; |
| 61 | } |
| 62 | #else |
| 63 | int main() { |
| 64 | return 0; |
| 65 | } |
| 66 | #endif // __BIONIC__ |