Move __tsan::Vector to __sanitizer
Summary: The low-fat STL-like vector container will be reused in MSan. It is needed to implement an atexit(3) interceptor on NetBSD/amd64 in MSan. Sponsored by <The NetBSD Foundation> Reviewers: joerg, dvyukov, eugenis, vitalybuka, kcc Reviewed By: dvyukov Subscribers: kubamracek, mgorny, llvm-commits, #sanitizers Tags: #sanitizers Differential Revision: https://reviews.llvm.org/D40726 llvm-svn: 319650
This commit is contained in:
parent
7cd4db94f8
commit
64fc9cf2e5
|
@ -140,6 +140,7 @@ set(SANITIZER_HEADERS
|
|||
sanitizer_syscall_linux_x86_64.inc
|
||||
sanitizer_syscall_linux_aarch64.inc
|
||||
sanitizer_thread_registry.h
|
||||
sanitizer_vector.h
|
||||
sanitizer_win.h)
|
||||
|
||||
include_directories(..)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
//===-- tsan_vector.h -------------------------------------------*- C++ -*-===//
|
||||
//===-- sanitizer_vector.h -------------------------------------*- C++ -*-===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
|
@ -7,38 +7,37 @@
|
|||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file is a part of ThreadSanitizer (TSan), a race detector.
|
||||
// This file is shared between sanitizers run-time libraries.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// Low-fat STL-like vector container.
|
||||
|
||||
#ifndef TSAN_VECTOR_H
|
||||
#define TSAN_VECTOR_H
|
||||
#ifndef SANITIZER_VECTOR_H
|
||||
#define SANITIZER_VECTOR_H
|
||||
|
||||
#include "tsan_defs.h"
|
||||
#include "tsan_mman.h"
|
||||
#include "sanitizer_common/sanitizer_allocator_internal.h"
|
||||
#include "sanitizer_common/sanitizer_libc.h"
|
||||
|
||||
namespace __tsan {
|
||||
namespace __sanitizer {
|
||||
|
||||
template<typename T>
|
||||
class Vector {
|
||||
public:
|
||||
explicit Vector(MBlockType typ)
|
||||
: typ_(typ)
|
||||
, begin_()
|
||||
explicit Vector()
|
||||
: begin_()
|
||||
, end_()
|
||||
, last_() {
|
||||
}
|
||||
|
||||
~Vector() {
|
||||
if (begin_)
|
||||
internal_free(begin_);
|
||||
InternalFree(begin_);
|
||||
}
|
||||
|
||||
void Reset() {
|
||||
if (begin_)
|
||||
internal_free(begin_);
|
||||
InternalFree(begin_);
|
||||
begin_ = 0;
|
||||
end_ = 0;
|
||||
last_ = 0;
|
||||
|
@ -91,7 +90,6 @@ class Vector {
|
|||
}
|
||||
|
||||
private:
|
||||
const MBlockType typ_;
|
||||
T *begin_;
|
||||
T *end_;
|
||||
T *last_;
|
||||
|
@ -109,10 +107,10 @@ class Vector {
|
|||
cap = 16;
|
||||
if (cap < size)
|
||||
cap = size;
|
||||
T *p = (T*)internal_alloc(typ_, cap * sizeof(T));
|
||||
T *p = (T*)InternalAlloc(cap * sizeof(T));
|
||||
if (cap0) {
|
||||
internal_memcpy(p, begin_, cap0 * sizeof(T));
|
||||
internal_free(begin_);
|
||||
InternalFree(begin_);
|
||||
}
|
||||
begin_ = p;
|
||||
end_ = begin_ + size;
|
||||
|
@ -122,6 +120,6 @@ class Vector {
|
|||
Vector(const Vector&);
|
||||
void operator=(const Vector&);
|
||||
};
|
||||
} // namespace __tsan
|
||||
} // namespace __sanitizer
|
||||
|
||||
#endif // #ifndef TSAN_VECTOR_H
|
||||
#endif // #ifndef SANITIZER_VECTOR_H
|
|
@ -34,7 +34,8 @@ set(SANITIZER_UNITTESTS
|
|||
sanitizer_suppressions_test.cc
|
||||
sanitizer_symbolizer_test.cc
|
||||
sanitizer_test_main.cc
|
||||
sanitizer_thread_registry_test.cc)
|
||||
sanitizer_thread_registry_test.cc
|
||||
sanitizer_vector_test.cc)
|
||||
|
||||
set(SANITIZER_TEST_HEADERS
|
||||
sanitizer_pthread_wrappers.h
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
//===-- tsan_vector_test.cc -----------------------------------------------===//
|
||||
//===-- sanitizer_vector_test.cc ------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
|
@ -7,17 +7,16 @@
|
|||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file is a part of ThreadSanitizer (TSan), a race detector.
|
||||
// This file is a part of *Sanitizer runtime.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
#include "tsan_vector.h"
|
||||
#include "tsan_rtl.h"
|
||||
#include "sanitizer_common/sanitizer_vector.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace __tsan {
|
||||
namespace __sanitizer {
|
||||
|
||||
TEST(Vector, Basic) {
|
||||
Vector<int> v(MBlockScopedBuf);
|
||||
Vector<int> v;
|
||||
EXPECT_EQ(v.Size(), (uptr)0);
|
||||
v.PushBack(42);
|
||||
EXPECT_EQ(v.Size(), (uptr)1);
|
||||
|
@ -29,7 +28,7 @@ TEST(Vector, Basic) {
|
|||
}
|
||||
|
||||
TEST(Vector, Stride) {
|
||||
Vector<int> v(MBlockScopedBuf);
|
||||
Vector<int> v;
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
v.PushBack(i);
|
||||
EXPECT_EQ(v.Size(), (uptr)(i + 1));
|
||||
|
@ -40,4 +39,4 @@ TEST(Vector, Stride) {
|
|||
}
|
||||
}
|
||||
|
||||
} // namespace __tsan
|
||||
} // namespace __sanitizer
|
|
@ -93,8 +93,7 @@ set(TSAN_HEADERS
|
|||
rtl/tsan_symbolize.h
|
||||
rtl/tsan_sync.h
|
||||
rtl/tsan_trace.h
|
||||
rtl/tsan_update_shadow_word_inl.h
|
||||
rtl/tsan_vector.h)
|
||||
rtl/tsan_update_shadow_word_inl.h)
|
||||
|
||||
set(TSAN_RUNTIME_LIBRARIES)
|
||||
add_compiler_rt_component(tsan)
|
||||
|
|
|
@ -200,7 +200,7 @@ struct InterceptorContext {
|
|||
Vector<struct AtExitCtx *> AtExitStack;
|
||||
|
||||
InterceptorContext()
|
||||
: libignore(LINKER_INITIALIZED), AtExitStack(MBlockAtExit) {
|
||||
: libignore(LINKER_INITIALIZED), AtExitStack() {
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include "sanitizer_common/sanitizer_internal_defs.h"
|
||||
#include "sanitizer_common/sanitizer_placement_new.h"
|
||||
#include "sanitizer_common/sanitizer_stacktrace.h"
|
||||
#include "sanitizer_common/sanitizer_vector.h"
|
||||
#include "tsan_interface_ann.h"
|
||||
#include "tsan_mutex.h"
|
||||
#include "tsan_report.h"
|
||||
|
@ -21,7 +22,6 @@
|
|||
#include "tsan_mman.h"
|
||||
#include "tsan_flags.h"
|
||||
#include "tsan_platform.h"
|
||||
#include "tsan_vector.h"
|
||||
|
||||
#define CALLERPC ((uptr)__builtin_return_address(0))
|
||||
|
||||
|
@ -185,10 +185,10 @@ void PrintMatchedBenignRaces() {
|
|||
int unique_count = 0;
|
||||
int hit_count = 0;
|
||||
int add_count = 0;
|
||||
Vector<ExpectRace> hit_matched(MBlockScopedBuf);
|
||||
Vector<ExpectRace> hit_matched;
|
||||
CollectMatchedBenignRaces(&hit_matched, &unique_count, &hit_count,
|
||||
&ExpectRace::hitcount);
|
||||
Vector<ExpectRace> add_matched(MBlockScopedBuf);
|
||||
Vector<ExpectRace> add_matched;
|
||||
CollectMatchedBenignRaces(&add_matched, &unique_count, &add_count,
|
||||
&ExpectRace::addcount);
|
||||
if (hit_matched.Size()) {
|
||||
|
|
|
@ -48,18 +48,18 @@ class Decorator: public __sanitizer::SanitizerCommonDecorator {
|
|||
|
||||
ReportDesc::ReportDesc()
|
||||
: tag(kExternalTagNone)
|
||||
, stacks(MBlockReportStack)
|
||||
, mops(MBlockReportMop)
|
||||
, locs(MBlockReportLoc)
|
||||
, mutexes(MBlockReportMutex)
|
||||
, threads(MBlockReportThread)
|
||||
, unique_tids(MBlockReportThread)
|
||||
, stacks()
|
||||
, mops()
|
||||
, locs()
|
||||
, mutexes()
|
||||
, threads()
|
||||
, unique_tids()
|
||||
, sleep()
|
||||
, count() {
|
||||
}
|
||||
|
||||
ReportMop::ReportMop()
|
||||
: mset(MBlockReportMutex) {
|
||||
: mset() {
|
||||
}
|
||||
|
||||
ReportDesc::~ReportDesc() {
|
||||
|
|
|
@ -14,8 +14,8 @@
|
|||
#define TSAN_REPORT_H
|
||||
|
||||
#include "sanitizer_common/sanitizer_symbolizer.h"
|
||||
#include "sanitizer_common/sanitizer_vector.h"
|
||||
#include "tsan_defs.h"
|
||||
#include "tsan_vector.h"
|
||||
|
||||
namespace __tsan {
|
||||
|
||||
|
|
|
@ -102,8 +102,8 @@ Context::Context()
|
|||
, thread_registry(new(thread_registry_placeholder) ThreadRegistry(
|
||||
CreateThreadContext, kMaxTid, kThreadQuarantineSize, kMaxTidReuse))
|
||||
, racy_mtx(MutexTypeRacy, StatMtxRacy)
|
||||
, racy_stacks(MBlockRacyStacks)
|
||||
, racy_addresses(MBlockRacyAddresses)
|
||||
, racy_stacks()
|
||||
, racy_addresses()
|
||||
, fired_suppressions_mtx(MutexTypeFired, StatMtxFired)
|
||||
, fired_suppressions(8)
|
||||
, clock_alloc("clock allocator") {
|
||||
|
@ -121,7 +121,7 @@ ThreadState::ThreadState(Context *ctx, int tid, int unique_id, u64 epoch,
|
|||
// , ignore_interceptors()
|
||||
, clock(tid, reuse_count)
|
||||
#if !SANITIZER_GO
|
||||
, jmp_bufs(MBlockJmpBuf)
|
||||
, jmp_bufs()
|
||||
#endif
|
||||
, tid(tid)
|
||||
, unique_id(unique_id)
|
||||
|
|
|
@ -34,12 +34,13 @@
|
|||
#include "sanitizer_common/sanitizer_libignore.h"
|
||||
#include "sanitizer_common/sanitizer_suppressions.h"
|
||||
#include "sanitizer_common/sanitizer_thread_registry.h"
|
||||
#include "sanitizer_common/sanitizer_vector.h"
|
||||
#include "tsan_clock.h"
|
||||
#include "tsan_defs.h"
|
||||
#include "tsan_flags.h"
|
||||
#include "tsan_mman.h"
|
||||
#include "tsan_sync.h"
|
||||
#include "tsan_trace.h"
|
||||
#include "tsan_vector.h"
|
||||
#include "tsan_report.h"
|
||||
#include "tsan_platform.h"
|
||||
#include "tsan_mutexset.h"
|
||||
|
|
|
@ -393,7 +393,7 @@ void RestoreStack(int tid, const u64 epoch, VarSizeStackTrace *stk,
|
|||
const u64 ebegin = RoundDown(eend, kTracePartSize);
|
||||
DPrintf("#%d: RestoreStack epoch=%zu ebegin=%zu eend=%zu partidx=%d\n",
|
||||
tid, (uptr)epoch, (uptr)ebegin, (uptr)eend, partidx);
|
||||
Vector<uptr> stack(MBlockReportStack);
|
||||
Vector<uptr> stack;
|
||||
stack.Resize(hdr->stack0.size + 64);
|
||||
for (uptr i = 0; i < hdr->stack0.size; i++) {
|
||||
stack[i] = hdr->stack0.trace[i];
|
||||
|
@ -659,7 +659,7 @@ void ReportRace(ThreadState *thr) {
|
|||
return;
|
||||
|
||||
// MutexSet is too large to live on stack.
|
||||
Vector<u64> mset_buffer(MBlockScopedBuf);
|
||||
Vector<u64> mset_buffer;
|
||||
mset_buffer.Resize(sizeof(MutexSet) / sizeof(u64) + 1);
|
||||
MutexSet *mset2 = new(&mset_buffer[0]) MutexSet();
|
||||
|
||||
|
|
|
@ -211,7 +211,7 @@ void ThreadFinalize(ThreadState *thr) {
|
|||
if (!flags()->report_thread_leaks)
|
||||
return;
|
||||
ThreadRegistryLock l(ctx->thread_registry);
|
||||
Vector<ThreadLeak> leaks(MBlockScopedBuf);
|
||||
Vector<ThreadLeak> leaks;
|
||||
ctx->thread_registry->RunCallbackForEachThreadLocked(
|
||||
MaybeReportThreadLeak, &leaks);
|
||||
for (uptr i = 0; i < leaks.Size(); i++) {
|
||||
|
|
|
@ -6,8 +6,7 @@ set(TSAN_UNIT_TEST_SOURCES
|
|||
tsan_shadow_test.cc
|
||||
tsan_stack_test.cc
|
||||
tsan_sync_test.cc
|
||||
tsan_unit_test_main.cc
|
||||
tsan_vector_test.cc)
|
||||
tsan_unit_test_main.cc)
|
||||
|
||||
add_tsan_unittest(TsanUnitTest
|
||||
SOURCES ${TSAN_UNIT_TEST_SOURCES})
|
||||
|
|
Loading…
Reference in New Issue