blob: 1ce120002115c540a0476da52eb85851e237c947 [file] [log] [blame]
Kostya Serebryanyda63c1d2016-02-26 21:33:56 +00001//===- FuzzerTracePC.cpp - PC tracing--------------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9// Trace PCs.
Kostya Serebryanya00b2432016-09-14 02:13:06 +000010// This module implements __sanitizer_cov_trace_pc_guard[_init],
11// the callback required for -fsanitize-coverage=trace-pc-guard instrumentation.
Kostya Serebryanyda63c1d2016-02-26 21:33:56 +000012//
Kostya Serebryanyda63c1d2016-02-26 21:33:56 +000013//===----------------------------------------------------------------------===//
14
15#include "FuzzerInternal.h"
16
17namespace fuzzer {
Mike Aizatsky1aa501e2016-05-10 23:43:15 +000018
Kostya Serebryanya00b2432016-09-14 02:13:06 +000019TracePC TPC;
Mike Aizatsky1aa501e2016-05-10 23:43:15 +000020
Kostya Serebryanya00b2432016-09-14 02:13:06 +000021void TracePC::HandleTrace(uint8_t *guard, uintptr_t PC) {
22 *guard = 0xff;
23 TotalCoverage++;
Kostya Serebryanyda63c1d2016-02-26 21:33:56 +000024}
Kostya Serebryanya00b2432016-09-14 02:13:06 +000025void TracePC::HandleInit(uint8_t *start, uint8_t *stop) {
26 Printf("INFO: guards: [%p,%p)\n", start, stop);
Kostya Serebryanyda63c1d2016-02-26 21:33:56 +000027}
Kostya Serebryanya00b2432016-09-14 02:13:06 +000028size_t TracePC::GetTotalCoverage() { return TotalCoverage; }
Kostya Serebryanyda63c1d2016-02-26 21:33:56 +000029
30} // namespace fuzzer
31
Dan Liew59144072016-06-06 20:27:09 +000032extern "C" {
Kostya Serebryany32661f92016-08-18 20:52:52 +000033__attribute__((visibility("default")))
Kostya Serebryanya00b2432016-09-14 02:13:06 +000034void __sanitizer_cov_trace_pc_guard(uint8_t *guard) {
35 uintptr_t PC = (uintptr_t)__builtin_return_address(0);
36 fuzzer::TPC.HandleTrace(guard, PC);
Kostya Serebryanyda63c1d2016-02-26 21:33:56 +000037}
Dan Liew59144072016-06-06 20:27:09 +000038
Kostya Serebryany32661f92016-08-18 20:52:52 +000039__attribute__((visibility("default")))
Kostya Serebryanya00b2432016-09-14 02:13:06 +000040void __sanitizer_cov_trace_pc_guard_init(uint8_t *start, uint8_t *stop) {
Dan Liew59144072016-06-06 20:27:09 +000041}
42}