1c5f01b2fSopenharmony_ci//===- FuzzerUtil.h - Internal header for the Fuzzer Utils ------*- C++ -* ===// 2c5f01b2fSopenharmony_ci// 3c5f01b2fSopenharmony_ci// The LLVM Compiler Infrastructure 4c5f01b2fSopenharmony_ci// 5c5f01b2fSopenharmony_ci// This file is distributed under the University of Illinois Open Source 6c5f01b2fSopenharmony_ci// License. See LICENSE.TXT for details. 7c5f01b2fSopenharmony_ci// 8c5f01b2fSopenharmony_ci//===----------------------------------------------------------------------===// 9c5f01b2fSopenharmony_ci// Util functions. 10c5f01b2fSopenharmony_ci//===----------------------------------------------------------------------===// 11c5f01b2fSopenharmony_ci 12c5f01b2fSopenharmony_ci#ifndef LLVM_FUZZER_UTIL_H 13c5f01b2fSopenharmony_ci#define LLVM_FUZZER_UTIL_H 14c5f01b2fSopenharmony_ci 15c5f01b2fSopenharmony_ci#include "FuzzerDefs.h" 16c5f01b2fSopenharmony_ci 17c5f01b2fSopenharmony_cinamespace fuzzer { 18c5f01b2fSopenharmony_ci 19c5f01b2fSopenharmony_civoid PrintHexArray(const Unit &U, const char *PrintAfter = ""); 20c5f01b2fSopenharmony_ci 21c5f01b2fSopenharmony_civoid PrintHexArray(const uint8_t *Data, size_t Size, 22c5f01b2fSopenharmony_ci const char *PrintAfter = ""); 23c5f01b2fSopenharmony_ci 24c5f01b2fSopenharmony_civoid PrintASCII(const uint8_t *Data, size_t Size, const char *PrintAfter = ""); 25c5f01b2fSopenharmony_ci 26c5f01b2fSopenharmony_civoid PrintASCII(const Unit &U, const char *PrintAfter = ""); 27c5f01b2fSopenharmony_ci 28c5f01b2fSopenharmony_ci// Changes U to contain only ASCII (isprint+isspace) characters. 29c5f01b2fSopenharmony_ci// Returns true iff U has been changed. 30c5f01b2fSopenharmony_cibool ToASCII(uint8_t *Data, size_t Size); 31c5f01b2fSopenharmony_ci 32c5f01b2fSopenharmony_cibool IsASCII(const Unit &U); 33c5f01b2fSopenharmony_ci 34c5f01b2fSopenharmony_cibool IsASCII(const uint8_t *Data, size_t Size); 35c5f01b2fSopenharmony_ci 36c5f01b2fSopenharmony_cistd::string Base64(const Unit &U); 37c5f01b2fSopenharmony_ci 38c5f01b2fSopenharmony_civoid PrintPC(const char *SymbolizedFMT, const char *FallbackFMT, uintptr_t PC); 39c5f01b2fSopenharmony_ci 40c5f01b2fSopenharmony_cistd::string DescribePC(const char *SymbolizedFMT, uintptr_t PC); 41c5f01b2fSopenharmony_ci 42c5f01b2fSopenharmony_ciunsigned NumberOfCpuCores(); 43c5f01b2fSopenharmony_ci 44c5f01b2fSopenharmony_cibool ExecuteCommandAndReadOutput(const std::string &Command, std::string *Out); 45c5f01b2fSopenharmony_ci 46c5f01b2fSopenharmony_ci// Platform specific functions. 47c5f01b2fSopenharmony_civoid SetSignalHandler(const FuzzingOptions& Options); 48c5f01b2fSopenharmony_ci 49c5f01b2fSopenharmony_civoid SleepSeconds(int Seconds); 50c5f01b2fSopenharmony_ci 51c5f01b2fSopenharmony_ciunsigned long GetPid(); 52c5f01b2fSopenharmony_ci 53c5f01b2fSopenharmony_cisize_t GetPeakRSSMb(); 54c5f01b2fSopenharmony_ci 55c5f01b2fSopenharmony_ciint ExecuteCommand(const std::string &Command); 56c5f01b2fSopenharmony_ci 57c5f01b2fSopenharmony_ciFILE *OpenProcessPipe(const char *Command, const char *Mode); 58c5f01b2fSopenharmony_ci 59c5f01b2fSopenharmony_ciconst void *SearchMemory(const void *haystack, size_t haystacklen, 60c5f01b2fSopenharmony_ci const void *needle, size_t needlelen); 61c5f01b2fSopenharmony_ci 62c5f01b2fSopenharmony_cistd::string CloneArgsWithoutX(const std::vector<std::string> &Args, 63c5f01b2fSopenharmony_ci const char *X1, const char *X2); 64c5f01b2fSopenharmony_ci 65c5f01b2fSopenharmony_ciinline std::string CloneArgsWithoutX(const std::vector<std::string> &Args, 66c5f01b2fSopenharmony_ci const char *X) { 67c5f01b2fSopenharmony_ci return CloneArgsWithoutX(Args, X, X); 68c5f01b2fSopenharmony_ci} 69c5f01b2fSopenharmony_ci 70c5f01b2fSopenharmony_ci} // namespace fuzzer 71c5f01b2fSopenharmony_ci 72c5f01b2fSopenharmony_ci#endif // LLVM_FUZZER_UTIL_H 73