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:
|
|
|
|
void HandleTrace(uintptr_t *guard, uintptr_t PC);
|
|
|
|
void HandleInit(uintptr_t *start, uintptr_t *stop);
|
|
|
|
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-09-21 09:50:50 +08:00
|
|
|
void FinalizeTrace();
|
|
|
|
|
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
|
|
|
void ResetNewPCIDs() { NumNewPCIDs = 0; }
|
|
|
|
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-23 10:18:59 +08:00
|
|
|
void ResetGuards();
|
|
|
|
|
2016-09-21 09:50:50 +08:00
|
|
|
void PrintModuleInfo();
|
|
|
|
|
|
|
|
void PrintCoverage();
|
|
|
|
|
|
|
|
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-22 09:34:58 +08:00
|
|
|
static const size_t kMaxNewPCIDs = 64;
|
|
|
|
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 {
|
|
|
|
uintptr_t *Start, *Stop;
|
|
|
|
};
|
|
|
|
|
|
|
|
Module Modules[4096];
|
|
|
|
size_t NumModules = 0;
|
|
|
|
size_t NumGuards = 0;
|
|
|
|
|
|
|
|
static const size_t kNumCounters = 1 << 14;
|
|
|
|
uint8_t Counters[kNumCounters];
|
|
|
|
|
|
|
|
static const size_t kNumPCs = 1 << 20;
|
|
|
|
uintptr_t PCs[kNumPCs];
|
|
|
|
|
|
|
|
ValueBitMap CounterMap;
|
2016-09-23 08:46:18 +08:00
|
|
|
ValueBitMap ValueProfileMap;
|
2016-09-21 09:50:50 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
extern TracePC TPC;
|
|
|
|
|
|
|
|
} // namespace fuzzer
|
|
|
|
|
|
|
|
#endif // LLVM_FUZZER_TRACE_PC
|