1// This is a host program for DLL tests.
2//
3// Just make sure we can compile this.
4// The actual compile&run sequence is to be done by the DLL tests.
5// RUN: %clang_cl_asan -O0 %s -Fe%t
6//
7// Get the list of ASan wrappers exported by the main module RTL:
8// RUN: dumpbin /EXPORTS %t | grep -o "__asan_wrap[^ ]*" | grep -v @ | sort | uniq > %t.exported_wrappers
9// FIXME: we should really check the other __asan exports too.
10// RUN: dumpbin /EXPORTS %t | grep -o "__sanitizer_[^ ]*" | grep -v @ | sort | uniq >> %t.exported_wrappers
11//
12// Get the list of ASan wrappers imported by the DLL RTL:
13// [BEWARE: be really careful with the sed commands, as this test can be run
14//  from different environemnts with different shells and seds]
15// RUN: grep INTERCEPT_LIBRARY_FUNCTION %p/../../../../lib/asan/asan_win_dll_thunk.cc | grep -v define | sed -e s/.*(/__asan_wrap_/ | sed -e s/).*// | sort | uniq > %t.dll_imports
16// RUN: grep "^INTERFACE_FUNCTION.*sanitizer" %p/../../../../lib/asan/asan_win_dll_thunk.cc | grep -v define | sed -e s/.*(// | sed -e s/).*// | sort | uniq >> %t.dll_imports
17//
18// Now make sure the DLL thunk imports everything:
19// RUN: echo
20// RUN: echo "=== NOTE === If you see a mismatch below, please update asan_win_dll_thunk.cc"
21// RUN: diff %t.dll_imports %t.exported_wrappers
22// REQUIRES: asan-static-runtime
23
24#include <stdio.h>
25#include <windows.h>
26
27int main(int argc, char **argv) {
28  if (argc != 2) {
29    printf("Usage: %s [client].dll\n", argv[0]);
30    return 101;
31  }
32
33  const char *dll_name = argv[1];
34
35  HMODULE h = LoadLibrary(dll_name);
36  if (!h) {
37    printf("Could not load DLL: %s (code: %lu)!\n",
38           dll_name, GetLastError());
39    return 102;
40  }
41
42  typedef int (*test_function)();
43  test_function gf = (test_function)GetProcAddress(h, "test_function");
44  if (!gf) {
45    printf("Could not locate test_function in the DLL!\n");
46    FreeLibrary(h);
47    return 103;
48  }
49
50  int ret = gf();
51
52  FreeLibrary(h);
53  return ret;
54}
55