Skip to content

Commit dfd7473

Browse files
dellis1972jonpryor
authored andcommitted
[monodroid] Fix runtime crash when using fastdev typemaps (dotnet#2696)
When using fastdev typemaps files we get the following error: F libc : Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0 in tid 5802 (haredandroidios), pid 5802 (haredandroidios) I crash_dump32: obtaining output fd from tombstoned, type: kDebuggerdTombstone I /system/bin/tombstoned: received crash request for pid 5802 I crash_dump32: performing dump of process 5802 (target tid = 5802) F DEBUG : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** F DEBUG : Build fingerprint: 'Android/sdk_phone_x86/generic_x86:9/PSR1.180720.012/4923214:userdebug/test-keys' F DEBUG : Revision: '0' F DEBUG : ABI: 'x86' F DEBUG : pid: 5802, tid: 5802, name: haredandroidios >>> com.xamarin.blankformssharedandroidios <<< F DEBUG : signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0 F DEBUG : Cause: null pointer dereference F DEBUG : eax 00000000 ebx e6b2e754 ecx 00000000 edx 00000000 F DEBUG : edi e0cc58f0 esi 00000000 F DEBUG : ebp ffd85ff8 esp ffd85fcc eip e6a60532 F DEBUG : F DEBUG : backtrace: F DEBUG : #00 pc 0001e532 /system/lib/libc.so (strlen+18) F DEBUG : #1 pc 00075952 /system/lib/libc.so (strdup+34) F DEBUG : #2 pc 0000f6ab /data/app/com.xamarin.blankformssharedandroidios-nCq7hL5Bz-TYILJl3W97zw==/lib/x86/libmonodroid.so (xamarin::android::internal::EmbeddedAssemblies::add_type_mapping(xamarin::android::internal::TypeMappingInfo**, char const*, char const*, char const*)+667) F DEBUG : #3 pc 00010ed7 /data/app/com.xamarin.blankformssharedandroidios-nCq7hL5Bz-TYILJl3W97zw==/lib/x86/libmonodroid.so (xamarin::android::internal::EmbeddedAssemblies::try_load_typemaps_from_directory(char const*)+871) F DEBUG : dotnet#4 pc 000233b8 /data/app/com.xamarin.blankformssharedandroidios-nCq7hL5Bz-TYILJl3W97zw==/lib/x86/libmonodroid.so (gather_bundled_assemblies(_JNIEnv*, xamarin::android::jstring_array_wrapper&, bool, int*)+248) F DEBUG : dotnet#5 pc 000229c6 /data/app/com.xamarin.blankformssharedandroidios-nCq7hL5Bz-TYILJl3W97zw==/lib/x86/libmonodroid.so (create_domain(_JNIEnv*, _jclass*, xamarin::android::jstring_array_wrapper&, _jstring*, _jobject*, bool)+166) F DEBUG : dotnet#6 pc 0001f20c /data/app/com.xamarin.blankformssharedandroidios-nCq7hL5Bz-TYILJl3W97zw==/lib/x86/libmonodroid.so (create_and_initialize_domain(_JNIEnv*, _jclass*, xamarin::android::jstring_array_wrapper&, _jobjectArray*, _jobject*, bool)+204) F DEBUG : dotnet#7 pc 0001c7af /data/app/com.xamarin.blankformssharedandroidios-nCq7hL5Bz-TYILJl3W97zw==/lib/x86/libmonodroid.so (Java_mono_android_Runtime_init+4255) The was down to the `try_load_typemaps_from_directory()` passing a `nullptr` to the `add_type_mapping()` method. This method was calling **strdup**(3), which does NOT like `nullptr`. Since the `source_entry` argument is only used for logging we might as well create a constant string with a value of `.__override__` so that if there is a problem we can see from the logs this was a fastdev issue.
1 parent 590e53c commit dfd7473

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/monodroid/jni/embedded-assemblies.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ const char *EmbeddedAssemblies::suffixes[] = {
4747
};
4848

4949
constexpr char EmbeddedAssemblies::assemblies_prefix[];
50+
constexpr char EmbeddedAssemblies::override_typemap_entry_name[];
5051

5152

5253
void EmbeddedAssemblies::set_assemblies_prefix (const char *prefix)
@@ -500,10 +501,10 @@ EmbeddedAssemblies::try_load_typemaps_from_directory (const char *path)
500501
int len = androidSystem.monodroid_read_file_into_memory (file_path, &val);
501502
if (len > 0 && val != nullptr) {
502503
if (utils.monodroid_dirent_hasextension (e, ".mj")) {
503-
if (!add_type_mapping (&managed_to_java_maps, file_path, nullptr, ((const char*)val)))
504+
if (!add_type_mapping (&managed_to_java_maps, file_path, override_typemap_entry_name, ((const char*)val)))
504505
delete[] val;
505506
} else if (utils.monodroid_dirent_hasextension (e, ".jm")) {
506-
if (!add_type_mapping (&java_to_managed_maps, file_path, nullptr, ((const char*)val)))
507+
if (!add_type_mapping (&java_to_managed_maps, file_path, override_typemap_entry_name, ((const char*)val)))
507508
delete[] val;
508509
}
509510
}

src/monodroid/jni/embedded-assemblies.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ namespace xamarin { namespace android { namespace internal {
1515
{
1616
private:
1717
static constexpr char assemblies_prefix[] = "assemblies/";
18+
static constexpr char override_typemap_entry_name[] = ".__override__";
1819
static const char *suffixes[];
1920

2021
public:

0 commit comments

Comments
 (0)