Skip to content

Commit cd2a310

Browse files
committed
Odds and ends
1 parent 1002536 commit cd2a310

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

src/native/clr/include/runtime-base/monodroid-dl.hh

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ namespace xamarin::android
121121
// JNI, we're going to assume it is and thus use System.loadLibrary eventually.
122122
return DsoLoader::load (name, flags, true /* is_jni */);
123123
} else if (dso->handle != nullptr) {
124+
log_debug (LOG_ASSEMBLY, "monodroid_dlopen: library {} already loaded, returning handle {:p}", name, dso->handle);
124125
return dso->handle;
125126
}
126127

@@ -140,13 +141,7 @@ namespace xamarin::android
140141
continue;
141142
}
142143

143-
android_dlextinfo dli;
144-
dli.flags = ANDROID_DLEXT_USE_LIBRARY_FD | ANDROID_DLEXT_USE_LIBRARY_FD_OFFSET;
145-
dli.library_fd = apk_entry->fd;
146-
dli.library_fd_offset = apk_entry->offset;
147-
148-
dso->handle = android_dlopen_ext (dso_name.data (), flags, &dli);
149-
144+
dso->handle = DsoLoader::load (apk_entry->fd, apk_entry->offset, dso_name, flags, dso->is_jni_library);
150145
if (dso->handle != nullptr) {
151146
return dso->handle;
152147
}

src/native/common/include/runtime-base/dso-loader.hh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ namespace xamarin::android {
8888

8989
static auto load_jni (std::string_view const& name, bool name_is_path) -> void*
9090
{
91-
log_debug (LOG_ASSEMBLY, "Loading JNI library {} with System.loadLibrary", name);
91+
log_debug (LOG_ASSEMBLY, "Trying to load loading shared JNI library {} with System.loadLibrary", name);
9292

9393
if (jni_env == nullptr || systemKlass == nullptr) [[unlikely]] {
9494
Helpers::abort_application ("DSO loader class not initialized properly."sv);
@@ -130,6 +130,8 @@ namespace xamarin::android {
130130
return name;
131131
};
132132

133+
// std::string is needed because we must pass a NUL-terminated string to Java, otherwise
134+
// strange things happen (and std::string_view is not necessarily such a string)
133135
const std::string undecorated_lib_name { get_undecorated_name (name, name_is_path) };
134136
log_debug (LOG_ASSEMBLY, "Undecorated library name: {}", undecorated_lib_name);
135137

@@ -142,6 +144,8 @@ namespace xamarin::android {
142144

143145
// This is unfortunate, but since `System.loadLibrary` doesn't return the class handle, we must get it this
144146
// way :(
147+
// We must use full name of the library, because dlopen won't accept an undecorated one without kicking up
148+
// a fuss.
145149
log_debug (LOG_ASSEMBLY, "Attempting to get library {} handle after System.loadLibrary", name);
146150
return log_and_return (dlopen (name.data (), RTLD_NOLOAD), name);
147151
}

0 commit comments

Comments
 (0)