brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.0 KiB · 7cad3f3 Raw
48 lines · cpp
1// RUN: %clang_cl_asan %LD %Od -DDLL %s %Fe%t.dll2// RUN: %clang_cl_asan %Od -DEXE %s %Fe%te.exe3// RUN: %env_asan_opts=report_globals=2 %run %te.exe %t.dll 2>&1 | FileCheck %s4 5#include <windows.h>6#include <stdio.h>7#include <string.h>8 9#if defined(EXE)10int main(int argc, char **argv) {11  if (argc != 2) {12    printf("Usage: %s [client].dll\n", argv[0]);13    return 101;14  }15  const char *dll_name = argv[1];16 17// CHECK: time to load DLL18  printf("time to load DLL\n");19  fflush(0);20 21// On DLL load, the "in DLL\n" string is registered:22// CHECK: Added Global{{.*}} size=1923// CHECK: in DLL(reason=1)24  HMODULE dll = LoadLibrary(dll_name);25  if (dll == NULL)26    return 3;27 28// CHECK: in DLL(reason=0)29// CHECK-NEXT: Removed Global{{.*}} size=1930  if (!FreeLibrary(dll))31    return 4;32 33// CHECK: bye!34  printf("bye!\n");35  fflush(0);36}37#elif defined(DLL)38extern "C" {39BOOL WINAPI DllMain(HMODULE, DWORD reason, LPVOID) {40  printf("in DLL(reason=%d)\n", (int)reason);41  fflush(0);42  return TRUE;43}44}45#else46# error oops!47#endif48