Wed, 31 Dec 2014 06:55:50 +0100
Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2
michael@0 | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
michael@0 | 2 | // Use of this source code is governed by a BSD-style license that can be |
michael@0 | 3 | // found in the LICENSE file. |
michael@0 | 4 | |
michael@0 | 5 | #ifndef BASE_DEBUG_LEAK_ANNOTATIONS_H_ |
michael@0 | 6 | #define BASE_DEBUG_LEAK_ANNOTATIONS_H_ |
michael@0 | 7 | |
michael@0 | 8 | #include "build/build_config.h" |
michael@0 | 9 | |
michael@0 | 10 | // This file defines macros which can be used to annotate intentional memory |
michael@0 | 11 | // leaks. Support for annotations is implemented in HeapChecker and |
michael@0 | 12 | // LeakSanitizer. Annotated objects will be treated as a source of live |
michael@0 | 13 | // pointers, i.e. any heap objects reachable by following pointers from an |
michael@0 | 14 | // annotated object will not be reported as leaks. |
michael@0 | 15 | // |
michael@0 | 16 | // ANNOTATE_SCOPED_MEMORY_LEAK: all allocations made in the current scope |
michael@0 | 17 | // will be annotated as leaks. |
michael@0 | 18 | // ANNOTATE_LEAKING_OBJECT_PTR(X): the heap object referenced by pointer X will |
michael@0 | 19 | // be annotated as a leak. |
michael@0 | 20 | // |
michael@0 | 21 | // Note that HeapChecker will report a fatal error if an object which has been |
michael@0 | 22 | // annotated with ANNOTATE_LEAKING_OBJECT_PTR is later deleted (but |
michael@0 | 23 | // LeakSanitizer won't). |
michael@0 | 24 | |
michael@0 | 25 | #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_NACL) && \ |
michael@0 | 26 | defined(USE_HEAPCHECKER) |
michael@0 | 27 | |
michael@0 | 28 | #include "third_party/tcmalloc/chromium/src/gperftools/heap-checker.h" |
michael@0 | 29 | |
michael@0 | 30 | #define ANNOTATE_SCOPED_MEMORY_LEAK \ |
michael@0 | 31 | HeapLeakChecker::Disabler heap_leak_checker_disabler; static_cast<void>(0) |
michael@0 | 32 | |
michael@0 | 33 | #define ANNOTATE_LEAKING_OBJECT_PTR(X) \ |
michael@0 | 34 | HeapLeakChecker::IgnoreObject(X) |
michael@0 | 35 | |
michael@0 | 36 | #elif defined(LEAK_SANITIZER) && !defined(OS_NACL) |
michael@0 | 37 | |
michael@0 | 38 | extern "C" { |
michael@0 | 39 | void __lsan_disable(); |
michael@0 | 40 | void __lsan_enable(); |
michael@0 | 41 | void __lsan_ignore_object(const void *p); |
michael@0 | 42 | } // extern "C" |
michael@0 | 43 | |
michael@0 | 44 | class ScopedLeakSanitizerDisabler { |
michael@0 | 45 | public: |
michael@0 | 46 | ScopedLeakSanitizerDisabler() { __lsan_disable(); } |
michael@0 | 47 | ~ScopedLeakSanitizerDisabler() { __lsan_enable(); } |
michael@0 | 48 | private: |
michael@0 | 49 | DISALLOW_COPY_AND_ASSIGN(ScopedLeakSanitizerDisabler); |
michael@0 | 50 | }; |
michael@0 | 51 | |
michael@0 | 52 | #define ANNOTATE_SCOPED_MEMORY_LEAK \ |
michael@0 | 53 | ScopedLeakSanitizerDisabler leak_sanitizer_disabler; static_cast<void>(0) |
michael@0 | 54 | |
michael@0 | 55 | #define ANNOTATE_LEAKING_OBJECT_PTR(X) __lsan_ignore_object(X); |
michael@0 | 56 | |
michael@0 | 57 | #else |
michael@0 | 58 | |
michael@0 | 59 | // If neither HeapChecker nor LSan are used, the annotations should be no-ops. |
michael@0 | 60 | #define ANNOTATE_SCOPED_MEMORY_LEAK ((void)0) |
michael@0 | 61 | #define ANNOTATE_LEAKING_OBJECT_PTR(X) ((void)0) |
michael@0 | 62 | |
michael@0 | 63 | #endif |
michael@0 | 64 | |
michael@0 | 65 | #endif // BASE_DEBUG_LEAK_ANNOTATIONS_H_ |