File: tsan.h

package info (click to toggle)
ocaml 5.3.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 43,124 kB
  • sloc: ml: 355,439; ansic: 51,636; sh: 25,098; asm: 5,413; makefile: 3,673; python: 919; javascript: 273; awk: 253; perl: 59; fortran: 21; cs: 9
file content (97 lines) | stat: -rw-r--r-- 3,520 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/**************************************************************************/
/*                                                                        */
/*                                 OCaml                                  */
/*                                                                        */
/*               Fabrice Buoro and Olivier Nicole, Tarides                */
/*                                                                        */
/*   Copyright 2023 Tarides                                               */
/*                                                                        */
/*   All rights reserved.  This file is distributed under the terms of    */
/*   the GNU Lesser General Public License version 2.1, with the          */
/*   special exception on linking described in the file LICENSE.          */
/*                                                                        */
/**************************************************************************/

#ifndef CAML_TSAN_H
#define CAML_TSAN_H

#ifdef __cplusplus
extern "C" {
#endif

/* Macro used to deactivate thread sanitizer on some functions. */
#define CAMLno_tsan
/* __has_feature is Clang-specific, but GCC defines __SANITIZE_ADDRESS__ and
 * __SANITIZE_THREAD__. */
#if defined(__has_feature)
#  if __has_feature(thread_sanitizer)
#    undef CAMLno_tsan
#    if defined(__has_attribute)
#      if __has_attribute(disable_sanitizer_instrumentation)
#        define CAMLno_tsan \
           __attribute__((disable_sanitizer_instrumentation))
#      else
#        define CAMLno_tsan __attribute__((no_sanitize("thread")))
#      endif
#    else
#      define CAMLno_tsan __attribute__((no_sanitize("thread")))
#    endif
#  endif
#else
#  if defined(__SANITIZE_THREAD__)
#    undef CAMLno_tsan
#    define CAMLno_tsan __attribute__((no_sanitize_thread))
#  endif
#endif

/* TSan records a release operation on encountering ANNOTATE_HAPPENS_BEFORE
 * and similarly an acquire operation on encountering ANNOTATE_HAPPENS_AFTER.
   These annotations are used to eliminate false positives. */
#define CAML_TSAN_ANNOTATE_HAPPENS_BEFORE(addr)
#define CAML_TSAN_ANNOTATE_HAPPENS_AFTER(addr)

#if defined(WITH_THREAD_SANITIZER)
#  undef CAML_TSAN_ANNOTATE_HAPPENS_BEFORE
#  undef CAML_TSAN_ANNOTATE_HAPPENS_AFTER

#  define CAML_TSAN_ANNOTATE_HAPPENS_BEFORE(addr)              \
  AnnotateHappensBefore(__FILE__, __LINE__, (void *)(addr));
#  define CAML_TSAN_ANNOTATE_HAPPENS_AFTER(addr)               \
  AnnotateHappensAfter(__FILE__, __LINE__, (void *)(addr));

extern void AnnotateHappensBefore(const char *f, int l, void *addr);
extern void AnnotateHappensAfter(const char *f, int l, void *addr);
#endif

/* Macro used to un-instrument some functions of the runtime for performance
   reasons, except if TSAN_INSTRUMENT_ALL is set. */
#if defined(TSAN_INSTRUMENT_ALL)
#  define CAMLno_tsan_for_perf
#else
#  define CAMLno_tsan_for_perf CAMLno_tsan
#endif

#ifdef __cplusplus
}
#endif

#ifdef CAML_INTERNALS

#include "mlvalues.h"

struct stack_info;

CAMLextern void caml_tsan_exit_on_raise(uintnat pc, char* sp, char* trapsp);
CAMLextern void caml_tsan_exit_on_raise_c(char* limit);

CAMLextern void caml_tsan_exit_on_perform(uintnat pc, char* sp);
CAMLextern void caml_tsan_entry_on_resume(uintnat pc, char* sp,
    struct stack_info const* stack);

extern void __tsan_func_exit(void*);
extern void __tsan_func_entry(void*);
void __tsan_write8(void *location);

#endif /* CAML_INTERNALS */

#endif /* CAML_TSAN_H */