summaryrefslogtreecommitdiffstats
path: root/compiler-rt/lib/fuzzer/FuzzerUtilPosix.cpp
diff options
context:
space:
mode:
authorKostya Serebryany <kcc@google.com>2019-01-31 00:09:43 +0000
committerKostya Serebryany <kcc@google.com>2019-01-31 00:09:43 +0000
commit8da9479e40512b3d1069cc5928c8aaca989fc124 (patch)
tree2230d9b1347d0a97074e066be25309a19e6271af /compiler-rt/lib/fuzzer/FuzzerUtilPosix.cpp
parent49c4c68919ae1be62665e6f0a58d97ae6aad1125 (diff)
downloadbcm5719-llvm-8da9479e40512b3d1069cc5928c8aaca989fc124.tar.gz
bcm5719-llvm-8da9479e40512b3d1069cc5928c8aaca989fc124.zip
[libFuzzer] experimental performance optimization -lazy_counters, off by default. Posix-only for now, tested on Linux
llvm-svn: 352700
Diffstat (limited to 'compiler-rt/lib/fuzzer/FuzzerUtilPosix.cpp')
-rw-r--r--compiler-rt/lib/fuzzer/FuzzerUtilPosix.cpp14
1 files changed, 13 insertions, 1 deletions
diff --git a/compiler-rt/lib/fuzzer/FuzzerUtilPosix.cpp b/compiler-rt/lib/fuzzer/FuzzerUtilPosix.cpp
index 68948d5ae21..56b10ffa668 100644
--- a/compiler-rt/lib/fuzzer/FuzzerUtilPosix.cpp
+++ b/compiler-rt/lib/fuzzer/FuzzerUtilPosix.cpp
@@ -18,6 +18,7 @@
#include <iomanip>
#include <signal.h>
#include <stdio.h>
+#include <sys/mman.h>
#include <sys/resource.h>
#include <sys/syscall.h>
#include <sys/time.h>
@@ -31,6 +32,11 @@ static void AlarmHandler(int, siginfo_t *, void *) {
Fuzzer::StaticAlarmCallback();
}
+static void SegvHandler(int, siginfo_t *si, void *) {
+ assert(si->si_signo == SIGSEGV);
+ Fuzzer::StaticSegvSignalCallback(si->si_addr);
+}
+
static void CrashHandler(int, siginfo_t *, void *) {
Fuzzer::StaticCrashSignalCallback();
}
@@ -64,6 +70,7 @@ static void SetSigaction(int signum,
}
sigact = {};
+ sigact.sa_flags = SA_SIGINFO;
sigact.sa_sigaction = callback;
if (sigaction(signum, &sigact, 0)) {
Printf("libFuzzer: sigaction failed with %d\n", errno);
@@ -82,6 +89,11 @@ void SetTimer(int Seconds) {
SetSigaction(SIGALRM, AlarmHandler);
}
+bool Mprotect(void *Ptr, size_t Size, bool AllowReadWrite) {
+ return 0 == mprotect(Ptr, Size,
+ AllowReadWrite ? (PROT_READ | PROT_WRITE) : PROT_NONE);
+}
+
void SetSignalHandler(const FuzzingOptions& Options) {
if (Options.UnitTimeoutSec > 0)
SetTimer(Options.UnitTimeoutSec / 2 + 1);
@@ -90,7 +102,7 @@ void SetSignalHandler(const FuzzingOptions& Options) {
if (Options.HandleTerm)
SetSigaction(SIGTERM, InterruptHandler);
if (Options.HandleSegv)
- SetSigaction(SIGSEGV, CrashHandler);
+ SetSigaction(SIGSEGV, SegvHandler);
if (Options.HandleBus)
SetSigaction(SIGBUS, CrashHandler);
if (Options.HandleAbrt)
OpenPOWER on IntegriCloud