少年修仙传客户端基础资源
hch
2024-04-01 d01413b00ef631ac20347716b23818b0b811f65f
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
/**
 * \file
 * Expensive asserts used when mono is built with --with-checked-build=yes
 *
 * Author:
 *    Rodrigo Kumpera (kumpera@gmail.com)
 *
 * (C) 2015 Xamarin
 */
 
#ifndef __CHECKED_BUILD_H__
#define __CHECKED_BUILD_H__
 
#include <config.h>
#include <mono/utils/atomic.h>
#include <mono/utils/mono-compiler.h>
#include <mono/utils/mono-publib.h>
 
typedef enum {
    MONO_CHECK_MODE_NONE = 0,
    MONO_CHECK_MODE_GC = 0x1,
    MONO_CHECK_MODE_METADATA = 0x2,
    MONO_CHECK_MODE_THREAD = 0x4,
    MONO_CHECK_MODE_ALL = MONO_CHECK_MODE_GC | MONO_CHECK_MODE_METADATA | MONO_CHECK_MODE_THREAD,
    MONO_CHECK_MODE_UNKNOWN = 0x8
} MonoCheckMode;
 
mono_bool mono_check_mode_enabled (MonoCheckMode query);
 
// This is for metadata writes which we have chosen not to check at the current time.
// Because in principle this should never happen, we still use a macro so that the exemptions will be easier to find, and remove, later.
// The current reason why this is needed is for pointers to constant strings, which the checker cannot verify yet.
#define CHECKED_METADATA_WRITE_PTR_EXEMPT(ptr, val) do { (ptr) = (val); } while (0)
 
#ifdef ENABLE_CHECKED_BUILD
 
#define g_assert_checked g_assert
 
/*
This can be called by embedders
*/
#define MONO_REQ_API_ENTRYPOINT
 
/*
The JIT will generate code that will land on this function
*/
#define MONO_REQ_RUNTIME_ENTRYPOINT
 
#define CHECKED_MONO_INIT() do { checked_build_init (); } while (0)
 
void checked_build_init (void);
 
#else
 
#define g_assert_checked(...)
 
#define MONO_REQ_API_ENTRYPOINT
#define MONO_REQ_RUNTIME_ENTRYPOINT
 
#define CHECKED_MONO_INIT()
 
#endif /* ENABLE_CHECKED_BUILD */
 
#ifdef ENABLE_CHECKED_BUILD_GC
/*
GC runtime modes rules:
 
- GC Safe
Can:
Call into foreigh functions.
Call GC Safe or Neutral modes functions.
Read from pinned managed memory.
 
Cannot:
Touch managed memory (read/write).
Be dettached.
 
What's good for?
Doing blocking calls.
 
- GC Unsafe
Can:
Touch managed memory (read/write).
Call GC Unsafe or Neutral modes functions.
 
Cannot:
Call foreign native code (embedder callbacks, pinvokes, etc)
Call into any Blocking functions/syscalls (mutexes, IO, etc)
Be dettached.
 
What's good for?
Poking into managed memory.
 
-- GC Neutral
Can:
Call other GC Neutral mode functions.
 
Cannot:
Touch managed memory.
Call foreign native code (embedder callbacks, pinvokes, etc)
Call into any Blocking functions/syscalls (mutexes, IO, etc)
Be dettached.
 
What's good for?
Functions that can be called from both coop or preept modes.
 
*/
 
#define MONO_REQ_GC_SAFE_MODE do {    \
    assert_gc_safe_mode (__FILE__, __LINE__);    \
} while (0);
 
#define MONO_REQ_GC_UNSAFE_MODE do {    \
    assert_gc_unsafe_mode (__FILE__, __LINE__);    \
} while (0);
 
#define MONO_REQ_GC_NEUTRAL_MODE do {    \
    assert_gc_neutral_mode (__FILE__, __LINE__);    \
} while (0);
 
/* In a GC critical region, the thread is not allowed to switch to GC safe mode.
 * For example if the thread is about to call a method that will manipulate managed objects.
 * The GC critical region must only occur in unsafe mode.
 */
#define MONO_PREPARE_GC_CRITICAL_REGION                    \
    MONO_REQ_GC_UNSAFE_MODE                        \
    do {                                \
        void* __critical_gc_region_cookie = critical_gc_region_begin()
 
#define MONO_FINISH_GC_CRITICAL_REGION            \
        critical_gc_region_end(__critical_gc_region_cookie);    \
    } while(0)
 
/* Verify that the thread is not currently in a GC critical region. */
#define MONO_REQ_GC_NOT_CRITICAL do {            \
        assert_not_in_gc_critical_region();    \
    } while(0)
 
/* Verify that the thread is currently in a GC critical region. */
#define MONO_REQ_GC_CRITICAL do {            \
        assert_in_gc_critical_region();    \
    } while(0)
 
void assert_gc_safe_mode (const char *file, int lineno);
void assert_gc_unsafe_mode (const char *file, int lineno);
void assert_gc_neutral_mode (const char *file, int lineno);
 
void* critical_gc_region_begin(void);
void critical_gc_region_end(void* token);
void assert_not_in_gc_critical_region(void);
void assert_in_gc_critical_region (void);
 
#else
 
#define MONO_REQ_GC_SAFE_MODE
#define MONO_REQ_GC_UNSAFE_MODE
#define MONO_REQ_GC_NEUTRAL_MODE
 
#define MONO_PREPARE_GC_CRITICAL_REGION
#define MONO_FINISH_GC_CRITICAL_REGION
 
#define MONO_REQ_GC_NOT_CRITICAL
#define MONO_REQ_GC_CRITICAL
 
#endif /* defined(ENABLE_CHECKED_BUILD_GC) */
 
#ifdef ENABLE_CHECKED_BUILD_METADATA
 
// Use when writing a pointer from one image or imageset to another.
#define CHECKED_METADATA_WRITE_PTR(ptr, val) do {    \
    check_metadata_store (&(ptr), (val));    \
    (ptr) = (val);    \
} while (0);
 
// Use when writing a pointer from an image or imageset to itself.
#define CHECKED_METADATA_WRITE_PTR_LOCAL(ptr, val) do {    \
    check_metadata_store_local (&(ptr), (val));    \
    (ptr) = (val);    \
} while (0);
 
// Use when writing a pointer from one image or imageset to another (atomic version).
#define CHECKED_METADATA_WRITE_PTR_ATOMIC(ptr, val) do {    \
    check_metadata_store (&(ptr), (val));    \
    mono_atomic_store_release (&(ptr), (val));    \
} while (0);
 
void check_metadata_store(void *from, void *to);
void check_metadata_store_local(void *from, void *to);
 
#define CHECKED_METADATA_STORE(ptr, val) check_metadata_store ((ptr), (val))
#define CHECKED_METADATA_STORE_LOCAL(ptr, val) check_metadata_store_local ((ptr), (val))
 
#else
 
#define CHECKED_METADATA_WRITE_PTR(ptr, val) do { (ptr) = (val); } while (0)
#define CHECKED_METADATA_WRITE_PTR_LOCAL(ptr, val) do { (ptr) = (val); } while (0)
#define CHECKED_METADATA_WRITE_PTR_ATOMIC(ptr, val) do { mono_atomic_store_release (&(ptr), (val)); } while (0)
 
#define CHECKED_METADATA_STORE(ptr, val) do { (ptr); (val); } while (0)
#define CHECKED_METADATA_STORE_LOCAL(ptr, val) do { (ptr); (val); } while (0)
 
#endif /* defined(ENABLE_CHECKED_BUILD_METADATA) */
 
#ifdef ENABLE_CHECKED_BUILD_THREAD
 
#define CHECKED_BUILD_THREAD_TRANSITION(transition, info, from_state, suspend_count, next_state, suspend_count_delta) do {    \
    checked_build_thread_transition (transition, info, from_state, suspend_count, next_state, suspend_count_delta);    \
} while (0)
 
void checked_build_thread_transition(const char *transition, void *info, int from_state, int suspend_count, int next_state, int suspend_count_delta);
 
G_GNUC_NORETURN MONO_ATTR_FORMAT_PRINTF(1,2) void mono_fatal_with_history(const char *msg, ...);
 
#else
 
#define CHECKED_BUILD_THREAD_TRANSITION(transition, info, from_state, suspend_count, next_state, suspend_count_delta)
 
#define mono_fatal_with_history g_error
 
#endif /* defined(ENABLE_CHECKED_BUILD_THREAD) */
 
#endif /* __CHECKED_BUILD_H__ */