]> granicus.if.org Git - llvm/commitdiff
[libFuzzer] increase the default size for shmem
authorKostya Serebryany <kcc@google.com>
Wed, 1 Feb 2017 00:07:47 +0000 (00:07 +0000)
committerKostya Serebryany <kcc@google.com>
Wed, 1 Feb 2017 00:07:47 +0000 (00:07 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293722 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Fuzzer/FuzzerDriver.cpp
lib/Fuzzer/FuzzerShmem.h
lib/Fuzzer/FuzzerShmemPosix.cpp
lib/Fuzzer/test/equivalence.test

index 5620cdea3fa2fe2e7947983a0b66cf184a795640..01f2bc0413e3177f32b257b9f92cf9e17196d029 100644 (file)
@@ -482,8 +482,8 @@ int FuzzerDriver(int *argc, char ***argv, UserCallback Callback) {
 
   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");
index 88719c1775fdda427cc39f14c2f880bc416c412a..53568e0acb69c93c6789b3a7354c2479f3db4fa3 100644 (file)
@@ -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];
 };
index c87407bb1d61f4e205cde4bb244fefe5cbe7e01b..b727c24e96005af4bac1fed86423586d99bf790e 100644 (file)
@@ -35,17 +35,17 @@ std::string SharedMemoryRegion::SemName(const char *Name, int Idx) {
 }
 
 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 *Name) {
   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++) {
index 6c9d87888e078e6e63ddc4edd4638f63d3652ade..2728447e34a761e68838abad53d4f4ac42316f2a 100644 (file)
@@ -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