forked from dotnet/android
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinternal-pinvokes.cc
337 lines (278 loc) · 8 KB
/
internal-pinvokes.cc
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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
#include "android-system.hh"
#include "globals.hh"
#include "internal-pinvokes.hh"
#include "jni-remapping.hh"
using namespace xamarin::android;
using namespace xamarin::android::internal;
unsigned int
monodroid_get_log_categories ()
{
return log_categories;
}
int
monodroid_get_system_property (const char *name, char **value)
{
return AndroidSystem::monodroid_get_system_property (name, value);
}
int
monodroid_embedded_assemblies_set_assemblies_prefix (const char *prefix)
{
embeddedAssemblies.set_assemblies_prefix (prefix);
return 0;
}
void
monodroid_log (LogLevel level, LogCategories category, const char *message)
{
switch (level) {
case LogLevel::Verbose:
case LogLevel::Debug:
log_debug_nocheck (category, message);
break;
case LogLevel::Info:
log_info_nocheck (category, message);
break;
case LogLevel::Warn:
case LogLevel::Silent: // warn is always printed
log_warn (category, message);
break;
case LogLevel::Error:
log_error (category, message);
break;
case LogLevel::Fatal:
log_fatal (category, message);
break;
default:
case LogLevel::Unknown:
case LogLevel::Default:
log_info_nocheck (category, message);
break;
}
}
void
monodroid_free (void *ptr)
{
free (ptr);
}
int
_monodroid_max_gref_get ()
{
return static_cast<int>(AndroidSystem::get_max_gref_count ());
}
int
_monodroid_gref_get ()
{
return osBridge.get_gc_gref_count ();
}
void
_monodroid_gref_log (const char *message)
{
osBridge._monodroid_gref_log (message);
}
int
_monodroid_gref_log_new (jobject curHandle, char curType, jobject newHandle, char newType, const char *threadName, int threadId, const char *from, int from_writable)
{
return osBridge._monodroid_gref_log_new (curHandle, curType, newHandle, newType, threadName, threadId, from, from_writable);
}
void
_monodroid_gref_log_delete (jobject handle, char type, const char *threadName, int threadId, const char *from, int from_writable)
{
osBridge._monodroid_gref_log_delete (handle, type, threadName, threadId, from, from_writable);
}
int
_monodroid_weak_gref_get ()
{
return osBridge.get_gc_weak_gref_count ();
}
void
_monodroid_weak_gref_new (jobject curHandle, char curType, jobject newHandle, char newType, const char *threadName, int threadId, const char *from, int from_writable)
{
osBridge._monodroid_weak_gref_new (curHandle, curType, newHandle, newType, threadName, threadId, from, from_writable);
}
void
_monodroid_weak_gref_delete (jobject handle, char type, const char *threadName, int threadId, const char *from, int from_writable)
{
osBridge._monodroid_weak_gref_delete (handle, type, threadName, threadId, from, from_writable);
}
void
_monodroid_lref_log_new (int lrefc, jobject handle, char type, const char *threadName, int threadId, const char *from, int from_writable)
{
osBridge._monodroid_lref_log_new (lrefc, handle, type, threadName, threadId, from, from_writable);
}
void
_monodroid_lref_log_delete (int lrefc, jobject handle, char type, const char *threadName, int threadId, const char *from, int from_writable)
{
osBridge._monodroid_lref_log_delete (lrefc, handle, type, threadName, threadId, from, from_writable);
}
void
_monodroid_gc_wait_for_bridge_processing ()
{
mono_gc_wait_for_bridge_processing ();
}
void
monodroid_clear_gdb_wait ()
{
monodroidRuntime.set_monodroid_gdb_wait (false);
}
void*
_monodroid_get_identity_hash_code (JNIEnv *env, void *v)
{
intptr_t rv = env->CallStaticIntMethod (monodroidRuntime.get_java_class_System (), monodroidRuntime.get_java_class_method_System_identityHashCode (), v);
return (void*) rv;
}
void*
_monodroid_timezone_get_default_id ()
{
JNIEnv *env = osBridge.ensure_jnienv ();
jmethodID getDefault = env->GetStaticMethodID (monodroidRuntime.get_java_class_TimeZone (), "getDefault", "()Ljava/util/TimeZone;");
jmethodID getID = env->GetMethodID (monodroidRuntime.get_java_class_TimeZone (), "getID", "()Ljava/lang/String;");
jobject d = env->CallStaticObjectMethod (monodroidRuntime.get_java_class_TimeZone (), getDefault);
jstring id = reinterpret_cast<jstring> (env->CallObjectMethod (d, getID));
const char *mutf8 = env->GetStringUTFChars (id, nullptr);
if (mutf8 == nullptr) {
log_error (LOG_DEFAULT, "Failed to convert Java TimeZone ID to UTF8 (out of memory?)");
env->DeleteLocalRef (id);
env->DeleteLocalRef (d);
return nullptr;
}
char *def_id = strdup (mutf8);
env->ReleaseStringUTFChars (id, mutf8);
env->DeleteLocalRef (id);
env->DeleteLocalRef (d);
return def_id;
}
void
_monodroid_counters_dump ([[maybe_unused]] const char *format, [[maybe_unused]] va_list args)
{
#if !defined (NET)
monodroidRuntime.dump_counters_v (format, args);
#endif // ndef NET
}
managed_timing_sequence*
monodroid_timing_start (const char *message)
{
if (timing == nullptr)
return nullptr;
managed_timing_sequence *ret = timing->get_available_sequence ();
if (message != nullptr) {
log_write (LOG_TIMING, LogLevel::Info, message);
}
ret->period.mark_start ();
return ret;
}
void
monodroid_timing_stop (managed_timing_sequence *sequence, const char *message)
{
static constexpr const char DEFAULT_MESSAGE[] = "Managed Timing";
if (sequence == nullptr)
return;
sequence->period.mark_end ();
Timing::info (sequence->period, message == nullptr ? DEFAULT_MESSAGE : message);
timing->release_sequence (sequence);
}
char**
monodroid_strsplit (const char *str, const char *delimiter, size_t max_tokens)
{
return Util::monodroid_strsplit (str, delimiter, max_tokens);
}
void
monodroid_strfreev (char **str_array)
{
Util::monodroid_strfreev (str_array);
}
char*
monodroid_strdup_printf (const char *format, ...)
{
va_list args;
va_start (args, format);
char *ret = Util::monodroid_strdup_vprintf (format, args);
va_end (args);
return ret;
}
char*
monodroid_TypeManager_get_java_class_name (jclass klass)
{
return monodroidRuntime.get_java_class_name_for_TypeManager (klass);
}
int
monodroid_get_namespaced_system_property (const char *name, char **value)
{
return static_cast<int>(AndroidSystem::monodroid_get_system_property (name, value));
}
FILE*
monodroid_fopen (const char* filename, const char* mode)
{
return Util::monodroid_fopen (filename, mode);
}
int
send_uninterrupted (int fd, void *buf, int len)
{
if (len < 0)
len = 0;
return Util::send_uninterrupted (fd, buf, static_cast<size_t>(len));
}
int
recv_uninterrupted (int fd, void *buf, int len)
{
if (len < 0)
len = 0;
return static_cast<int>(Util::recv_uninterrupted (fd, buf, static_cast<size_t>(len)));
}
void
set_world_accessable (const char *path)
{
Util::set_world_accessable (path);
}
void
create_public_directory (const char *dir)
{
Util::create_public_directory (dir);
}
char*
path_combine (const char *path1, const char *path2)
{
return Util::path_combine (path1, path2);
}
void*
monodroid_dylib_mono_new ([[maybe_unused]] const char *libmono_path)
{
return nullptr;
}
void
monodroid_dylib_mono_free ([[maybe_unused]] void *mono_imports)
{
// no-op
}
/*
this function is used from JavaInterop and should be treated as public API
https://github.com/dotnet/java-interop/blob/master/src/java-interop/java-interop-gc-bridge-mono.c#L266
it should also accept libmono_path = nullptr parameter
*/
int
monodroid_dylib_mono_init (void *mono_imports, [[maybe_unused]] const char *libmono_path)
{
if (mono_imports == nullptr)
return FALSE;
return TRUE;
}
void*
monodroid_get_dylib ()
{
return nullptr;
}
const char*
_monodroid_lookup_replacement_type (const char *jniSimpleReference)
{
return JniRemapping::lookup_replacement_type (jniSimpleReference);
}
const JniRemappingReplacementMethod*
_monodroid_lookup_replacement_method_info (const char *jniSourceType, const char *jniMethodName, const char *jniMethodSignature)
{
return JniRemapping::lookup_replacement_method_info (jniSourceType, jniMethodName, jniMethodSignature);
}
void
monodroid_log_traces (uint32_t kind, const char *first_line)
{
JNIEnv *env = osBridge.ensure_jnienv ();
auto tk = static_cast<TraceKind>(kind);
monodroidRuntime.log_traces (env, tk, first_line);
}