From 46b8665ea49afebea3161dbad80f81b4d81fd83f Mon Sep 17 00:00:00 2001 From: Alexey Samsonov Date: Fri, 5 Apr 2013 07:41:21 +0000 Subject: [PATCH] Remove InternalAlloc/InternalFree calls from StopTheWorld. Patch by Sergey Matveev. llvm-svn: 178855 --- compiler-rt/lib/sanitizer_common/sanitizer_linux.cc | 9 +++++---- compiler-rt/lib/sanitizer_common/sanitizer_linux.h | 3 ++- .../sanitizer_stoptheworld_linux.cc | 13 +++++-------- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cc b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cc index 1c1a3fbc34ab..ef185571ada1 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cc @@ -651,8 +651,9 @@ int internal_sigaltstack(const struct sigaltstack *ss, ThreadLister::ThreadLister(int pid) : pid_(pid), descriptor_(-1), + buffer_(4096), error_(true), - entry_((linux_dirent *)buffer_), + entry_((struct linux_dirent *)buffer_.data()), bytes_read_(0) { char task_directory_path[80]; internal_snprintf(task_directory_path, sizeof(task_directory_path), @@ -700,8 +701,8 @@ bool ThreadLister::GetDirectoryEntries() { CHECK_GE(descriptor_, 0); CHECK_NE(error_, true); bytes_read_ = internal_getdents(descriptor_, - (struct linux_dirent *)buffer_, - sizeof(buffer_)); + (struct linux_dirent *)buffer_.data(), + buffer_.size()); if (bytes_read_ < 0) { Report("Can't read directory entries from /proc/%d/task.\n", pid_); error_ = true; @@ -709,7 +710,7 @@ bool ThreadLister::GetDirectoryEntries() { } else if (bytes_read_ == 0) { return false; } - entry_ = (struct linux_dirent *)buffer_; + entry_ = (struct linux_dirent *)buffer_.data(); return true; } diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux.h b/compiler-rt/lib/sanitizer_common/sanitizer_linux.h index 33d39bf50c19..13b60fa91bc0 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_linux.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux.h @@ -13,6 +13,7 @@ #ifndef SANITIZER_LINUX_H #define SANITIZER_LINUX_H +#include "sanitizer_common.h" #include "sanitizer_internal_defs.h" struct sigaltstack; @@ -43,7 +44,7 @@ class ThreadLister { int pid_; int descriptor_; - char buffer_[4096]; + InternalScopedBuffer buffer_; bool error_; struct linux_dirent* entry_; int bytes_read_; diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_linux.cc b/compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_linux.cc index 05da7fb0ebd1..8bb155588cdc 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_linux.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_linux.cc @@ -148,27 +148,24 @@ void ThreadSuspender::KillAllThreads() { } bool ThreadSuspender::SuspendAllThreads() { - void *mem = InternalAlloc(sizeof(ThreadLister)); - ThreadLister *thread_lister = new(mem) ThreadLister(pid_); + ThreadLister thread_lister(pid_); bool added_threads; do { // Run through the directory entries once. added_threads = false; - pid_t tid = thread_lister->GetNextTID(); + pid_t tid = thread_lister.GetNextTID(); while (tid >= 0) { if (SuspendThread(tid)) added_threads = true; - tid = thread_lister->GetNextTID(); + tid = thread_lister.GetNextTID(); } - if (thread_lister->error()) { + if (thread_lister.error()) { // Detach threads and fail. ResumeAllThreads(); - InternalFree(mem); return false; } - thread_lister->Reset(); + thread_lister.Reset(); } while (added_threads); - InternalFree(mem); return true; }