Skip to content

Commit b3823db

Browse files
committed
MAUI hello world works now
1 parent d166220 commit b3823db

File tree

7 files changed

+24
-11
lines changed

7 files changed

+24
-11
lines changed

src/Mono.Android/Android.Runtime/RuntimeNativeMethods.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ internal static class RuntimeNativeMethods
9393
internal static extern IntPtr clr_typemap_managed_to_java (string fullName, IntPtr mvid);
9494

9595
[DllImport (RuntimeConstants.InternalDllName, CallingConvention = CallingConvention.Cdecl)]
96-
internal static extern string clr_typemap_java_to_managed (string fullName);
96+
internal static extern IntPtr clr_typemap_java_to_managed (string fullName);
9797

9898
[MethodImplAttribute(MethodImplOptions.InternalCall)]
9999
internal static extern void monodroid_unhandled_exception (Exception javaException);

src/Mono.Android/Java.Interop/TypeManager.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,12 +223,16 @@ static Type monovm_typemap_java_to_managed (string java_type_name)
223223
[UnconditionalSuppressMessage ("Trimming", "IL2057", Justification = "Value of java_type_name isn't statically known.")]
224224
static Type? clr_typemap_java_to_managed (string java_type_name)
225225
{
226-
string? managedTypeName = RuntimeNativeMethods.clr_typemap_java_to_managed (java_type_name);
227-
if (String.IsNullOrEmpty (managedTypeName)) {
226+
IntPtr managedTypeNamePointer = RuntimeNativeMethods.clr_typemap_java_to_managed (java_type_name);
227+
if (managedTypeNamePointer == IntPtr.Zero) {
228228
return null;
229229
}
230230

231-
return Type.GetType (managedTypeName);
231+
string managedTypeName = Marshal.PtrToStringAnsi (managedTypeNamePointer);
232+
Logger.Log (LogLevel.Info, "monodroid", $"clr_typemap_java_to_managed ('{java_type_name}') returned '{managedTypeName}'");
233+
Type ret = Type.GetType (managedTypeName);
234+
Logger.Log (LogLevel.Info, "monodroid", $"Loaded type: {ret}");
235+
return ret;
232236
}
233237

234238
internal static Type? GetJavaToManagedType (string class_name)

src/Xamarin.Android.Build.Tasks/Utilities/TypeMappingReleaseNativeAssemblyGeneratorCLR.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ void InitJavaMap (ConstructionState cs)
398398
TypeMapJava map_entry;
399399
foreach (TypeMapGenerator.TypeMapReleaseEntry entry in mappingData.JavaTypes) {
400400
string assemblyName = mappingData.Modules[entry.ModuleIndex].AssemblyName;
401-
string fullManagedTypeName = $"{assemblyName}, {entry.ManagedTypeName}";
401+
string fullManagedTypeName = $"{entry.ManagedTypeName}, {assemblyName}";
402402
uint managedTypeNameIndex = GetEntryIndex (fullManagedTypeName, seenManagedTypeNames, cs.ManagedTypeNames);
403403
cs.JavaNames.Add (entry.JavaName);
404404

src/native/clr/host/generate-pinvoke-tables.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ const std::vector<std::string> internal_pinvoke_names = {
7979
// "recv_uninterrupted",
8080
// "send_uninterrupted",
8181
// "set_world_accessable",
82+
83+
// We can treat liblog as "internal", since we link against it
84+
"__android_log_print",
8285
};
8386

8487
const std::vector<std::string> dotnet_pinvoke_names = {
@@ -647,6 +650,7 @@ void write_library_name_hashes (Hash (*hasher)(const char*, size_t), std::ostrea
647650
{
648651
write_library_name_hash (hasher, output, "java-interop", "java_interop");
649652
write_library_name_hash (hasher, output, "xa-internal-api", "xa_internal_api");
653+
write_library_name_hash (hasher, output, "liblog", "android_liblog");
650654
write_library_name_hash (hasher, output, "libSystem.Native", "system_native");
651655
write_library_name_hash (hasher, output, "libSystem.IO.Compression.Native", "system_io_compression_native");
652656
write_library_name_hash (hasher, output, "libSystem.Security.Cryptography.Native.Android", "system_security_cryptography_native_android");

src/native/clr/host/pinvoke-override.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ auto PinvokeOverride::monodroid_pinvoke_override (const char *library_name, cons
1616
hash_t library_name_hash = xxhash::hash (library_name, strlen (library_name));
1717
hash_t entrypoint_hash = xxhash::hash (entrypoint_name, strlen (entrypoint_name));
1818

19-
if (library_name_hash == java_interop_library_hash || library_name_hash == xa_internal_api_library_hash) {
19+
if (library_name_hash == java_interop_library_hash || library_name_hash == xa_internal_api_library_hash || library_name_hash == android_liblog_library_hash) {
2020
PinvokeEntry *entry = find_pinvoke_address (entrypoint_hash, internal_pinvokes.data (), internal_pinvokes_count);
2121

2222
if (entry == nullptr) [[unlikely]] {

src/native/clr/host/pinvoke-tables.include

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
namespace {
1212
#if INTPTR_MAX == INT64_MAX
1313
//64-bit internal p/invoke table
14-
std::array<PinvokeEntry, 9> internal_pinvokes {{
14+
std::array<PinvokeEntry, 10> internal_pinvokes {{
15+
{0x4310c1531ddddc14, "__android_log_print", reinterpret_cast<void*>(&__android_log_print)},
1516
{0x4b1956138764939a, "_monodroid_gref_log_new", reinterpret_cast<void*>(&_monodroid_gref_log_new)},
1617
{0x9187e6bc6294cacf, "clr_typemap_managed_to_java", reinterpret_cast<void*>(&clr_typemap_managed_to_java)},
1718
{0x9a946dfe9916a942, "clr_typemap_java_to_managed", reinterpret_cast<void*>(&clr_typemap_java_to_managed)},
@@ -507,14 +508,16 @@ namespace {
507508

508509
constexpr hash_t java_interop_library_hash = 0x54568ec36068e6b6;
509510
constexpr hash_t xa_internal_api_library_hash = 0x43fd1b21148361b2;
511+
constexpr hash_t android_liblog_library_hash = 0x1f2e4bce0544fb0a;
510512
constexpr hash_t system_native_library_hash = 0x4cd7bd0032e920e1;
511513
constexpr hash_t system_io_compression_native_library_hash = 0x9190f4cb761b1d3c;
512514
constexpr hash_t system_security_cryptography_native_android_library_hash = 0x1848c0093f0afd8;
513515
constexpr hash_t system_globalization_native_library_hash = 0x28b5c8fca080abd5;
514516
#else
515517
//32-bit internal p/invoke table
516-
std::array<PinvokeEntry, 9> internal_pinvokes {{
518+
std::array<PinvokeEntry, 10> internal_pinvokes {{
517519
{0xb7a486a, "monodroid_TypeManager_get_java_class_name", reinterpret_cast<void*>(&monodroid_TypeManager_get_java_class_name)},
520+
{0x39e5b5d4, "__android_log_print", reinterpret_cast<void*>(&__android_log_print)},
518521
{0x656e00bd, "clr_typemap_managed_to_java", reinterpret_cast<void*>(&clr_typemap_managed_to_java)},
519522
{0xa04e5d1c, "monodroid_free", reinterpret_cast<void*>(&monodroid_free)},
520523
{0xb02468aa, "_monodroid_gref_get", reinterpret_cast<void*>(&_monodroid_gref_get)},
@@ -1009,12 +1012,13 @@ constexpr hash_t system_globalization_native_library_hash = 0x28b5c8fca080abd5;
10091012

10101013
constexpr hash_t java_interop_library_hash = 0x6e36e350;
10111014
constexpr hash_t xa_internal_api_library_hash = 0x13c9bd62;
1015+
constexpr hash_t android_liblog_library_hash = 0xa70c9969;
10121016
constexpr hash_t system_native_library_hash = 0x5b9ade60;
10131017
constexpr hash_t system_io_compression_native_library_hash = 0xafe3142c;
10141018
constexpr hash_t system_security_cryptography_native_android_library_hash = 0x93625cd;
10151019
constexpr hash_t system_globalization_native_library_hash = 0xa66f1e5a;
10161020
#endif
10171021

1018-
constexpr size_t internal_pinvokes_count = 9;
1022+
constexpr size_t internal_pinvokes_count = 10;
10191023
constexpr size_t dotnet_pinvokes_count = 477;
10201024
} // end of anonymous namespace

src/native/clr/host/typemap.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,10 @@ auto TypeMapper::typemap_java_to_managed (const char *typeName) noexcept -> cons
282282

283283
log_debug (
284284
LOG_ASSEMBLY,
285-
"Java type '{}' corresponds to managed type '{}'",
285+
"Java type '{}' corresponds to managed type '{}' ({:p}",
286286
optional_string (typeName),
287-
optional_string (managed_type_names[java_entry->managed_type_name_index])
287+
optional_string (managed_type_names[java_entry->managed_type_name_index]),
288+
reinterpret_cast<const void*>(managed_type_names[java_entry->managed_type_name_index])
288289
);
289290
return managed_type_names[java_entry->managed_type_name_index];
290291
}

0 commit comments

Comments
 (0)