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