1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/security/sandbox/chromium/base/debug/leak_annotations.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,65 @@ 1.4 +// Copyright (c) 2011 The Chromium Authors. All rights reserved. 1.5 +// Use of this source code is governed by a BSD-style license that can be 1.6 +// found in the LICENSE file. 1.7 + 1.8 +#ifndef BASE_DEBUG_LEAK_ANNOTATIONS_H_ 1.9 +#define BASE_DEBUG_LEAK_ANNOTATIONS_H_ 1.10 + 1.11 +#include "build/build_config.h" 1.12 + 1.13 +// This file defines macros which can be used to annotate intentional memory 1.14 +// leaks. Support for annotations is implemented in HeapChecker and 1.15 +// LeakSanitizer. Annotated objects will be treated as a source of live 1.16 +// pointers, i.e. any heap objects reachable by following pointers from an 1.17 +// annotated object will not be reported as leaks. 1.18 +// 1.19 +// ANNOTATE_SCOPED_MEMORY_LEAK: all allocations made in the current scope 1.20 +// will be annotated as leaks. 1.21 +// ANNOTATE_LEAKING_OBJECT_PTR(X): the heap object referenced by pointer X will 1.22 +// be annotated as a leak. 1.23 +// 1.24 +// Note that HeapChecker will report a fatal error if an object which has been 1.25 +// annotated with ANNOTATE_LEAKING_OBJECT_PTR is later deleted (but 1.26 +// LeakSanitizer won't). 1.27 + 1.28 +#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_NACL) && \ 1.29 + defined(USE_HEAPCHECKER) 1.30 + 1.31 +#include "third_party/tcmalloc/chromium/src/gperftools/heap-checker.h" 1.32 + 1.33 +#define ANNOTATE_SCOPED_MEMORY_LEAK \ 1.34 + HeapLeakChecker::Disabler heap_leak_checker_disabler; static_cast<void>(0) 1.35 + 1.36 +#define ANNOTATE_LEAKING_OBJECT_PTR(X) \ 1.37 + HeapLeakChecker::IgnoreObject(X) 1.38 + 1.39 +#elif defined(LEAK_SANITIZER) && !defined(OS_NACL) 1.40 + 1.41 +extern "C" { 1.42 +void __lsan_disable(); 1.43 +void __lsan_enable(); 1.44 +void __lsan_ignore_object(const void *p); 1.45 +} // extern "C" 1.46 + 1.47 +class ScopedLeakSanitizerDisabler { 1.48 + public: 1.49 + ScopedLeakSanitizerDisabler() { __lsan_disable(); } 1.50 + ~ScopedLeakSanitizerDisabler() { __lsan_enable(); } 1.51 + private: 1.52 + DISALLOW_COPY_AND_ASSIGN(ScopedLeakSanitizerDisabler); 1.53 +}; 1.54 + 1.55 +#define ANNOTATE_SCOPED_MEMORY_LEAK \ 1.56 + ScopedLeakSanitizerDisabler leak_sanitizer_disabler; static_cast<void>(0) 1.57 + 1.58 +#define ANNOTATE_LEAKING_OBJECT_PTR(X) __lsan_ignore_object(X); 1.59 + 1.60 +#else 1.61 + 1.62 +// If neither HeapChecker nor LSan are used, the annotations should be no-ops. 1.63 +#define ANNOTATE_SCOPED_MEMORY_LEAK ((void)0) 1.64 +#define ANNOTATE_LEAKING_OBJECT_PTR(X) ((void)0) 1.65 + 1.66 +#endif 1.67 + 1.68 +#endif // BASE_DEBUG_LEAK_ANNOTATIONS_H_