Skip to content

Commit 358c72a

Browse files
committed
Enable a bunch of p/invokes
1 parent 63b78d5 commit 358c72a

16 files changed

+503
-115
lines changed

src/native/clr/host/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,11 @@ set(XAMARIN_MONODROID_SOURCES
3030
host.cc
3131
host-jni.cc
3232
host-util.cc
33+
internal-pinvokes.cc
3334
os-bridge.cc
35+
runtime-util.cc
3436
typemap.cc
37+
xamarin_getifaddrs.cc
3538
)
3639

3740
list(APPEND LOCAL_CLANG_CHECK_SOURCES

src/native/clr/host/host.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <host/host-jni.hh>
1414
#include <host/host-util.hh>
1515
#include <host/os-bridge.hh>
16+
#include <host/runtime-util.hh>
1617
#include <runtime-base/android-system.hh>
1718
#include <runtime-base/jni-wrappers.hh>
1819
#include <runtime-base/logger.hh>
@@ -264,7 +265,7 @@ void Host::Java_mono_android_Runtime_initInternal (JNIEnv *env, jclass runtimeCl
264265

265266
size_t total_time_index;
266267
if (FastTiming::enabled ()) [[unlikely]] {
267-
_timing = std::make_unique<Timing> ();
268+
_timing = std::make_shared<Timing> ();
268269
total_time_index = internal_timing.start_event (TimingEventKind::TotalRuntimeInit);
269270
}
270271

@@ -278,6 +279,8 @@ void Host::Java_mono_android_Runtime_initInternal (JNIEnv *env, jclass runtimeCl
278279
Util::set_environment_variable_for_directory ("HOME", home);
279280
create_xdg_directories_and_environment (home);
280281

282+
java_TimeZone = RuntimeUtil::get_class_from_runtime_field (env, runtimeClass, "java_util_TimeZone", true);
283+
281284
AndroidSystem::detect_embedded_dso_mode (applicationDirs);
282285
AndroidSystem::set_running_in_emulator (isEmulator);
283286
AndroidSystem::set_primary_override_dir (home);
Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
#include <host/host.hh>
2+
#include <host/os-bridge.hh>
3+
#include <host/typemap.hh>
4+
#include <runtime-base/android-system.hh>
5+
#include <runtime-base/cpu-arch.hh>
6+
#include <runtime-base/internal-pinvokes.hh>
7+
#include <runtime-base/jni-remapping.hh>
8+
9+
using namespace xamarin::android;
10+
11+
int _monodroid_gref_get () noexcept
12+
{
13+
return OSBridge::get_gc_gref_count ();
14+
}
15+
16+
void _monodroid_gref_log (const char *message) noexcept
17+
{
18+
}
19+
20+
int _monodroid_gref_log_new (jobject curHandle, char curType, jobject newHandle, char newType, const char *threadName, int threadId, const char *from, int from_writable) noexcept
21+
{
22+
return OSBridge::_monodroid_gref_log_new (curHandle, curType, newHandle, newType, threadName, threadId, from, from_writable);
23+
}
24+
25+
void _monodroid_gref_log_delete (jobject handle, char type, const char *threadName, int threadId, const char *from, int from_writable) noexcept
26+
{
27+
}
28+
29+
const char* clr_typemap_managed_to_java (const char *typeName, const uint8_t *mvid) noexcept
30+
{
31+
return TypeMapper::typemap_managed_to_java (typeName, mvid);
32+
}
33+
34+
bool clr_typemap_java_to_managed (const char *java_type_name, char const** assembly_name, uint32_t *managed_type_token_id) noexcept
35+
{
36+
return TypeMapper::typemap_java_to_managed (java_type_name, assembly_name, managed_type_token_id);
37+
}
38+
39+
void monodroid_log (LogLevel level, LogCategories category, const char *message) noexcept
40+
{
41+
switch (level) {
42+
case LogLevel::Verbose:
43+
case LogLevel::Debug:
44+
log_debug_nocheck (category, std::string_view { message });
45+
break;
46+
47+
case LogLevel::Info:
48+
log_info_nocheck (category, std::string_view { message });
49+
break;
50+
51+
case LogLevel::Warn:
52+
case LogLevel::Silent: // warn is always printed
53+
log_warn (category, std::string_view { message });
54+
break;
55+
56+
case LogLevel::Error:
57+
log_error (category, std::string_view { message });
58+
break;
59+
60+
case LogLevel::Fatal:
61+
log_fatal (category, std::string_view { message });
62+
break;
63+
64+
default:
65+
case LogLevel::Unknown:
66+
case LogLevel::Default:
67+
log_info_nocheck (category, std::string_view { message });
68+
break;
69+
}
70+
}
71+
72+
char* monodroid_TypeManager_get_java_class_name (jclass klass) noexcept
73+
{
74+
return Host::get_java_class_name_for_TypeManager (klass);
75+
}
76+
77+
void monodroid_free (void *ptr) noexcept
78+
{
79+
free (ptr);
80+
}
81+
82+
const char*
83+
_monodroid_lookup_replacement_type (const char *jniSimpleReference)
84+
{
85+
return JniRemapping::lookup_replacement_type (jniSimpleReference);
86+
}
87+
88+
const JniRemappingReplacementMethod*
89+
_monodroid_lookup_replacement_method_info (const char *jniSourceType, const char *jniMethodName, const char *jniMethodSignature)
90+
{
91+
return JniRemapping::lookup_replacement_method_info (jniSourceType, jniMethodName, jniMethodSignature);
92+
}
93+
94+
managed_timing_sequence* monodroid_timing_start (const char *message)
95+
{
96+
// Technically a reference here is against the idea of shared pointers, but
97+
// in this instance it's fine since we know we won't be storing the pointer
98+
// and this way things are slightly faster.
99+
std::shared_ptr<Timing> const &timing = Host::get_timing ();
100+
if (!timing) {
101+
return nullptr;
102+
}
103+
104+
managed_timing_sequence *ret = timing->get_available_sequence ();
105+
if (message != nullptr) {
106+
log_write (LOG_TIMING, LogLevel::Info, message);
107+
}
108+
ret->period.mark_start ();
109+
return ret;
110+
}
111+
112+
void monodroid_timing_stop (managed_timing_sequence *sequence, const char *message)
113+
{
114+
static constexpr const char DEFAULT_MESSAGE[] = "Managed Timing";
115+
if (sequence == nullptr) {
116+
return;
117+
}
118+
119+
std::shared_ptr<Timing> const &timing = Host::get_timing ();
120+
if (!timing) [[unlikely]] {
121+
return;
122+
}
123+
124+
sequence->period.mark_end ();
125+
Timing::info (sequence->period, message == nullptr ? DEFAULT_MESSAGE : message);
126+
timing->release_sequence (sequence);
127+
}
128+
129+
void _monodroid_weak_gref_new (jobject curHandle, char curType, jobject newHandle, char newType, const char *threadName, int threadId, const char *from, int from_writable)
130+
{
131+
OSBridge::_monodroid_weak_gref_new (curHandle, curType, newHandle, newType, threadName, threadId, from, from_writable);
132+
}
133+
134+
int _monodroid_weak_gref_get ()
135+
{
136+
return OSBridge::get_gc_weak_gref_count ();
137+
}
138+
139+
int _monodroid_max_gref_get ()
140+
{
141+
return static_cast<int>(AndroidSystem::get_max_gref_count ());
142+
}
143+
144+
void _monodroid_weak_gref_delete (jobject handle, char type, const char *threadName, int threadId, const char *from, int from_writable)
145+
{
146+
OSBridge::_monodroid_weak_gref_delete (handle, type, threadName, threadId, from, from_writable);
147+
}
148+
149+
void _monodroid_lref_log_new (int lrefc, jobject handle, char type, const char *threadName, int threadId, const char *from, int from_writable)
150+
{
151+
OSBridge::_monodroid_lref_log_new (lrefc, handle, type, threadName, threadId, from, from_writable);
152+
}
153+
154+
void _monodroid_lref_log_delete (int lrefc, jobject handle, char type, const char *threadName, int threadId, const char *from, int from_writable)
155+
{
156+
OSBridge::_monodroid_lref_log_delete (lrefc, handle, type, threadName, threadId, from, from_writable);
157+
}
158+
159+
void _monodroid_gc_wait_for_bridge_processing ()
160+
{
161+
// mono_gc_wait_for_bridge_processing (); - replace with the new GC bridge call, when we have it
162+
}
163+
164+
void _monodroid_detect_cpu_and_architecture (uint16_t *built_for_cpu, uint16_t *running_on_cpu, unsigned char *is64bit)
165+
{
166+
abort_if_invalid_pointer_argument (built_for_cpu, "built_for_cpu");
167+
abort_if_invalid_pointer_argument (running_on_cpu, "running_on_cpu");
168+
abort_if_invalid_pointer_argument (is64bit, "is64bit");
169+
170+
bool _64bit;
171+
monodroid_detect_cpu_and_architecture (*built_for_cpu, *running_on_cpu, _64bit);
172+
*is64bit = _64bit;
173+
}
174+
175+
void* _monodroid_timezone_get_default_id ()
176+
{
177+
JNIEnv *env = OSBridge::ensure_jnienv ();
178+
jmethodID getDefault = env->GetStaticMethodID (Host::get_java_class_TimeZone (), "getDefault", "()Ljava/util/TimeZone;");
179+
jmethodID getID = env->GetMethodID (Host::get_java_class_TimeZone (), "getID", "()Ljava/lang/String;");
180+
jobject d = env->CallStaticObjectMethod (Host::get_java_class_TimeZone (), getDefault);
181+
jstring id = reinterpret_cast<jstring> (env->CallObjectMethod (d, getID));
182+
const char *mutf8 = env->GetStringUTFChars (id, nullptr);
183+
if (mutf8 == nullptr) {
184+
log_error (LOG_DEFAULT, "Failed to convert Java TimeZone ID to UTF8 (out of memory?)"sv);
185+
env->DeleteLocalRef (id);
186+
env->DeleteLocalRef (d);
187+
return nullptr;
188+
}
189+
char *def_id = strdup (mutf8);
190+
env->ReleaseStringUTFChars (id, mutf8);
191+
env->DeleteLocalRef (id);
192+
env->DeleteLocalRef (d);
193+
return def_id;
194+
}

0 commit comments

Comments
 (0)