1 // RUN: %clangxx %s -o %t -ldl
2 // RUN: %clangxx_hwasan -shared %s -o %t.so -DSHARED_LIB -shared-libsan -Wl,-rpath,%compiler_rt_libdir
3 // RUN: %env_hwasan_opts=disable_allocator_tagging=0 %run %t
5 // The dynamic loader on Android O appears to have a bug where it crashes when
6 // dlopening DF_1_GLOBAL libraries.
7 // REQUIRES: android-28
11 // Test that allocations made by the system allocator can be realloc'd and freed
12 // by the hwasan allocator.
14 typedef void run_test_fn(void *(*system_malloc)(size_t size));
18 // Call the __sanitizer_ versions of these functions so that the test
19 // doesn't require the Android dynamic loader.
20 extern "C" void *__sanitizer_realloc(void *ptr, size_t size);
21 extern "C" void __sanitizer_free(void *ptr);
23 extern "C" run_test_fn run_test;
24 void run_test(void *(*system_malloc)(size_t size)) {
25 void *mem = system_malloc(64);
26 mem = __sanitizer_realloc(mem, 128);
27 __sanitizer_free(mem);
36 int main(int argc, char **argv) {
37 std::string path = argv[0];
39 void *lib = dlopen(path.c_str(), RTLD_NOW);
41 printf("error in dlopen(): %s\n", dlerror());
45 auto run_test = reinterpret_cast<run_test_fn *>(dlsym(lib, "run_test"));
47 printf("failed dlsym\n");