| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | |
| // See https://llvm.org/LICENSE.txt for license information. | |
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | |
| #include <windows.h> | |
| #ifdef BUILD_DLL | |
| namespace { | |
| void WriteStderr(const char *Msg, DWORD Len) { | |
| DWORD Written = 0; | |
| WriteFile(GetStdHandle(STD_ERROR_HANDLE), Msg, Len, &Written, nullptr); | |
| } | |
| } // namespace | |
| extern "C" BOOL WINAPI DllMain(HINSTANCE, DWORD Reason, LPVOID Reserved) { | |
| if (Reason == DLL_PROCESS_ATTACH) { | |
| static const char Msg[] = "DLL_PROCESS_ATTACH_CALLED\n"; | |
| WriteStderr(Msg, sizeof(Msg) - 1); | |
| } else if (Reason == DLL_PROCESS_DETACH && Reserved != nullptr) { | |
| static const char Msg[] = "DLL_PROCESS_DETACH_CALLED\n"; | |
| WriteStderr(Msg, sizeof(Msg) - 1); | |
| } | |
| return TRUE; | |
| } | |
| #else | |
| # include <cstddef> | |
| # include <cstdint> | |
| # include <cstdio> | |
| # include <cstdlib> | |
| extern "C" int LLVMFuzzerTestOneInput(const uint8_t *, size_t) { | |
| if (!LoadLibraryA("detach.dll")) { | |
| fprintf(stderr, "LoadLibraryA failed: %lu\n", GetLastError()); | |
| fflush(stderr); | |
| abort(); | |
| } | |
| # ifdef EXIT_IN_TARGET | |
| exit(0); | |
| # else | |
| for (;;) | |
| Sleep(100); | |
| # endif | |
| } | |
| #endif |