[sanitizer] Replace InternalScopedBuffer with InternalMmapVector
authorVitaly Buka <vitalybuka@google.com>
Mon, 7 May 2018 05:56:36 +0000 (05:56 +0000)
committerVitaly Buka <vitalybuka@google.com>
Mon, 7 May 2018 05:56:36 +0000 (05:56 +0000)
llvm-svn: 331618

16 files changed:
compiler-rt/lib/asan/asan_report.cc
compiler-rt/lib/esan/esan_sideline_linux.cpp
compiler-rt/lib/hwasan/hwasan_linux.cc
compiler-rt/lib/lsan/lsan_common.cc
compiler-rt/lib/sanitizer_common/sanitizer_common.h
compiler-rt/lib/sanitizer_common/sanitizer_file.cc
compiler-rt/lib/sanitizer_common/sanitizer_linux.h
compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cc
compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc
compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_report.cc
compiler-rt/lib/sanitizer_common/sanitizer_unwind_linux_libcdep.cc
compiler-rt/lib/sanitizer_common/sanitizer_win.cc
compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator_test.cc
compiler-rt/lib/stats/stats.cc
compiler-rt/lib/tsan/rtl/tsan_platform_linux.cc
compiler-rt/lib/tsan/rtl/tsan_rtl.cc

index 271e89a..1801738 100644 (file)
@@ -156,7 +156,7 @@ class ScopedInErrorReport {
 
     // Copy the message buffer so that we could start logging without holding a
     // lock that gets aquired during printing.
-    InternalScopedBuffer<char> buffer_copy(kErrorMessageBufferSize);
+    InternalMmapVector<char> buffer_copy(kErrorMessageBufferSize);
     {
       BlockingMutexLock l(&error_message_buf_mutex);
       internal_memcpy(buffer_copy.data(),
index 4a96910..2de25fb 100644 (file)
@@ -70,7 +70,7 @@ int SidelineThread::runSideline(void *Arg) {
   internal_prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0);
 
   // Set up a signal handler on an alternate stack for safety.
-  InternalScopedBuffer<char> StackMap(SigAltStackSize);
+  InternalMmapVector<char> StackMap(SigAltStackSize);
   stack_t SigAltStack;
   SigAltStack.ss_sp = StackMap.data();
   SigAltStack.ss_size = SigAltStackSize;
index 693e3b5..3d79230 100644 (file)
@@ -336,7 +336,7 @@ static bool HwasanOnSIGTRAP(int signo, siginfo_t *info, ucontext_t *uc) {
   if (!ai.is_store && !ai.is_load)
     return false;
 
-  InternalScopedBuffer<BufferedStackTrace> stack_buffer(1);
+  InternalMmapVector<BufferedStackTrace> stack_buffer(1);
   BufferedStackTrace *stack = stack_buffer.data();
   stack->Reset();
   SignalContext sig{info, uc};
index 25967c2..12ea8c2 100644 (file)
@@ -214,7 +214,7 @@ void ForEachExtraStackRangeCb(uptr begin, uptr end, void* arg) {
 // Scans thread data (stacks and TLS) for heap pointers.
 static void ProcessThreads(SuspendedThreadsList const &suspended_threads,
                            Frontier *frontier) {
-  InternalScopedBuffer<uptr> registers(suspended_threads.RegisterCount());
+  InternalMmapVector<uptr> registers(suspended_threads.RegisterCount());
   uptr registers_begin = reinterpret_cast<uptr>(registers.data());
   uptr registers_end =
       reinterpret_cast<uptr>(registers.data() + registers.size());
index 4e79a99..9b90a19 100644 (file)
@@ -532,6 +532,10 @@ template<typename T>
 class InternalMmapVector : public InternalMmapVectorNoCtor<T> {
  public:
   InternalMmapVector() { InternalMmapVectorNoCtor<T>::Initialize(1); }
+  explicit InternalMmapVector(uptr cnt) {
+    InternalMmapVectorNoCtor<T>::Initialize(cnt);
+    this->resize(cnt);
+  }
   ~InternalMmapVector() { InternalMmapVectorNoCtor<T>::Destroy(); }
   // Disallow copies and moves.
   InternalMmapVector(const InternalMmapVector &) = delete;
@@ -540,22 +544,10 @@ class InternalMmapVector : public InternalMmapVectorNoCtor<T> {
   InternalMmapVector &operator=(InternalMmapVector &&) = delete;
 };
 
-// InternalScopedBuffer can be used instead of large stack arrays to
-// keep frame size low.
-// FIXME: use InternalAlloc instead of MmapOrDie once
-// InternalAlloc is made libc-free.
-template <typename T>
-class InternalScopedBuffer : public InternalMmapVector<T> {
- public:
-  explicit InternalScopedBuffer(uptr cnt) : InternalMmapVector<T>() {
-    this->resize(cnt);
-  }
-};
-
-class InternalScopedString : public InternalScopedBuffer<char> {
+class InternalScopedString : public InternalMmapVector<char> {
  public:
   explicit InternalScopedString(uptr max_length)
-      : InternalScopedBuffer<char>(max_length), length_(0) {
+      : InternalMmapVector<char>(max_length), length_(0) {
     (*this)[0] = '\0';
   }
   uptr length() { return length_; }
index cde54bf..a263a50 100644 (file)
@@ -140,7 +140,7 @@ char *FindPathToBinary(const char *name) {
   if (!path)
     return nullptr;
   uptr name_len = internal_strlen(name);
-  InternalScopedBuffer<char> buffer(kMaxPathLength);
+  InternalMmapVector<char> buffer(kMaxPathLength);
   const char *beg = path;
   while (true) {
     const char *end = internal_strchrnul(beg, kPathSeparator);
index e005af9..5d38f5e 100644 (file)
@@ -87,7 +87,7 @@ class ThreadLister {
 
   int pid_;
   int descriptor_;
-  InternalScopedBuffer<char> buffer_;
+  InternalMmapVector<char> buffer_;
   bool error_;
   struct linux_dirent* entry_;
   int bytes_read_;
index 25bb80d..c08b605 100644 (file)
@@ -607,7 +607,7 @@ u32 GetNumberOfCPUs() {
   uptr fd = internal_open("/sys/devices/system/cpu", O_RDONLY | O_DIRECTORY);
   if (internal_iserror(fd))
     return 0;
-  InternalScopedBuffer<u8> buffer(4096);
+  InternalMmapVector<u8> buffer(4096);
   uptr bytes_read = buffer.size();
   uptr n_cpus = 0;
   u8 *d_type;
index a83421d..e911216 100644 (file)
@@ -295,7 +295,7 @@ static int TracerThread(void* argument) {
   thread_suspender_instance = &thread_suspender;
 
   // Alternate stack for signal handling.
-  InternalScopedBuffer<char> handler_stack_memory(kHandlerStackSize);
+  InternalMmapVector<char> handler_stack_memory(kHandlerStackSize);
   stack_t handler_stack;
   internal_memset(&handler_stack, 0, sizeof(handler_stack));
   handler_stack.ss_sp = handler_stack_memory.data();
index 1b21833..1081ec3 100644 (file)
@@ -96,7 +96,7 @@ void ReportMmapWriteExec(int prot) {
   ScopedErrorReportLock l;
   SanitizerCommonDecorator d;
 
-  InternalScopedBuffer<BufferedStackTrace> stack_buffer(1);
+  InternalMmapVector<BufferedStackTrace> stack_buffer(1);
   BufferedStackTrace *stack = stack_buffer.data();
   stack->Reset();
   uptr top = 0;
@@ -175,7 +175,7 @@ static void ReportStackOverflowImpl(const SignalContext &sig, u32 tid,
          SanitizerToolName, kDescription, (void *)sig.addr, (void *)sig.pc,
          (void *)sig.bp, (void *)sig.sp, tid);
   Printf("%s", d.Default());
-  InternalScopedBuffer<BufferedStackTrace> stack_buffer(1);
+  InternalMmapVector<BufferedStackTrace> stack_buffer(1);
   BufferedStackTrace *stack = stack_buffer.data();
   stack->Reset();
   unwind(sig, unwind_context, stack);
@@ -205,7 +205,7 @@ static void ReportDeadlySignalImpl(const SignalContext &sig, u32 tid,
       Report("Hint: address points to the zero page.\n");
   }
   MaybeReportNonExecRegion(sig.pc);
-  InternalScopedBuffer<BufferedStackTrace> stack_buffer(1);
+  InternalMmapVector<BufferedStackTrace> stack_buffer(1);
   BufferedStackTrace *stack = stack_buffer.data();
   stack->Reset();
   unwind(sig, unwind_context, stack);
index 24c9470..9e12c41 100644 (file)
@@ -149,7 +149,7 @@ void BufferedStackTrace::SlowUnwindStackWithContext(uptr pc, void *context,
 
   void *map = acquire_my_map_info_list();
   CHECK(map);
-  InternalScopedBuffer<backtrace_frame_t> frames(kStackTraceMax);
+  InternalMmapVector<backtrace_frame_t> frames(kStackTraceMax);
   // siginfo argument appears to be unused.
   sptr res = unwind_backtrace_signal_arch(/* siginfo */ 0, context, map,
                                           frames.data(),
index 326abae..f59420c 100644 (file)
@@ -424,7 +424,7 @@ void DumpProcessMap() {
   modules.init();
   uptr num_modules = modules.size();
 
-  InternalScopedBuffer<ModuleInfo> module_infos(num_modules);
+  InternalMmapVector<ModuleInfo> module_infos(num_modules);
   for (size_t i = 0; i < num_modules; ++i) {
     module_infos[i].filepath = modules[i].full_name();
     module_infos[i].base_address = modules[i].ranges().front()->beg;
index 6db2c94..e79d121 100644 (file)
@@ -813,10 +813,10 @@ TEST(Allocator, LargeAlloc) {
 TEST(Allocator, ScopedBuffer) {
   const int kSize = 512;
   {
-    InternalScopedBuffer<int> int_buf(kSize);
+    InternalMmapVector<int> int_buf(kSize);
     EXPECT_EQ((uptr)kSize, int_buf.size()); // NOLINT
   }
-  InternalScopedBuffer<char> char_buf(kSize);
+  InternalMmapVector<char> char_buf(kSize);
   EXPECT_EQ((uptr)kSize, char_buf.size()); // NOLINT
   internal_memset(char_buf.data(), 'c', kSize);
   for (int i = 0; i < kSize; i++) {
index 6a6eb3a..c7a9a38 100644 (file)
@@ -42,7 +42,7 @@ void WriteLE(fd_t fd, uptr val) {
 }
 
 void OpenStatsFile(const char *path_env) {
-  InternalScopedBuffer<char> path(kMaxPathLength);
+  InternalMmapVector<char> path(kMaxPathLength);
   SubstituteForFlagValue(path_env, path.data(), kMaxPathLength);
 
   error_t err;
index df093f3..de989b7 100644 (file)
@@ -168,7 +168,7 @@ static void MapRodata() {
   fd_t fd = openrv;
   // Fill the file with kShadowRodata.
   const uptr kMarkerSize = 512 * 1024 / sizeof(u64);
-  InternalScopedBuffer<u64> marker(kMarkerSize);
+  InternalMmapVector<u64> marker(kMarkerSize);
   // volatile to prevent insertion of memset
   for (volatile u64 *p = marker.data(); p < marker.data() + kMarkerSize; p++)
     *p = kShadowRodata;
index 5991af3..ee8433a 100644 (file)
@@ -140,7 +140,7 @@ static void MemoryProfiler(Context *ctx, fd_t fd, int i) {
   uptr n_threads;
   uptr n_running_threads;
   ctx->thread_registry->GetNumberOfThreads(&n_threads, &n_running_threads);
-  InternalScopedBuffer<char> buf(4096);
+  InternalMmapVector<char> buf(4096);
   WriteMemoryProfile(buf.data(), buf.size(), n_threads, n_running_threads);
   WriteToFile(fd, buf.data(), internal_strlen(buf.data()));
 }