Remove the default clause from a fully-covering switch
[llvm-core.git] / lib / Fuzzer / FuzzerExtFunctionsDlsymWin.cpp
blob321b3ec5d41405d245232f64d28c1ec7d8d5c761
1 //===- FuzzerExtFunctionsDlsymWin.cpp - Interface to external functions ---===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 // Implementation using dynamic loading for Windows.
10 //===----------------------------------------------------------------------===//
11 #include "FuzzerDefs.h"
12 #if LIBFUZZER_WINDOWS
14 #include "FuzzerExtFunctions.h"
15 #include "FuzzerIO.h"
16 #include "Windows.h"
18 // This must be included after Windows.h.
19 #include "Psapi.h"
21 namespace fuzzer {
23 ExternalFunctions::ExternalFunctions() {
24 HMODULE Modules[1024];
25 DWORD BytesNeeded;
26 HANDLE CurrentProcess = GetCurrentProcess();
28 if (!EnumProcessModules(CurrentProcess, Modules, sizeof(Modules),
29 &BytesNeeded)) {
30 Printf("EnumProcessModules failed (error: %d).\n", GetLastError());
31 exit(1);
34 if (sizeof(Modules) < BytesNeeded) {
35 Printf("Error: the array is not big enough to hold all loaded modules.\n");
36 exit(1);
39 for (size_t i = 0; i < (BytesNeeded / sizeof(HMODULE)); i++)
41 FARPROC Fn;
42 #define EXT_FUNC(NAME, RETURN_TYPE, FUNC_SIG, WARN) \
43 if (this->NAME == nullptr) { \
44 Fn = GetProcAddress(Modules[i], #NAME); \
45 if (Fn == nullptr) \
46 Fn = GetProcAddress(Modules[i], #NAME "__dll"); \
47 this->NAME = (decltype(ExternalFunctions::NAME)) Fn; \
49 #include "FuzzerExtFunctions.def"
50 #undef EXT_FUNC
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"
57 #undef EXT_FUNC
60 } // namespace fuzzer
62 #endif // LIBFUZZER_WINDOWS