1// Make sure we can handle reloading the same DLL multiple times.
2// RUN: %clang_cl_asan %LD %Od -DDLL %s %Fe%t.dll
3// RUN: %clang_cl_asan %Od -DEXE %s %Fe%te.exe
4// RUN: %env_asan_opts=report_globals=1 %run %te.exe %t.dll 2>&1 | FileCheck %s
5
6#include <windows.h>
7#include <stdio.h>
8#include <string.h>
9
10#if defined(EXE)
11int main(int argc, char **argv) {
12 if (argc != 2) {
13 printf("Usage: %s [client].dll\n", argv[0]);
14 return 101;
15 }
16 const char *dll_name = argv[1];
17
18// CHECK: time to load DLL
19 printf("time to load DLL\n");
20 fflush(0);
21
22// CHECK: in DLL(reason=1)
23// CHECK: in DLL(reason=0)
24// CHECK: in DLL(reason=1)
25// CHECK: in DLL(reason=0)
26// CHECK: in DLL(reason=1)
27// CHECK: in DLL(reason=0)
28 for (int i = 0; i < 30; ++i) {
29 HMODULE dll = LoadLibrary(dll_name);
30 if (dll == NULL)
31 return 3;
32
33 if (!FreeLibrary(dll))
34 return 4;
35 }
36
37// CHECK: All OK!
38 printf("All OK!\n");
39 fflush(0);
40}
41#elif defined(DLL)
42extern "C" {
43BOOL WINAPI DllMain(HMODULE, DWORD reason, LPVOID) {
44 printf("in DLL(reason=%d)\n", (int)reason);
45 fflush(0);
46 return TRUE;
47}
48}
49#else
50# error oops!
51#endif
52

Provided by KDAB

Privacy Policy
Update your C++ knowledge – Modern C++11/14/17 Training
Find out more

source code of compiler-rt/test/asan/TestCases/Windows/report_globals_reload_dll.cpp