[compiler-rt] r331618 - [sanitizer] Replace InternalScopedBuffer with InternalMmapVector

Vitaly Buka via llvm-commits llvm-commits at lists.llvm.org
Sun May 6 22:56:36 PDT 2018


Author: vitalybuka
Date: Sun May  6 22:56:36 2018
New Revision: 331618

URL: http://llvm.org/viewvc/llvm-project?rev=331618&view=rev
Log:
[sanitizer] Replace InternalScopedBuffer with InternalMmapVector

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

Modified: compiler-rt/trunk/lib/asan/asan_report.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_report.cc?rev=331618&r1=331617&r2=331618&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_report.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_report.cc Sun May  6 22:56:36 2018
@@ -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(),

Modified: compiler-rt/trunk/lib/esan/esan_sideline_linux.cpp
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/esan/esan_sideline_linux.cpp?rev=331618&r1=331617&r2=331618&view=diff
==============================================================================
--- compiler-rt/trunk/lib/esan/esan_sideline_linux.cpp (original)
+++ compiler-rt/trunk/lib/esan/esan_sideline_linux.cpp Sun May  6 22:56:36 2018
@@ -70,7 +70,7 @@ int SidelineThread::runSideline(void *Ar
   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;

Modified: compiler-rt/trunk/lib/hwasan/hwasan_linux.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/hwasan/hwasan_linux.cc?rev=331618&r1=331617&r2=331618&view=diff
==============================================================================
--- compiler-rt/trunk/lib/hwasan/hwasan_linux.cc (original)
+++ compiler-rt/trunk/lib/hwasan/hwasan_linux.cc Sun May  6 22:56:36 2018
@@ -336,7 +336,7 @@ static bool HwasanOnSIGTRAP(int signo, s
   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};

Modified: compiler-rt/trunk/lib/lsan/lsan_common.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/lsan/lsan_common.cc?rev=331618&r1=331617&r2=331618&view=diff
==============================================================================
--- compiler-rt/trunk/lib/lsan/lsan_common.cc (original)
+++ compiler-rt/trunk/lib/lsan/lsan_common.cc Sun May  6 22:56:36 2018
@@ -214,7 +214,7 @@ void ForEachExtraStackRangeCb(uptr begin
 // 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());

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h?rev=331618&r1=331617&r2=331618&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h Sun May  6 22:56:36 2018
@@ -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 Intern
   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_; }

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_file.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_file.cc?rev=331618&r1=331617&r2=331618&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_file.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_file.cc Sun May  6 22:56:36 2018
@@ -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);

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.h?rev=331618&r1=331617&r2=331618&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux.h Sun May  6 22:56:36 2018
@@ -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_;

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux_libcdep.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux_libcdep.cc?rev=331618&r1=331617&r2=331618&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux_libcdep.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux_libcdep.cc Sun May  6 22:56:36 2018
@@ -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;

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc?rev=331618&r1=331617&r2=331618&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc Sun May  6 22:56:36 2018
@@ -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();

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_report.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_report.cc?rev=331618&r1=331617&r2=331618&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_report.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_symbolizer_report.cc Sun May  6 22:56:36 2018
@@ -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(cons
          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
       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);

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_unwind_linux_libcdep.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_unwind_linux_libcdep.cc?rev=331618&r1=331617&r2=331618&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_unwind_linux_libcdep.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_unwind_linux_libcdep.cc Sun May  6 22:56:36 2018
@@ -149,7 +149,7 @@ void BufferedStackTrace::SlowUnwindStack
 
   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(),

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc?rev=331618&r1=331617&r2=331618&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc Sun May  6 22:56:36 2018
@@ -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;

Modified: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_allocator_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_allocator_test.cc?rev=331618&r1=331617&r2=331618&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_allocator_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_allocator_test.cc Sun May  6 22:56:36 2018
@@ -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++) {

Modified: compiler-rt/trunk/lib/stats/stats.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/stats/stats.cc?rev=331618&r1=331617&r2=331618&view=diff
==============================================================================
--- compiler-rt/trunk/lib/stats/stats.cc (original)
+++ compiler-rt/trunk/lib/stats/stats.cc Sun May  6 22:56:36 2018
@@ -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;

Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_platform_linux.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_platform_linux.cc?rev=331618&r1=331617&r2=331618&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_platform_linux.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_platform_linux.cc Sun May  6 22:56:36 2018
@@ -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;

Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc?rev=331618&r1=331617&r2=331618&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc Sun May  6 22:56:36 2018
@@ -140,7 +140,7 @@ static void MemoryProfiler(Context *ctx,
   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()));
 }




More information about the llvm-commits mailing list