Ryan Prichard | b7cd752 | 2018-06-05 21:39:46 -0700 | [diff] [blame] | 1 | #include <dlfcn.h> |
| 2 | #include <stdio.h> |
| 3 | #include <stdlib.h> |
| 4 | |
| 5 | #include <thread> |
| 6 | |
| 7 | // Verify that the emutls key is deleted by spawning and joining a thread. If |
| 8 | // the key isn't deleted, Bionic will try to run the per-thread emutls cleanup |
| 9 | // function in the unloaded library and crash. This step is a regression test |
| 10 | // for b/71814577. |
| 11 | |
| 12 | int main() { |
| 13 | std::thread([] { |
| 14 | void* solib = dlopen("libndktest.so", RTLD_NOW); |
Elliott Hughes | 11dc4cd | 2024-03-20 16:36:06 -0700 | [diff] [blame] | 15 | if (!solib) { |
| 16 | fprintf(stderr, "can't find libndktest.so (%s)\n", dlerror()); |
| 17 | abort(); |
| 18 | } |
Ryan Prichard | b7cd752 | 2018-06-05 21:39:46 -0700 | [diff] [blame] | 19 | void (*test_func)() = (void(*)())dlsym(solib, "test_func"); |
| 20 | if (!test_func) { |
| 21 | fprintf(stderr, "can't find test_func func (%s)\n", dlerror()); |
| 22 | abort(); |
| 23 | } |
| 24 | test_func(); |
| 25 | dlclose(solib); |
| 26 | }).join(); |
| 27 | return 0; |
| 28 | } |