Path: blob/main/contrib/llvm-project/compiler-rt/lib/fuzzer/FuzzerUtilLinux.cpp
35262 views
//===- FuzzerUtilLinux.cpp - Misc utils for Linux. ------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7// Misc utils for Linux.8//===----------------------------------------------------------------------===//9#include "FuzzerPlatform.h"10#if LIBFUZZER_LINUX || LIBFUZZER_NETBSD || LIBFUZZER_FREEBSD || \11LIBFUZZER_EMSCRIPTEN12#include "FuzzerCommand.h"13#include "FuzzerInternal.h"1415#include <signal.h>16#include <stdlib.h>17#include <sys/types.h>18#include <sys/wait.h>19#include <unistd.h>202122namespace fuzzer {2324int ExecuteCommand(const Command &Cmd) {25std::string CmdLine = Cmd.toString();26int exit_code = system(CmdLine.c_str());27if (WIFEXITED(exit_code))28return WEXITSTATUS(exit_code);29if (WIFSIGNALED(exit_code) && WTERMSIG(exit_code) == SIGINT)30return Fuzzer::InterruptExitCode();31return exit_code;32}3334void DiscardOutput(int Fd) {35FILE* Temp = fopen("/dev/null", "w");36if (!Temp)37return;38dup2(fileno(Temp), Fd);39fclose(Temp);40}4142void SetThreadName(std::thread &thread, const std::string &name) {43#if LIBFUZZER_LINUX || LIBFUZZER_FREEBSD44(void)pthread_setname_np(thread.native_handle(), name.c_str());45#elif LIBFUZZER_NETBSD46(void)pthread_setname_np(thread.native_handle(), "%s", const_cast<char *>(name.c_str()));47#endif48}4950} // namespace fuzzer5152#endif535455