2016-09-21 09:50:50 +08:00
|
|
|
//===- FuzzerTracePC.h - Internal header for the Fuzzer ---------*- C++ -* ===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// fuzzer::TracePC
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_FUZZER_TRACE_PC
|
|
|
|
#define LLVM_FUZZER_TRACE_PC
|
|
|
|
|
|
|
|
#include "FuzzerDefs.h"
|
2016-09-22 05:17:23 +08:00
|
|
|
#include "FuzzerValueBitMap.h"
|
2016-09-21 09:50:50 +08:00
|
|
|
|
|
|
|
namespace fuzzer {
|
|
|
|
|
|
|
|
class TracePC {
|
|
|
|
public:
|
2016-09-30 09:19:56 +08:00
|
|
|
static const size_t kFeatureSetSize = ValueBitMap::kNumberOfItems;
|
|
|
|
|
2016-09-30 01:43:24 +08:00
|
|
|
void HandleTrace(uint32_t *guard, uintptr_t PC);
|
|
|
|
void HandleInit(uint32_t *start, uint32_t *stop);
|
2016-09-21 09:50:50 +08:00
|
|
|
void HandleCallerCallee(uintptr_t Caller, uintptr_t Callee);
|
2016-09-23 08:46:18 +08:00
|
|
|
void HandleValueProfile(size_t Value) { ValueProfileMap.AddValue(Value); }
|
2016-09-23 09:20:07 +08:00
|
|
|
size_t GetTotalPCCoverage() { return TotalPCCoverage; }
|
|
|
|
void ResetTotalPCCoverage() { TotalPCCoverage = 0; }
|
2016-09-21 09:50:50 +08:00
|
|
|
void SetUseCounters(bool UC) { UseCounters = UC; }
|
2016-09-23 08:46:18 +08:00
|
|
|
void SetUseValueProfile(bool VP) { UseValueProfile = VP; }
|
2016-09-23 08:22:46 +08:00
|
|
|
bool UpdateCounterMap(ValueBitMap *MaxCounterMap) {
|
2016-09-23 09:20:07 +08:00
|
|
|
return MaxCounterMap->MergeFrom(CounterMap);
|
2016-09-23 08:22:46 +08:00
|
|
|
}
|
2016-09-23 08:46:18 +08:00
|
|
|
bool UpdateValueProfileMap(ValueBitMap *MaxValueProfileMap) {
|
|
|
|
return UseValueProfile && MaxValueProfileMap->MergeFrom(ValueProfileMap);
|
|
|
|
}
|
2016-10-01 09:04:29 +08:00
|
|
|
bool FinalizeTrace(size_t InputSize);
|
2016-09-21 09:50:50 +08:00
|
|
|
|
2016-09-22 09:34:58 +08:00
|
|
|
size_t GetNewPCIDs(uintptr_t **NewPCIDsPtr) {
|
|
|
|
*NewPCIDsPtr = NewPCIDs;
|
2016-09-23 08:22:46 +08:00
|
|
|
return Min(kMaxNewPCIDs, NumNewPCIDs);
|
2016-09-21 09:50:50 +08:00
|
|
|
}
|
|
|
|
|
2016-09-22 09:34:58 +08:00
|
|
|
uintptr_t GetPCbyPCID(uintptr_t PCID) { return PCs[PCID]; }
|
|
|
|
|
2016-09-23 10:18:59 +08:00
|
|
|
void ResetMaps() {
|
2016-09-22 09:34:58 +08:00
|
|
|
NumNewPCIDs = 0;
|
2016-09-21 09:50:50 +08:00
|
|
|
CounterMap.Reset();
|
2016-09-23 09:58:51 +08:00
|
|
|
ValueProfileMap.Reset();
|
2016-09-24 04:04:13 +08:00
|
|
|
memset(Counters, 0, sizeof(Counters));
|
2016-09-21 09:50:50 +08:00
|
|
|
}
|
|
|
|
|
2016-09-24 07:51:58 +08:00
|
|
|
void UpdateFeatureSet(size_t CurrentElementIdx, size_t CurrentElementSize);
|
|
|
|
void PrintFeatureSet();
|
|
|
|
|
2016-09-23 10:18:59 +08:00
|
|
|
void ResetGuards();
|
|
|
|
|
2016-09-21 09:50:50 +08:00
|
|
|
void PrintModuleInfo();
|
|
|
|
|
|
|
|
void PrintCoverage();
|
|
|
|
|
2016-09-30 09:19:56 +08:00
|
|
|
bool HasFeature(size_t Idx) { return CounterMap.Get(Idx); }
|
|
|
|
|
2016-09-21 09:50:50 +08:00
|
|
|
private:
|
|
|
|
bool UseCounters = false;
|
2016-09-23 08:46:18 +08:00
|
|
|
bool UseValueProfile = false;
|
2016-09-23 09:20:07 +08:00
|
|
|
size_t TotalPCCoverage = 0;
|
2016-09-21 09:50:50 +08:00
|
|
|
|
2016-09-27 08:10:20 +08:00
|
|
|
static const size_t kMaxNewPCIDs = 1024;
|
2016-09-22 09:34:58 +08:00
|
|
|
uintptr_t NewPCIDs[kMaxNewPCIDs];
|
|
|
|
size_t NumNewPCIDs = 0;
|
|
|
|
void AddNewPCID(uintptr_t PCID) {
|
|
|
|
NewPCIDs[(NumNewPCIDs++) % kMaxNewPCIDs] = PCID;
|
|
|
|
}
|
2016-09-21 09:50:50 +08:00
|
|
|
|
|
|
|
struct Module {
|
2016-09-30 01:43:24 +08:00
|
|
|
uint32_t *Start, *Stop;
|
2016-09-21 09:50:50 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
Module Modules[4096];
|
|
|
|
size_t NumModules = 0;
|
|
|
|
size_t NumGuards = 0;
|
|
|
|
|
|
|
|
static const size_t kNumCounters = 1 << 14;
|
2016-09-28 09:16:24 +08:00
|
|
|
alignas(8) uint8_t Counters[kNumCounters];
|
2016-09-21 09:50:50 +08:00
|
|
|
|
|
|
|
static const size_t kNumPCs = 1 << 20;
|
|
|
|
uintptr_t PCs[kNumPCs];
|
|
|
|
|
|
|
|
ValueBitMap CounterMap;
|
2016-09-23 08:46:18 +08:00
|
|
|
ValueBitMap ValueProfileMap;
|
2016-10-01 09:04:29 +08:00
|
|
|
uint32_t InputSizesPerFeature[kFeatureSetSize];
|
2016-09-21 09:50:50 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
extern TracePC TPC;
|
|
|
|
|
|
|
|
} // namespace fuzzer
|
|
|
|
|
|
|
|
#endif // LLVM_FUZZER_TRACE_PC
|