1.1
|
(patrick 10-Aug-20)
| 1
|
: //===- FuzzerUtilLinux.cpp - Misc utils for Linux. ------------------------===//
|
|
| 2
|
: //
|
|
| 3
|
: // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
| 4
|
: // See https://llvm.org/LICENSE.txt for license information.
|
|
| 5
|
: // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
| 6
|
: //
|
|
| 7
|
: //===----------------------------------------------------------------------===//
|
|
| 8
|
: // Misc utils for Linux.
|
|
| 9
|
: //===----------------------------------------------------------------------===//
|
1.1.1.2
|
(patrick 02-Jan-21)
| 10
|
: #include "FuzzerPlatform.h"
|
1.1
|
(patrick 10-Aug-20)
| 11
|
: #if LIBFUZZER_LINUX || LIBFUZZER_NETBSD || LIBFUZZER_FREEBSD || \
|
1.1.1.3
|
(patrick 17-Dec-21)
| 12
|
: LIBFUZZER_EMSCRIPTEN
|
1.1
|
(patrick 10-Aug-20)
| 13
|
: #include "FuzzerCommand.h"
|
1.1.1.4
|
(robert 26-Jan-24)
| 14
|
: #include "FuzzerInternal.h"
|
1.1
|
(patrick 10-Aug-20)
| 15
|
:
|
1.1.1.4
|
(robert 26-Jan-24)
| 16
|
: #include <signal.h>
|
1.1
|
(patrick 10-Aug-20)
| 17
|
: #include <stdlib.h>
|
|
| 18
|
: #include <sys/types.h>
|
|
| 19
|
: #include <sys/wait.h>
|
|
| 20
|
: #include <unistd.h>
|
|
| 21
|
:
|
|
| 22
|
:
|
|
| 23
|
: namespace fuzzer {
|
|
| 24
|
:
|
|
| 25
|
: int ExecuteCommand(const Command &Cmd) {
|
|
| 26
|
: std::string CmdLine = Cmd.toString();
|
|
| 27
|
: int exit_code = system(CmdLine.c_str());
|
|
| 28
|
: if (WIFEXITED(exit_code))
|
|
| 29
|
: return WEXITSTATUS(exit_code);
|
1.1.1.4
|
(robert 26-Jan-24)
| 30
|
: if (WIFSIGNALED(exit_code) && WTERMSIG(exit_code) == SIGINT)
|
|
| 31
|
: return Fuzzer::InterruptExitCode();
|
1.1
|
(patrick 10-Aug-20)
| 32
|
: return exit_code;
|
|
| 33
|
: }
|
|
| 34
|
:
|
|
| 35
|
: void DiscardOutput(int Fd) {
|
|
| 36
|
: FILE* Temp = fopen("/dev/null", "w");
|
|
| 37
|
: if (!Temp)
|
|
| 38
|
: return;
|
|
| 39
|
: dup2(fileno(Temp), Fd);
|
|
| 40
|
: fclose(Temp);
|
|
| 41
|
: }
|
|
| 42
|
:
|
1.1.1.5
|
(rsadowsk 21-Aug-25)
| 43
|
: void SetThreadName(std::thread &thread, const std::string &name) {
|
|
| 44
|
: #if LIBFUZZER_LINUX || LIBFUZZER_FREEBSD
|
|
| 45
|
: (void)pthread_setname_np(thread.native_handle(), name.c_str());
|
|
| 46
|
: #elif LIBFUZZER_NETBSD
|
|
| 47
|
: (void)pthread_setname_np(thread.native_handle(), "%s", const_cast<char *>(name.c_str()));
|
|
| 48
|
: #endif
|
|
| 49
|
: }
|
|
| 50
|
:
|
1.1
|
(patrick 10-Aug-20)
| 51
|
: } // namespace fuzzer
|
|
| 52
|
:
|
|
| 53
|
: #endif
|