File: report_globals_reload_dll.cpp

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (51 lines) | stat: -rw-r--r-- 1,120 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Make sure we can handle reloading the same DLL multiple times.
// RUN: %clang_cl_asan %LD %Od -DDLL %s %Fe%t.dll
// RUN: %clang_cl_asan %Od -DEXE %s %Fe%te.exe
// RUN: %env_asan_opts=report_globals=1 %run %te.exe %t.dll 2>&1 | FileCheck %s

#include <windows.h>
#include <stdio.h>
#include <string.h>

extern "C" {
#if defined(EXE)
int main(int argc, char **argv) {
  if (argc != 2) {
    printf("Usage: %s [client].dll\n", argv[0]);
    return 101;
  }
  const char *dll_name = argv[1];

// CHECK: time to load DLL
  printf("time to load DLL\n");
  fflush(0);

// CHECK: in DLL(reason=1)
// CHECK: in DLL(reason=0)
// CHECK: in DLL(reason=1)
// CHECK: in DLL(reason=0)
// CHECK: in DLL(reason=1)
// CHECK: in DLL(reason=0)
  for (int i = 0; i < 30; ++i) {
    HMODULE dll = LoadLibrary(dll_name);
    if (dll == NULL)
      return 3;

    if (!FreeLibrary(dll))
      return 4;
  }

// CHECK: All OK!
  printf("All OK!\n");
  fflush(0);
}
#elif defined(DLL)
BOOL WINAPI DllMain(HMODULE, DWORD reason, LPVOID) {
  printf("in DLL(reason=%d)\n", (int)reason);
  fflush(0);
  return TRUE;
}
#else
# error oops!
#endif
}