Home | History | Annotate | Download | only in Windows
      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 //
     10 // Get the list of ASan wrappers imported by the DLL RTL:
     11 // RUN: grep INTERCEPT_LIBRARY_FUNCTION %p/../../../../lib/asan/asan_dll_thunk.cc | grep -v define | sed "s/.*(\(.*\)).*/__asan_wrap_\1/" | sort | uniq > %t.dll_imports
     12 //
     13 // Now make sure the DLL thunk imports everything:
     14 // RUN: echo
     15 // RUN: echo "=== NOTE === If you see a mismatch below, please update asan_dll_thunk.cc"
     16 // RUN: diff %t.dll_imports %t.exported_wrappers
     17 
     18 #include <stdio.h>
     19 #include <windows.h>
     20 
     21 int main(int argc, char **argv) {
     22   if (argc != 2) {
     23     printf("Usage: %s [client].dll\n", argv[0]);
     24     return 101;
     25   }
     26 
     27   const char *dll_name = argv[1];
     28 
     29   HMODULE h = LoadLibrary(dll_name);
     30   if (!h) {
     31     printf("Could not load DLL: %s (code: %lu)!\n",
     32            dll_name, GetLastError());
     33     return 102;
     34   }
     35 
     36   typedef int (*test_function)();
     37   test_function gf = (test_function)GetProcAddress(h, "test_function");
     38   if (!gf) {
     39     printf("Could not locate test_function in the DLL!\n");
     40     FreeLibrary(h);
     41     return 103;
     42   }
     43 
     44   int ret = gf();
     45 
     46   FreeLibrary(h);
     47   return ret;
     48 }
     49