Merge pull request #1870 from saper/langinfo_h
[mono.git] / mono / utils / checked-build.h
1 /*
2  * checked-build.h: Expensive asserts used when mono is built with --with-checked-build=yes
3  *
4  * Author:
5  *      Rodrigo Kumpera (kumpera@gmail.com)
6  *
7  * (C) 2015 Xamarin
8  */
9
10 #ifndef __CHECKED_BUILD_H__
11 #define __CHECKED_BUILD_H__
12
13 #include <config.h>
14
15 #ifdef CHECKED_BUILD
16
17 /*
18 GC runtime modes rules:
19
20 - GC Safe
21 Can:
22 Call into foreigh functions.
23 Call GC Safe or Neutral modes functions.
24 Read from pinned managed memory.
25
26 Cannot:
27 Touch managed memory (read/write).
28 Be dettached.
29
30 What's good for?
31 Doing blocking calls.
32
33 - GC Unsafe
34 Can:
35 Touch managed memory (read/write).
36 Call GC Unsafe or Neutral modes functions.
37
38 Cannot:
39 Call foreign native code (embedder callbacks, pinvokes, etc)
40 Call into any Blocking functions/syscalls (mutexes, IO, etc)
41 Be dettached.
42
43 What's good for?
44 Poking into managed memory.
45
46 -- GC Neutral
47 Can:
48 Call other GC Neutral mode functions.
49
50 Cannot:
51 Touch managed memory.
52 Call foreign native code (embedder callbacks, pinvokes, etc)
53 Call into any Blocking functions/syscalls (mutexes, IO, etc)
54 Be dettached.
55
56 What's good for?
57 Functions that can be called from both coop or preept modes.
58
59 */
60
61 #define MONO_REQ_GC_SAFE_MODE do {      \
62         assert_gc_safe_mode (); \
63 } while (0);
64
65 #define MONO_REQ_GC_UNSAFE_MODE do {    \
66         assert_gc_unsafe_mode ();       \
67 } while (0);
68
69 #define MONO_REQ_GC_NEUTRAL_MODE do {   \
70         assert_gc_neutral_mode ();      \
71 } while (0);
72
73 /*
74 This can be called by embedders
75 */
76 #define MONO_REQ_API_ENTRYPOINT
77
78 /*
79 The JIT will generate code that will land on this function
80 */
81 #define MONO_REQ_RUNTIME_ENTRYPOINT
82
83 #define CHECKED_MONO_INIT() do { checked_build_init (); } while (0)
84
85 #define CHECKED_BUILD_THREAD_TRANSITION(transition, info, from_state, suspend_count, next_state, suspend_count_delta) do {      \
86         checked_build_thread_transition (transition, info, from_state, suspend_count, next_state, suspend_count_delta); \
87 } while (0)
88
89 void assert_gc_safe_mode (void);
90 void assert_gc_unsafe_mode (void);
91 void assert_gc_neutral_mode (void);
92
93 void checked_build_init (void);
94 void checked_build_thread_transition(const char *transition, void *info, int from_state, int suspend_count, int next_state, int suspend_count_delta);
95
96 #else
97
98 #define MONO_REQ_GC_SAFE_MODE
99 #define MONO_REQ_GC_UNSAFE_MODE
100 #define MONO_REQ_GC_NEUTRAL_MODE
101 #define MONO_REQ_API_ENTRYPOINT
102 #define MONO_REQ_RUNTIME_ENTRYPOINT
103
104 #define CHECKED_MONO_INIT()
105 #define CHECKED_BUILD_THREAD_TRANSITION(transition, info, from_state, suspend_count, next_state, suspend_count_delta)
106
107 #endif /* CHECKED_BUILD */
108
109 #endif