forked from OSchip/llvm-project
[lsan] GetUserBegin() in LSan.
Separate the notions of user-visible chunk and allocator chunk, to facilitate ASan integration. llvm-svn: 182256
This commit is contained in:
parent
67c918a424
commit
bcfd838bcb
|
@ -146,6 +146,10 @@ void *PointsIntoChunk(void* p) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
void *GetUserBegin(void *p) {
|
||||
return p;
|
||||
}
|
||||
|
||||
LsanMetadata::LsanMetadata(void *chunk) {
|
||||
metadata_ = Metadata(chunk);
|
||||
CHECK(metadata_);
|
||||
|
|
|
@ -177,6 +177,7 @@ static void FloodFillReachable(InternalVector<uptr> *frontier) {
|
|||
|
||||
// Mark leaked chunks which are reachable from other leaked chunks.
|
||||
void MarkIndirectlyLeakedCb::operator()(void *p) const {
|
||||
p = GetUserBegin(p);
|
||||
LsanMetadata m(p);
|
||||
if (m.allocated() && m.tag() != kReachable) {
|
||||
ScanRangeForPointers(reinterpret_cast<uptr>(p),
|
||||
|
@ -205,6 +206,7 @@ static void ClassifyAllChunks(SuspendedThreadsList const &suspended_threads) {
|
|||
}
|
||||
|
||||
void ClearTagCb::operator()(void *p) const {
|
||||
p = GetUserBegin(p);
|
||||
LsanMetadata m(p);
|
||||
m.set_tag(kDirectlyLeaked);
|
||||
}
|
||||
|
@ -228,6 +230,7 @@ static void LockAndSuspendThreads(StopTheWorldCallback callback, void *arg) {
|
|||
///// Normal leak checking. /////
|
||||
|
||||
void CollectLeaksCb::operator()(void *p) const {
|
||||
p = GetUserBegin(p);
|
||||
LsanMetadata m(p);
|
||||
if (!m.allocated()) return;
|
||||
if (m.tag() != kReachable) {
|
||||
|
@ -249,6 +252,7 @@ static void CollectLeaks(LeakReport *leak_report) {
|
|||
}
|
||||
|
||||
void PrintLeakedCb::operator()(void *p) const {
|
||||
p = GetUserBegin(p);
|
||||
LsanMetadata m(p);
|
||||
if (!m.allocated()) return;
|
||||
if (m.tag() != kReachable) {
|
||||
|
@ -291,6 +295,7 @@ void DoLeakCheck() {
|
|||
///// Reporting of leaked blocks' addresses (for testing). /////
|
||||
|
||||
void ReportLeakedCb::operator()(void *p) const {
|
||||
p = GetUserBegin(p);
|
||||
LsanMetadata m(p);
|
||||
if (m.allocated() && m.tag() != kReachable)
|
||||
leaked_->push_back(p);
|
||||
|
|
|
@ -170,11 +170,14 @@ bool GetThreadRangesLocked(uptr os_id, uptr *stack_begin, uptr *stack_end,
|
|||
uptr *tls_begin, uptr *tls_end,
|
||||
uptr *cache_begin, uptr *cache_end);
|
||||
// If p points into a chunk that has been allocated to the user, return its
|
||||
// address. Otherwise, return 0.
|
||||
// user-visible address. Otherwise, return 0.
|
||||
void *PointsIntoChunk(void *p);
|
||||
// Return address of user-visible chunk contained in this allocator chunk.
|
||||
void *GetUserBegin(void *p);
|
||||
// Wrapper for chunk metadata operations.
|
||||
class LsanMetadata {
|
||||
public:
|
||||
// Constructor accepts pointer to user-visible chunk.
|
||||
explicit LsanMetadata(void *chunk);
|
||||
bool allocated() const;
|
||||
ChunkTag tag() const;
|
||||
|
|
Loading…
Reference in New Issue