blob: 1256a849cee130617f8312d03e27cb398f844b24 [file] [log] [blame]
Ryan Prichardb7cd7522018-06-05 21:39:46 -07001#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
12int main() {
13 std::thread([] {
14 void* solib = dlopen("libndktest.so", RTLD_NOW);
Elliott Hughes11dc4cd2024-03-20 16:36:06 -070015 if (!solib) {
16 fprintf(stderr, "can't find libndktest.so (%s)\n", dlerror());
17 abort();
18 }
Ryan Prichardb7cd7522018-06-05 21:39:46 -070019 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}