diff options
author | Vitaly Buka <vitalybuka@google.com> | 2018-05-07 05:56:36 +0000 |
---|---|---|
committer | Vitaly Buka <vitalybuka@google.com> | 2018-05-07 05:56:36 +0000 |
commit | 8e7235a6d07ff68e281958a18061b329e93e94f4 (patch) | |
tree | c954c91bff6a4d5f215acf2127f5d83caba969b5 | |
parent | 1d754d2b06bbd1864d6ceafc98d933a277af0cbe (diff) |
[sanitizer] Replace InternalScopedBuffer with InternalMmapVector
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@331618 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/asan/asan_report.cc | 2 | ||||
-rw-r--r-- | lib/esan/esan_sideline_linux.cpp | 2 | ||||
-rw-r--r-- | lib/hwasan/hwasan_linux.cc | 2 | ||||
-rw-r--r-- | lib/lsan/lsan_common.cc | 2 | ||||
-rw-r--r-- | lib/sanitizer_common/sanitizer_common.h | 20 | ||||
-rw-r--r-- | lib/sanitizer_common/sanitizer_file.cc | 2 | ||||
-rw-r--r-- | lib/sanitizer_common/sanitizer_linux.h | 2 | ||||
-rw-r--r-- | lib/sanitizer_common/sanitizer_linux_libcdep.cc | 2 | ||||
-rw-r--r-- | lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc | 2 | ||||
-rw-r--r-- | lib/sanitizer_common/sanitizer_symbolizer_report.cc | 6 | ||||
-rw-r--r-- | lib/sanitizer_common/sanitizer_unwind_linux_libcdep.cc | 2 | ||||
-rw-r--r-- | lib/sanitizer_common/sanitizer_win.cc | 2 | ||||
-rw-r--r-- | lib/sanitizer_common/tests/sanitizer_allocator_test.cc | 4 | ||||
-rw-r--r-- | lib/stats/stats.cc | 2 | ||||
-rw-r--r-- | lib/tsan/rtl/tsan_platform_linux.cc | 2 | ||||
-rw-r--r-- | lib/tsan/rtl/tsan_rtl.cc | 2 |
16 files changed, 24 insertions, 32 deletions
diff --git a/lib/asan/asan_report.cc b/lib/asan/asan_report.cc index 271e89a75..1801738ff 100644 --- a/lib/asan/asan_report.cc +++ b/lib/asan/asan_report.cc @@ -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(), diff --git a/lib/esan/esan_sideline_linux.cpp b/lib/esan/esan_sideline_linux.cpp index 4a96910ec..2de25fba7 100644 --- a/lib/esan/esan_sideline_linux.cpp +++ b/lib/esan/esan_sideline_linux.cpp @@ -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; diff --git a/lib/hwasan/hwasan_linux.cc b/lib/hwasan/hwasan_linux.cc index 693e3b5b3..3d7923047 100644 --- a/lib/hwasan/hwasan_linux.cc +++ b/lib/hwasan/hwasan_linux.cc @@ -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}; diff --git a/lib/lsan/lsan_common.cc b/lib/lsan/lsan_common.cc index 25967c2d1..12ea8c2bb 100644 --- a/lib/lsan/lsan_common.cc +++ b/lib/lsan/lsan_common.cc @@ -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()); diff --git a/lib/sanitizer_common/sanitizer_common.h b/lib/sanitizer_common/sanitizer_common.h index 4e79a9990..9b90a19eb 100644 --- a/lib/sanitizer_common/sanitizer_common.h +++ b/lib/sanitizer_common/sanitizer_common.h @@ -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_; } diff --git a/lib/sanitizer_common/sanitizer_file.cc b/lib/sanitizer_common/sanitizer_file.cc index cde54bfde..a263a50cb 100644 --- a/lib/sanitizer_common/sanitizer_file.cc +++ b/lib/sanitizer_common/sanitizer_file.cc @@ -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); diff --git a/lib/sanitizer_common/sanitizer_linux.h b/lib/sanitizer_common/sanitizer_linux.h index e005af94d..5d38f5ecf 100644 --- a/lib/sanitizer_common/sanitizer_linux.h +++ b/lib/sanitizer_common/sanitizer_linux.h @@ -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_; diff --git a/lib/sanitizer_common/sanitizer_linux_libcdep.cc b/lib/sanitizer_common/sanitizer_linux_libcdep.cc index 25bb80d82..c08b6054b 100644 --- a/lib/sanitizer_common/sanitizer_linux_libcdep.cc +++ b/lib/sanitizer_common/sanitizer_linux_libcdep.cc @@ -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; diff --git a/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc b/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc index a83421df4..e911216a0 100644 --- a/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc +++ b/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc @@ -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(); diff --git a/lib/sanitizer_common/sanitizer_symbolizer_report.cc b/lib/sanitizer_common/sanitizer_symbolizer_report.cc index 1b218336d..1081ec359 100644 --- a/lib/sanitizer_common/sanitizer_symbolizer_report.cc +++ b/lib/sanitizer_common/sanitizer_symbolizer_report.cc @@ -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); diff --git a/lib/sanitizer_common/sanitizer_unwind_linux_libcdep.cc b/lib/sanitizer_common/sanitizer_unwind_linux_libcdep.cc index 24c947001..9e12c417c 100644 --- a/lib/sanitizer_common/sanitizer_unwind_linux_libcdep.cc +++ b/lib/sanitizer_common/sanitizer_unwind_linux_libcdep.cc @@ -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(), diff --git a/lib/sanitizer_common/sanitizer_win.cc b/lib/sanitizer_common/sanitizer_win.cc index 326abaee1..f59420cbd 100644 --- a/lib/sanitizer_common/sanitizer_win.cc +++ b/lib/sanitizer_common/sanitizer_win.cc @@ -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; diff --git a/lib/sanitizer_common/tests/sanitizer_allocator_test.cc b/lib/sanitizer_common/tests/sanitizer_allocator_test.cc index 6db2c9484..e79d12159 100644 --- a/lib/sanitizer_common/tests/sanitizer_allocator_test.cc +++ b/lib/sanitizer_common/tests/sanitizer_allocator_test.cc @@ -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++) { diff --git a/lib/stats/stats.cc b/lib/stats/stats.cc index 6a6eb3a3c..c7a9a38a6 100644 --- a/lib/stats/stats.cc +++ b/lib/stats/stats.cc @@ -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; diff --git a/lib/tsan/rtl/tsan_platform_linux.cc b/lib/tsan/rtl/tsan_platform_linux.cc index df093f351..de989b780 100644 --- a/lib/tsan/rtl/tsan_platform_linux.cc +++ b/lib/tsan/rtl/tsan_platform_linux.cc @@ -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; diff --git a/lib/tsan/rtl/tsan_rtl.cc b/lib/tsan/rtl/tsan_rtl.cc index 5991af394..ee8433aba 100644 --- a/lib/tsan/rtl/tsan_rtl.cc +++ b/lib/tsan/rtl/tsan_rtl.cc @@ -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())); } |