1 //===- FuzzerExtFunctionsDlsymWin.cpp - Interface to external functions ---===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
9 // Implementation using dynamic loading for Windows.
10 //===----------------------------------------------------------------------===//
11 #include "FuzzerDefs.h"
14 #include "FuzzerExtFunctions.h"
18 // This must be included after Windows.h.
23 ExternalFunctions::ExternalFunctions() {
24 HMODULE Modules
[1024];
26 HANDLE CurrentProcess
= GetCurrentProcess();
28 if (!EnumProcessModules(CurrentProcess
, Modules
, sizeof(Modules
),
30 Printf("EnumProcessModules failed (error: %d).\n", GetLastError());
34 if (sizeof(Modules
) < BytesNeeded
) {
35 Printf("Error: the array is not big enough to hold all loaded modules.\n");
39 for (size_t i
= 0; i
< (BytesNeeded
/ sizeof(HMODULE
)); i
++)
42 #define EXT_FUNC(NAME, RETURN_TYPE, FUNC_SIG, WARN) \
43 if (this->NAME == nullptr) { \
44 Fn = GetProcAddress(Modules[i], #NAME); \
46 Fn = GetProcAddress(Modules[i], #NAME "__dll"); \
47 this->NAME = (decltype(ExternalFunctions::NAME)) Fn; \
49 #include "FuzzerExtFunctions.def"
53 #define EXT_FUNC(NAME, RETURN_TYPE, FUNC_SIG, WARN) \
54 if (this->NAME == nullptr && WARN) \
55 Printf("WARNING: Failed to find function \"%s\".\n", #NAME);
56 #include "FuzzerExtFunctions.def"
62 #endif // LIBFUZZER_WINDOWS