blob: af94452719b1cc919c3d39c75463ae95de3e05bf [file] [log] [blame]
Brian Silverman20350ac2021-11-17 18:19:55 -08001/* -*- Mode: c; c-basic-offset: 2; indent-tabs-mode: nil -*- */
Austin Schuh745610d2015-09-06 18:19:50 -07002/* Copyright (c) 2008, Google Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the
14 * distribution.
15 * * Neither the name of Google Inc. nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 *
31 * ---
32 * Author: Kostya Serebryany
33 */
34
35/* This file defines dynamic annotations for use with dynamic analysis
36 tool such as valgrind, PIN, etc.
37
38 Dynamic annotation is a source code annotation that affects
39 the generated code (that is, the annotation is not a comment).
40 Each such annotation is attached to a particular
41 instruction and/or to a particular object (address) in the program.
42
43 The annotations that should be used by users are macros in all upper-case
44 (e.g., ANNOTATE_NEW_MEMORY).
45
46 Actual implementation of these macros may differ depending on the
47 dynamic analysis tool being used.
48
49 See http://code.google.com/p/data-race-test/ for more information.
50
51 This file supports the following dynamic analysis tools:
52 - None (DYNAMIC_ANNOTATIONS_ENABLED is not defined or zero).
53 Macros are defined empty.
54 - ThreadSanitizer, Helgrind, DRD (DYNAMIC_ANNOTATIONS_ENABLED is 1).
55 Macros are defined as calls to non-inlinable empty functions
56 that are intercepted by Valgrind. */
57
58#ifndef BASE_DYNAMIC_ANNOTATIONS_H_
59#define BASE_DYNAMIC_ANNOTATIONS_H_
60
Austin Schuh745610d2015-09-06 18:19:50 -070061#ifdef __cplusplus
62extern "C" {
63#endif
Austin Schuh745610d2015-09-06 18:19:50 -070064
65/* Return non-zero value if running under valgrind.
66
67 If "valgrind.h" is included into dynamic_annotations.c,
68 the regular valgrind mechanism will be used.
69 See http://valgrind.org/docs/manual/manual-core-adv.html about
70 RUNNING_ON_VALGRIND and other valgrind "client requests".
71 The file "valgrind.h" may be obtained by doing
72 svn co svn://svn.valgrind.org/valgrind/trunk/include
73
74 If for some reason you can't use "valgrind.h" or want to fake valgrind,
75 there are two ways to make this function return non-zero:
76 - Use environment variable: export RUNNING_ON_VALGRIND=1
77 - Make your tool intercept the function RunningOnValgrind() and
78 change its return value.
79 */
80int RunningOnValgrind(void);
81
Austin Schuh745610d2015-09-06 18:19:50 -070082#ifdef __cplusplus
83}
84#endif
85
Austin Schuh745610d2015-09-06 18:19:50 -070086#endif /* BASE_DYNAMIC_ANNOTATIONS_H_ */