[llvm] r293722 - [libFuzzer] increase the default size for shmem
Kostya Serebryany via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 31 16:07:48 PST 2017
Author: kcc
Date: Tue Jan 31 18:07:47 2017
New Revision: 293722
URL: http://llvm.org/viewvc/llvm-project?rev=293722&view=rev
Log:
[libFuzzer] increase the default size for shmem
Modified:
llvm/trunk/lib/Fuzzer/FuzzerDriver.cpp
llvm/trunk/lib/Fuzzer/FuzzerShmem.h
llvm/trunk/lib/Fuzzer/FuzzerShmemPosix.cpp
llvm/trunk/lib/Fuzzer/test/equivalence.test
Modified: llvm/trunk/lib/Fuzzer/FuzzerDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/FuzzerDriver.cpp?rev=293722&r1=293721&r2=293722&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/FuzzerDriver.cpp (original)
+++ llvm/trunk/lib/Fuzzer/FuzzerDriver.cpp Tue Jan 31 18:07:47 2017
@@ -482,8 +482,8 @@ int FuzzerDriver(int *argc, char ***argv
if (auto Name = Flags.run_equivalence_server) {
SMR.Destroy(Name);
- if (!SMR.Create(Name, 1 << 12)) {
- Printf("ERROR: can't create shared memory region\n");
+ if (!SMR.Create(Name)) {
+ Printf("ERROR: can't create shared memory region\n");
return 1;
}
Printf("INFO: EQUIVALENCE SERVER UP\n");
Modified: llvm/trunk/lib/Fuzzer/FuzzerShmem.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/FuzzerShmem.h?rev=293722&r1=293721&r2=293722&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/FuzzerShmem.h (original)
+++ llvm/trunk/lib/Fuzzer/FuzzerShmem.h Tue Jan 31 18:07:47 2017
@@ -22,10 +22,9 @@ namespace fuzzer {
class SharedMemoryRegion {
public:
- bool Create(const char *Name, size_t Size);
+ bool Create(const char *Name);
bool Open(const char *Name);
bool Destroy(const char *Name);
- size_t GetSize() const { return Size; }
uint8_t *GetData() { return Data; }
void PostServer() {Post(0);}
void WaitServer() {Wait(0);}
@@ -33,7 +32,7 @@ class SharedMemoryRegion {
void WaitClient() {Wait(1);}
size_t WriteByteArray(const uint8_t *Bytes, size_t N) {
- N = std::min(N, GetSize() - sizeof(N));
+ assert(N <= kShmemSize - sizeof(N));
memcpy(GetData(), &N, sizeof(N));
memcpy(GetData() + sizeof(N), Bytes, N);
assert(N == ReadByteArraySize());
@@ -50,6 +49,8 @@ class SharedMemoryRegion {
bool IsClient() const { return Data && !IAmServer; }
private:
+
+ static const size_t kShmemSize = 1 << 22;
bool IAmServer;
std::string Path(const char *Name);
std::string SemName(const char *Name, int Idx);
@@ -57,7 +58,6 @@ private:
void Wait(int Idx);
bool Map(int fd);
- size_t Size = 0;
uint8_t *Data = nullptr;
void *Semaphore[2];
};
Modified: llvm/trunk/lib/Fuzzer/FuzzerShmemPosix.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/FuzzerShmemPosix.cpp?rev=293722&r1=293721&r2=293722&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/FuzzerShmemPosix.cpp (original)
+++ llvm/trunk/lib/Fuzzer/FuzzerShmemPosix.cpp Tue Jan 31 18:07:47 2017
@@ -35,17 +35,17 @@ std::string SharedMemoryRegion::SemName(
}
bool SharedMemoryRegion::Map(int fd) {
- Data = (uint8_t *)mmap(0, Size, PROT_WRITE | PROT_READ, MAP_SHARED, fd, 0);
+ Data =
+ (uint8_t *)mmap(0, kShmemSize, PROT_WRITE | PROT_READ, MAP_SHARED, fd, 0);
if (Data == (uint8_t*)-1)
return false;
return true;
}
-bool SharedMemoryRegion::Create(const char *Name, size_t Size) {
+bool SharedMemoryRegion::Create(const char *Name) {
int fd = open(Path(Name).c_str(), O_CREAT | O_RDWR, 0777);
if (fd < 0) return false;
- if (ftruncate(fd, Size) < 0) return false;
- this->Size = Size;
+ if (ftruncate(fd, kShmemSize) < 0) return false;
if (!Map(fd))
return false;
for (int i = 0; i < 2; i++) {
@@ -64,7 +64,7 @@ bool SharedMemoryRegion::Open(const char
struct stat stat_res;
if (0 != fstat(fd, &stat_res))
return false;
- Size = stat_res.st_size;
+ assert(stat_res.st_size == kShmemSize);
if (!Map(fd))
return false;
for (int i = 0; i < 2; i++) {
Modified: llvm/trunk/lib/Fuzzer/test/equivalence.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/test/equivalence.test?rev=293722&r1=293721&r2=293722&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/test/equivalence.test (original)
+++ llvm/trunk/lib/Fuzzer/test/equivalence.test Tue Jan 31 18:07:47 2017
@@ -1,6 +1,6 @@
RUN: LLVMFuzzer-EquivalenceATest -run_equivalence_server=EQUIV_TEST & export APID=$!
RUN: sleep 3
-RUN: not LLVMFuzzer-EquivalenceBTest -use_equivalence_server=EQUIV_TEST 2>&1 | FileCheck %s
+RUN: not LLVMFuzzer-EquivalenceBTest -use_equivalence_server=EQUIV_TEST -max_len=4096 2>&1 | FileCheck %s
CHECK: ERROR: libFuzzer: equivalence-mismatch. Sizes: {{.*}}; offset 2
CHECK: SUMMARY: libFuzzer: equivalence-mismatch
RUN: kill -9 $APID
More information about the llvm-commits
mailing list