]> git.ipfire.org Git - thirdparty/gcc.git/blame - libsanitizer/include/sanitizer/tsan_interface.h
Update merge script and HOWTO_MERGE documentation.
[thirdparty/gcc.git] / libsanitizer / include / sanitizer / tsan_interface.h
CommitLineData
5d3805fc
JJ
1//===-- tsan_interface.h ----------------------------------------*- C++ -*-===//
2//
3// This file is distributed under the University of Illinois Open Source
4// License. See LICENSE.TXT for details.
5//
6//===----------------------------------------------------------------------===//
7//
8// This file is a part of ThreadSanitizer (TSan), a race detector.
9//
10// Public interface header for TSan.
11//===----------------------------------------------------------------------===//
12#ifndef SANITIZER_TSAN_INTERFACE_H
13#define SANITIZER_TSAN_INTERFACE_H
14
15#include <sanitizer/common_interface_defs.h>
16
17#ifdef __cplusplus
18extern "C" {
19#endif
20
21// __tsan_release establishes a happens-before relation with a preceding
22// __tsan_acquire on the same address.
23void __tsan_acquire(void *addr);
24void __tsan_release(void *addr);
25
26// Annotations for custom mutexes.
27// The annotations allow to get better reports (with sets of locked mutexes),
28// detect more types of bugs (e.g. mutex misuses, races between lock/unlock and
29// destruction and potential deadlocks) and improve precision and performance
30// (by ignoring individual atomic operations in mutex code). However, the
31// downside is that annotated mutex code itself is not checked for correctness.
32
33// Mutex creation flags are passed to __tsan_mutex_create annotation.
34// If mutex has no constructor and __tsan_mutex_create is not called,
35// the flags may be passed to __tsan_mutex_pre_lock/__tsan_mutex_post_lock
36// annotations.
37
38// Mutex has static storage duration and no-op constructor and destructor.
39// This effectively makes tsan ignore destroy annotation.
40const unsigned __tsan_mutex_linker_init = 1 << 0;
41// Mutex is write reentrant.
42const unsigned __tsan_mutex_write_reentrant = 1 << 1;
43// Mutex is read reentrant.
44const unsigned __tsan_mutex_read_reentrant = 1 << 2;
45
46// Mutex operation flags:
47
48// Denotes read lock operation.
49const unsigned __tsan_mutex_read_lock = 1 << 3;
50// Denotes try lock operation.
51const unsigned __tsan_mutex_try_lock = 1 << 4;
52// Denotes that a try lock operation has failed to acquire the mutex.
53const unsigned __tsan_mutex_try_lock_failed = 1 << 5;
54// Denotes that the lock operation acquires multiple recursion levels.
55// Number of levels is passed in recursion parameter.
56// This is useful for annotation of e.g. Java builtin monitors,
57// for which wait operation releases all recursive acquisitions of the mutex.
58const unsigned __tsan_mutex_recursive_lock = 1 << 6;
59// Denotes that the unlock operation releases all recursion levels.
60// Number of released levels is returned and later must be passed to
61// the corresponding __tsan_mutex_post_lock annotation.
62const unsigned __tsan_mutex_recursive_unlock = 1 << 7;
63
64// Annotate creation of a mutex.
65// Supported flags: mutex creation flags.
66void __tsan_mutex_create(void *addr, unsigned flags);
67
68// Annotate destruction of a mutex.
69// Supported flags:
70// - __tsan_mutex_linker_init
71void __tsan_mutex_destroy(void *addr, unsigned flags);
72
73// Annotate start of lock operation.
74// Supported flags:
75// - __tsan_mutex_read_lock
76// - __tsan_mutex_try_lock
77// - all mutex creation flags
78void __tsan_mutex_pre_lock(void *addr, unsigned flags);
79
80// Annotate end of lock operation.
81// Supported flags:
82// - __tsan_mutex_read_lock (must match __tsan_mutex_pre_lock)
83// - __tsan_mutex_try_lock (must match __tsan_mutex_pre_lock)
84// - __tsan_mutex_try_lock_failed
85// - __tsan_mutex_recursive_lock
86// - all mutex creation flags
87void __tsan_mutex_post_lock(void *addr, unsigned flags, int recursion);
88
89// Annotate start of unlock operation.
90// Supported flags:
91// - __tsan_mutex_read_lock
92// - __tsan_mutex_recursive_unlock
93int __tsan_mutex_pre_unlock(void *addr, unsigned flags);
94
95// Annotate end of unlock operation.
96// Supported flags:
97// - __tsan_mutex_read_lock (must match __tsan_mutex_pre_unlock)
98void __tsan_mutex_post_unlock(void *addr, unsigned flags);
99
100// Annotate start/end of notify/signal/broadcast operation.
101// Supported flags: none.
102void __tsan_mutex_pre_signal(void *addr, unsigned flags);
103void __tsan_mutex_post_signal(void *addr, unsigned flags);
104
105// Annotate start/end of a region of code where lock/unlock/signal operation
106// diverts to do something else unrelated to the mutex. This can be used to
107// annotate, for example, calls into cooperative scheduler or contention
108// profiling code.
109// These annotations must be called only from within
110// __tsan_mutex_pre/post_lock, __tsan_mutex_pre/post_unlock,
111// __tsan_mutex_pre/post_signal regions.
112// Supported flags: none.
113void __tsan_mutex_pre_divert(void *addr, unsigned flags);
114void __tsan_mutex_post_divert(void *addr, unsigned flags);
115
116// External race detection API.
117// Can be used by non-instrumented libraries to detect when their objects are
118// being used in an unsafe manner.
119// - __tsan_external_read/__tsan_external_write annotates the logical reads
120// and writes of the object at the specified address. 'caller_pc' should
121// be the PC of the library user, which the library can obtain with e.g.
122// `__builtin_return_address(0)`.
123// - __tsan_external_register_tag registers a 'tag' with the specified name,
124// which is later used in read/write annotations to denote the object type
125// - __tsan_external_assign_tag can optionally mark a heap object with a tag
126void *__tsan_external_register_tag(const char *object_type);
127void __tsan_external_register_header(void *tag, const char *header);
128void __tsan_external_assign_tag(void *addr, void *tag);
129void __tsan_external_read(void *addr, void *caller_pc, void *tag);
130void __tsan_external_write(void *addr, void *caller_pc, void *tag);
131
132#ifdef __cplusplus
133} // extern "C"
134#endif
135
136#endif // SANITIZER_TSAN_INTERFACE_H