diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2020-01-17 20:45:01 +0000 |
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2020-01-17 20:45:01 +0000 |
| commit | 706b4fc47bbc608932d3b491ae19a3b9cde9497b (patch) | |
| tree | 4adf86a776049cbf7f69a1929c4babcbbef925eb /compiler-rt/lib/fuzzer | |
| parent | 7cc9cf2bf09f069cb2dd947ead05d0b54301fb71 (diff) | |
Notes
Diffstat (limited to 'compiler-rt/lib/fuzzer')
| -rw-r--r-- | compiler-rt/lib/fuzzer/FuzzerDefs.h | 18 | ||||
| -rw-r--r-- | compiler-rt/lib/fuzzer/FuzzerDriver.cpp | 7 | ||||
| -rw-r--r-- | compiler-rt/lib/fuzzer/FuzzerExtFunctionsWeak.cpp | 2 | ||||
| -rw-r--r-- | compiler-rt/lib/fuzzer/FuzzerExtraCounters.cpp | 2 | ||||
| -rw-r--r-- | compiler-rt/lib/fuzzer/FuzzerFlags.def | 3 | ||||
| -rw-r--r-- | compiler-rt/lib/fuzzer/FuzzerIO.cpp | 2 | ||||
| -rw-r--r-- | compiler-rt/lib/fuzzer/FuzzerIO.h | 2 | ||||
| -rw-r--r-- | compiler-rt/lib/fuzzer/FuzzerIOPosix.cpp | 8 | ||||
| -rw-r--r-- | compiler-rt/lib/fuzzer/FuzzerIOWindows.cpp | 8 | ||||
| -rw-r--r-- | compiler-rt/lib/fuzzer/FuzzerUtil.h | 2 | ||||
| -rw-r--r-- | compiler-rt/lib/fuzzer/FuzzerUtilDarwin.cpp | 9 | ||||
| -rw-r--r-- | compiler-rt/lib/fuzzer/FuzzerUtilFuchsia.cpp | 77 | ||||
| -rw-r--r-- | compiler-rt/lib/fuzzer/FuzzerUtilLinux.cpp | 11 | ||||
| -rw-r--r-- | compiler-rt/lib/fuzzer/FuzzerUtilPosix.cpp | 5 | ||||
| -rw-r--r-- | compiler-rt/lib/fuzzer/FuzzerUtilWindows.cpp | 9 |
15 files changed, 122 insertions, 43 deletions
diff --git a/compiler-rt/lib/fuzzer/FuzzerDefs.h b/compiler-rt/lib/fuzzer/FuzzerDefs.h index 5dc2d8e1ac09..5793e86aa804 100644 --- a/compiler-rt/lib/fuzzer/FuzzerDefs.h +++ b/compiler-rt/lib/fuzzer/FuzzerDefs.h @@ -30,6 +30,7 @@ #define LIBFUZZER_FREEBSD 0 #define LIBFUZZER_OPENBSD 0 #define LIBFUZZER_WINDOWS 0 +#define LIBFUZZER_EMSCRIPTEN 0 #elif __APPLE__ #define LIBFUZZER_APPLE 1 #define LIBFUZZER_FUCHSIA 0 @@ -38,6 +39,7 @@ #define LIBFUZZER_FREEBSD 0 #define LIBFUZZER_OPENBSD 0 #define LIBFUZZER_WINDOWS 0 +#define LIBFUZZER_EMSCRIPTEN 0 #elif __NetBSD__ #define LIBFUZZER_APPLE 0 #define LIBFUZZER_FUCHSIA 0 @@ -46,6 +48,7 @@ #define LIBFUZZER_FREEBSD 0 #define LIBFUZZER_OPENBSD 0 #define LIBFUZZER_WINDOWS 0 +#define LIBFUZZER_EMSCRIPTEN 0 #elif __FreeBSD__ #define LIBFUZZER_APPLE 0 #define LIBFUZZER_FUCHSIA 0 @@ -54,6 +57,7 @@ #define LIBFUZZER_FREEBSD 1 #define LIBFUZZER_OPENBSD 0 #define LIBFUZZER_WINDOWS 0 +#define LIBFUZZER_EMSCRIPTEN 0 #elif __OpenBSD__ #define LIBFUZZER_APPLE 0 #define LIBFUZZER_FUCHSIA 0 @@ -62,6 +66,7 @@ #define LIBFUZZER_FREEBSD 0 #define LIBFUZZER_OPENBSD 1 #define LIBFUZZER_WINDOWS 0 +#define LIBFUZZER_EMSCRIPTEN 0 #elif _WIN32 #define LIBFUZZER_APPLE 0 #define LIBFUZZER_FUCHSIA 0 @@ -70,6 +75,7 @@ #define LIBFUZZER_FREEBSD 0 #define LIBFUZZER_OPENBSD 0 #define LIBFUZZER_WINDOWS 1 +#define LIBFUZZER_EMSCRIPTEN 0 #elif __Fuchsia__ #define LIBFUZZER_APPLE 0 #define LIBFUZZER_FUCHSIA 1 @@ -78,6 +84,16 @@ #define LIBFUZZER_FREEBSD 0 #define LIBFUZZER_OPENBSD 0 #define LIBFUZZER_WINDOWS 0 +#define LIBFUZZER_EMSCRIPTEN 0 +#elif __EMSCRIPTEN__ +#define LIBFUZZER_APPLE 0 +#define LIBFUZZER_FUCHSIA 0 +#define LIBFUZZER_LINUX 0 +#define LIBFUZZER_NETBSD 0 +#define LIBFUZZER_FREEBSD 0 +#define LIBFUZZER_OPENBSD 0 +#define LIBFUZZER_WINDOWS 0 +#define LIBFUZZER_EMSCRIPTEN 1 #else #error "Support for your platform has not been implemented" #endif @@ -95,7 +111,7 @@ #define LIBFUZZER_POSIX \ (LIBFUZZER_APPLE || LIBFUZZER_LINUX || LIBFUZZER_NETBSD || \ - LIBFUZZER_FREEBSD || LIBFUZZER_OPENBSD) + LIBFUZZER_FREEBSD || LIBFUZZER_OPENBSD || LIBFUZZER_EMSCRIPTEN) #ifdef __x86_64 # if __has_attribute(target) diff --git a/compiler-rt/lib/fuzzer/FuzzerDriver.cpp b/compiler-rt/lib/fuzzer/FuzzerDriver.cpp index 44c90655b932..dd3cab0ee8d2 100644 --- a/compiler-rt/lib/fuzzer/FuzzerDriver.cpp +++ b/compiler-rt/lib/fuzzer/FuzzerDriver.cpp @@ -280,7 +280,8 @@ static void RssThread(Fuzzer *F, size_t RssLimitMb) { } static void StartRssThread(Fuzzer *F, size_t RssLimitMb) { - if (!RssLimitMb) return; + if (!RssLimitMb) + return; std::thread T(RssThread, F, RssLimitMb); T.detach(); } @@ -737,7 +738,11 @@ int FuzzerDriver(int *argc, char ***argv, UserCallback Callback) { if (U.size() <= Word::GetMaxSize()) MD->AddWordToManualDictionary(Word(U.data(), U.size())); + // Threads are only supported by Chrome. Don't use them with emscripten + // for now. +#if !LIBFUZZER_EMSCRIPTEN StartRssThread(F, Flags.rss_limit_mb); +#endif // LIBFUZZER_EMSCRIPTEN Options.HandleAbrt = Flags.handle_abrt; Options.HandleBus = Flags.handle_bus; diff --git a/compiler-rt/lib/fuzzer/FuzzerExtFunctionsWeak.cpp b/compiler-rt/lib/fuzzer/FuzzerExtFunctionsWeak.cpp index ea5b87bd5196..d56dab36c646 100644 --- a/compiler-rt/lib/fuzzer/FuzzerExtFunctionsWeak.cpp +++ b/compiler-rt/lib/fuzzer/FuzzerExtFunctionsWeak.cpp @@ -13,7 +13,7 @@ //===----------------------------------------------------------------------===// #include "FuzzerDefs.h" #if LIBFUZZER_LINUX || LIBFUZZER_NETBSD || LIBFUZZER_FUCHSIA || \ - LIBFUZZER_FREEBSD || LIBFUZZER_OPENBSD + LIBFUZZER_FREEBSD || LIBFUZZER_OPENBSD || LIBFUZZER_EMSCRIPTEN #include "FuzzerExtFunctions.h" #include "FuzzerIO.h" diff --git a/compiler-rt/lib/fuzzer/FuzzerExtraCounters.cpp b/compiler-rt/lib/fuzzer/FuzzerExtraCounters.cpp index 3f38f4fb70c1..b2face778203 100644 --- a/compiler-rt/lib/fuzzer/FuzzerExtraCounters.cpp +++ b/compiler-rt/lib/fuzzer/FuzzerExtraCounters.cpp @@ -11,7 +11,7 @@ #include "FuzzerDefs.h" #if LIBFUZZER_LINUX || LIBFUZZER_NETBSD || LIBFUZZER_FREEBSD || \ - LIBFUZZER_OPENBSD + LIBFUZZER_OPENBSD || LIBFUZZER_FUCHSIA || LIBFUZZER_EMSCRIPTEN __attribute__((weak)) extern uint8_t __start___libfuzzer_extra_counters; __attribute__((weak)) extern uint8_t __stop___libfuzzer_extra_counters; diff --git a/compiler-rt/lib/fuzzer/FuzzerFlags.def b/compiler-rt/lib/fuzzer/FuzzerFlags.def index 0e19a9cde6ca..a67415743032 100644 --- a/compiler-rt/lib/fuzzer/FuzzerFlags.def +++ b/compiler-rt/lib/fuzzer/FuzzerFlags.def @@ -56,7 +56,8 @@ FUZZER_FLAG_STRING(merge_control_file, "Specify a control file used for the merge process. " "If a merge process gets killed it tries to leave this file " "in a state suitable for resuming the merge. " - "By default a temporary file will be used.") + "By default a temporary file will be used." + "The same file can be used for multistep merge process.") FUZZER_FLAG_INT(minimize_crash, 0, "If 1, minimizes the provided" " crash input. Use with -runs=N or -max_total_time=N to limit " "the number attempts." diff --git a/compiler-rt/lib/fuzzer/FuzzerIO.cpp b/compiler-rt/lib/fuzzer/FuzzerIO.cpp index 7e5ba30a2e7d..f0708164be87 100644 --- a/compiler-rt/lib/fuzzer/FuzzerIO.cpp +++ b/compiler-rt/lib/fuzzer/FuzzerIO.cpp @@ -111,7 +111,7 @@ std::string DirPlusFile(const std::string &DirPath, void DupAndCloseStderr() { int OutputFd = DuplicateFile(2); - if (OutputFd > 0) { + if (OutputFd >= 0) { FILE *NewOutputFile = OpenFile(OutputFd, "w"); if (NewOutputFile) { OutputFile = NewOutputFile; diff --git a/compiler-rt/lib/fuzzer/FuzzerIO.h b/compiler-rt/lib/fuzzer/FuzzerIO.h index fe0d7b451758..ae8dd24e373c 100644 --- a/compiler-rt/lib/fuzzer/FuzzerIO.h +++ b/compiler-rt/lib/fuzzer/FuzzerIO.h @@ -94,8 +94,6 @@ int DuplicateFile(int Fd); void RemoveFile(const std::string &Path); void RenameFile(const std::string &OldPath, const std::string &NewPath); -void DiscardOutput(int Fd); - intptr_t GetHandleFromFd(int fd); void MkDir(const std::string &Path); diff --git a/compiler-rt/lib/fuzzer/FuzzerIOPosix.cpp b/compiler-rt/lib/fuzzer/FuzzerIOPosix.cpp index cfd69bbc8111..fcd9b8d8b9c7 100644 --- a/compiler-rt/lib/fuzzer/FuzzerIOPosix.cpp +++ b/compiler-rt/lib/fuzzer/FuzzerIOPosix.cpp @@ -124,14 +124,6 @@ void RenameFile(const std::string &OldPath, const std::string &NewPath) { rename(OldPath.c_str(), NewPath.c_str()); } -void DiscardOutput(int Fd) { - FILE* Temp = fopen("/dev/null", "w"); - if (!Temp) - return; - dup2(fileno(Temp), Fd); - fclose(Temp); -} - intptr_t GetHandleFromFd(int fd) { return static_cast<intptr_t>(fd); } diff --git a/compiler-rt/lib/fuzzer/FuzzerIOWindows.cpp b/compiler-rt/lib/fuzzer/FuzzerIOWindows.cpp index 510afebef738..56757aa09a37 100644 --- a/compiler-rt/lib/fuzzer/FuzzerIOWindows.cpp +++ b/compiler-rt/lib/fuzzer/FuzzerIOWindows.cpp @@ -223,14 +223,6 @@ void RenameFile(const std::string &OldPath, const std::string &NewPath) { rename(OldPath.c_str(), NewPath.c_str()); } -void DiscardOutput(int Fd) { - FILE* Temp = fopen("nul", "w"); - if (!Temp) - return; - _dup2(_fileno(Temp), Fd); - fclose(Temp); -} - intptr_t GetHandleFromFd(int fd) { return _get_osfhandle(fd); } diff --git a/compiler-rt/lib/fuzzer/FuzzerUtil.h b/compiler-rt/lib/fuzzer/FuzzerUtil.h index 85c5571d684f..00ea6550646f 100644 --- a/compiler-rt/lib/fuzzer/FuzzerUtil.h +++ b/compiler-rt/lib/fuzzer/FuzzerUtil.h @@ -79,6 +79,8 @@ inline std::pair<std::string, std::string> SplitBefore(std::string X, return std::make_pair(S.substr(0, Pos), S.substr(Pos)); } +void DiscardOutput(int Fd); + std::string DisassembleCmd(const std::string &FileName); std::string SearchRegexCmd(const std::string &Regex); diff --git a/compiler-rt/lib/fuzzer/FuzzerUtilDarwin.cpp b/compiler-rt/lib/fuzzer/FuzzerUtilDarwin.cpp index 171db23570c4..d449bc248f09 100644 --- a/compiler-rt/lib/fuzzer/FuzzerUtilDarwin.cpp +++ b/compiler-rt/lib/fuzzer/FuzzerUtilDarwin.cpp @@ -17,6 +17,7 @@ #include <stdlib.h> #include <string.h> #include <sys/wait.h> +#include <unistd.h> // There is no header for this on macOS so declare here extern "C" char **environ; @@ -156,6 +157,14 @@ int ExecuteCommand(const Command &Cmd) { return ProcessStatus; } +void DiscardOutput(int Fd) { + FILE* Temp = fopen("/dev/null", "w"); + if (!Temp) + return; + dup2(fileno(Temp), Fd); + fclose(Temp); +} + } // namespace fuzzer #endif // LIBFUZZER_APPLE diff --git a/compiler-rt/lib/fuzzer/FuzzerUtilFuchsia.cpp b/compiler-rt/lib/fuzzer/FuzzerUtilFuchsia.cpp index 79fd950bbf97..bde9f68d62aa 100644 --- a/compiler-rt/lib/fuzzer/FuzzerUtilFuchsia.cpp +++ b/compiler-rt/lib/fuzzer/FuzzerUtilFuchsia.cpp @@ -18,6 +18,7 @@ #include <cinttypes> #include <cstdint> #include <fcntl.h> +#include <lib/fdio/fdio.h> #include <lib/fdio/spawn.h> #include <string> #include <sys/select.h> @@ -76,6 +77,23 @@ void InterruptHandler() { Fuzzer::StaticInterruptCallback(); } +// CFAOffset is used to reference the stack pointer before entering the +// trampoline (Stack Pointer + CFAOffset = prev Stack Pointer). Before jumping +// to the trampoline we copy all the registers onto the stack. We need to make +// sure that the new stack has enough space to store all the registers. +// +// The trampoline holds CFI information regarding the registers stored in the +// stack, which is then used by the unwinder to restore them. +#if defined(__x86_64__) +// In x86_64 the crashing function might also be using the red zone (128 bytes +// on top of their rsp). +constexpr size_t CFAOffset = 128 + sizeof(zx_thread_state_general_regs_t); +#elif defined(__aarch64__) +// In aarch64 we need to always have the stack pointer aligned to 16 bytes, so we +// make sure that we are keeping that same alignment. +constexpr size_t CFAOffset = (sizeof(zx_thread_state_general_regs_t) + 15) & -(uintptr_t)16; +#endif + // For the crash handler, we need to call Fuzzer::StaticCrashSignalCallback // without POSIX signal handlers. To achieve this, we use an assembly function // to add the necessary CFI unwinding information and a C function to bridge @@ -140,7 +158,6 @@ void InterruptHandler() { OP_NUM(27) \ OP_NUM(28) \ OP_NUM(29) \ - OP_NUM(30) \ OP_REG(sp) #else @@ -148,14 +165,17 @@ void InterruptHandler() { #endif // Produces a CFI directive for the named or numbered register. +// The value used refers to an assembler immediate operand with the same name +// as the register (see ASM_OPERAND_REG). #define CFI_OFFSET_REG(reg) ".cfi_offset " #reg ", %c[" #reg "]\n" -#define CFI_OFFSET_NUM(num) CFI_OFFSET_REG(r##num) +#define CFI_OFFSET_NUM(num) CFI_OFFSET_REG(x##num) -// Produces an assembler input operand for the named or numbered register. +// Produces an assembler immediate operand for the named or numbered register. +// This operand contains the offset of the register relative to the CFA. #define ASM_OPERAND_REG(reg) \ - [reg] "i"(offsetof(zx_thread_state_general_regs_t, reg)), + [reg] "i"(offsetof(zx_thread_state_general_regs_t, reg) - CFAOffset), #define ASM_OPERAND_NUM(num) \ - [r##num] "i"(offsetof(zx_thread_state_general_regs_t, r[num])), + [x##num] "i"(offsetof(zx_thread_state_general_regs_t, r[num]) - CFAOffset), // Trampoline to bridge from the assembly below to the static C++ crash // callback. @@ -168,7 +188,16 @@ static void StaticCrashHandler() { } // Creates the trampoline with the necessary CFI information to unwind through -// to the crashing call stack. The attribute is necessary because the function +// to the crashing call stack: +// * Defining the CFA so that it points to the stack pointer at the point +// of crash. +// * Storing all registers at the point of crash in the stack and refer to them +// via CFI information (relative to the CFA). +// * Setting the return column so the unwinder knows how to continue unwinding. +// * (x86_64) making sure rsp is aligned before calling StaticCrashHandler. +// * Calling StaticCrashHandler that will trigger the unwinder. +// +// The __attribute__((used)) is necessary because the function // is never called; it's just a container around the assembly to allow it to // use operands for compile-time computed constants. __attribute__((used)) @@ -181,16 +210,21 @@ void MakeTrampoline() { ".cfi_signal_frame\n" #if defined(__x86_64__) ".cfi_return_column rip\n" - ".cfi_def_cfa rsp, 0\n" + ".cfi_def_cfa rsp, %c[CFAOffset]\n" FOREACH_REGISTER(CFI_OFFSET_REG, CFI_OFFSET_NUM) + "mov %%rsp, %%rbp\n" + ".cfi_def_cfa_register rbp\n" + "andq $-16, %%rsp\n" "call %c[StaticCrashHandler]\n" "ud2\n" #elif defined(__aarch64__) ".cfi_return_column 33\n" - ".cfi_def_cfa sp, 0\n" - ".cfi_offset 33, %c[pc]\n" + ".cfi_def_cfa sp, %c[CFAOffset]\n" FOREACH_REGISTER(CFI_OFFSET_REG, CFI_OFFSET_NUM) - "bl %[StaticCrashHandler]\n" + ".cfi_offset 33, %c[pc]\n" + ".cfi_offset 30, %c[lr]\n" + "bl %c[StaticCrashHandler]\n" + "brk 1\n" #else #error "Unsupported architecture for fuzzing on Fuchsia" #endif @@ -202,8 +236,10 @@ void MakeTrampoline() { : FOREACH_REGISTER(ASM_OPERAND_REG, ASM_OPERAND_NUM) #if defined(__aarch64__) ASM_OPERAND_REG(pc) + ASM_OPERAND_REG(lr) #endif - [StaticCrashHandler] "i" (StaticCrashHandler)); + [StaticCrashHandler] "i" (StaticCrashHandler), + [CFAOffset] "i" (CFAOffset)); } void CrashHandler(zx_handle_t *Event) { @@ -269,17 +305,14 @@ void CrashHandler(zx_handle_t *Event) { // onto the stack and jump into a trampoline with CFI instructions on how // to restore it. #if defined(__x86_64__) - uintptr_t StackPtr = - (GeneralRegisters.rsp - (128 + sizeof(GeneralRegisters))) & - -(uintptr_t)16; + uintptr_t StackPtr = GeneralRegisters.rsp - CFAOffset; __unsanitized_memcpy(reinterpret_cast<void *>(StackPtr), &GeneralRegisters, sizeof(GeneralRegisters)); GeneralRegisters.rsp = StackPtr; GeneralRegisters.rip = reinterpret_cast<zx_vaddr_t>(CrashTrampolineAsm); #elif defined(__aarch64__) - uintptr_t StackPtr = - (GeneralRegisters.sp - sizeof(GeneralRegisters)) & -(uintptr_t)16; + uintptr_t StackPtr = GeneralRegisters.sp - CFAOffset; __unsanitized_memcpy(reinterpret_cast<void *>(StackPtr), &GeneralRegisters, sizeof(GeneralRegisters)); GeneralRegisters.sp = StackPtr; @@ -497,6 +530,18 @@ const void *SearchMemory(const void *Data, size_t DataLen, const void *Patt, return memmem(Data, DataLen, Patt, PattLen); } +// In fuchsia, accessing /dev/null is not supported. There's nothing +// similar to a file that discards everything that is written to it. +// The way of doing something similar in fuchsia is by using +// fdio_null_create and binding that to a file descriptor. +void DiscardOutput(int Fd) { + fdio_t *fdio_null = fdio_null_create(); + if (fdio_null == nullptr) return; + int nullfd = fdio_bind_to_fd(fdio_null, -1, 0); + if (nullfd < 0) return; + dup2(nullfd, Fd); +} + } // namespace fuzzer #endif // LIBFUZZER_FUCHSIA diff --git a/compiler-rt/lib/fuzzer/FuzzerUtilLinux.cpp b/compiler-rt/lib/fuzzer/FuzzerUtilLinux.cpp index d5a15d19f2a9..993023e70393 100644 --- a/compiler-rt/lib/fuzzer/FuzzerUtilLinux.cpp +++ b/compiler-rt/lib/fuzzer/FuzzerUtilLinux.cpp @@ -9,12 +9,13 @@ //===----------------------------------------------------------------------===// #include "FuzzerDefs.h" #if LIBFUZZER_LINUX || LIBFUZZER_NETBSD || LIBFUZZER_FREEBSD || \ - LIBFUZZER_OPENBSD + LIBFUZZER_OPENBSD || LIBFUZZER_EMSCRIPTEN #include "FuzzerCommand.h" #include <stdlib.h> #include <sys/types.h> #include <sys/wait.h> +#include <unistd.h> namespace fuzzer { @@ -27,6 +28,14 @@ int ExecuteCommand(const Command &Cmd) { return exit_code; } +void DiscardOutput(int Fd) { + FILE* Temp = fopen("/dev/null", "w"); + if (!Temp) + return; + dup2(fileno(Temp), Fd); + fclose(Temp); +} + } // namespace fuzzer #endif diff --git a/compiler-rt/lib/fuzzer/FuzzerUtilPosix.cpp b/compiler-rt/lib/fuzzer/FuzzerUtilPosix.cpp index cefe7ae181e7..8048e6a8afd2 100644 --- a/compiler-rt/lib/fuzzer/FuzzerUtilPosix.cpp +++ b/compiler-rt/lib/fuzzer/FuzzerUtilPosix.cpp @@ -98,7 +98,8 @@ void SetTimer(int Seconds) { } void SetSignalHandler(const FuzzingOptions& Options) { - if (Options.UnitTimeoutSec > 0) + // setitimer is not implemented in emscripten. + if (Options.UnitTimeoutSec > 0 && !LIBFUZZER_EMSCRIPTEN) SetTimer(Options.UnitTimeoutSec / 2 + 1); if (Options.HandleInt) SetSigaction(SIGINT, InterruptHandler); @@ -133,7 +134,7 @@ size_t GetPeakRSSMb() { if (getrusage(RUSAGE_SELF, &usage)) return 0; if (LIBFUZZER_LINUX || LIBFUZZER_FREEBSD || LIBFUZZER_NETBSD || - LIBFUZZER_OPENBSD) { + LIBFUZZER_OPENBSD || LIBFUZZER_EMSCRIPTEN) { // ru_maxrss is in KiB return usage.ru_maxrss >> 10; } else if (LIBFUZZER_APPLE) { diff --git a/compiler-rt/lib/fuzzer/FuzzerUtilWindows.cpp b/compiler-rt/lib/fuzzer/FuzzerUtilWindows.cpp index ed90044c3f83..527e7dbd1cf6 100644 --- a/compiler-rt/lib/fuzzer/FuzzerUtilWindows.cpp +++ b/compiler-rt/lib/fuzzer/FuzzerUtilWindows.cpp @@ -16,6 +16,7 @@ #include <chrono> #include <cstring> #include <errno.h> +#include <io.h> #include <iomanip> #include <signal.h> #include <stdio.h> @@ -190,6 +191,14 @@ std::string SearchRegexCmd(const std::string &Regex) { return "findstr /r \"" + Regex + "\""; } +void DiscardOutput(int Fd) { + FILE* Temp = fopen("nul", "w"); + if (!Temp) + return; + _dup2(_fileno(Temp), Fd); + fclose(Temp); +} + } // namespace fuzzer #endif // LIBFUZZER_WINDOWS |
