Skip to content

Commit 06003e7

Browse files
committed
Both MonoVM and CoreCLR should work now
1 parent 92c6029 commit 06003e7

File tree

3 files changed

+33
-13
lines changed

3 files changed

+33
-13
lines changed

src/native/clr/host/host.cc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ auto Host::zip_scan_callback (std::string_view const& apk_path, int apk_fd, dyna
147147
}
148148
}
149149

150-
if (!entry_name.starts_with (Zip::lib_prefix) || !entry_name.ends_with (Constants::dso_suffix)) {
150+
if (!AndroidSystem::is_embedded_dso_mode_enabled () || !entry_name.starts_with (Zip::lib_prefix) || !entry_name.ends_with (Constants::dso_suffix)) {
151151
return false;
152152
}
153153

@@ -156,6 +156,14 @@ auto Host::zip_scan_callback (std::string_view const& apk_path, int apk_fd, dyna
156156
hash_t name_hash = xxhash::hash (lib_name.data (), lib_name.length ());
157157
log_debug (LOG_ASSEMBLY, "Library name is: {}; hash == 0x{:x}", lib_name, name_hash);
158158

159+
DSOApkEntry *apk_entry = MonodroidDl::find_dso_apk_entry (name_hash);
160+
if (apk_entry == nullptr) {
161+
return false;
162+
}
163+
164+
log_debug (LOG_ASSEMBLY, "Found matching DSO APK entry");
165+
apk_entry->fd = apk_fd;
166+
apk_entry->offset = offset;
159167
return false;
160168
}
161169

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

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,23 @@ namespace xamarin::android
8484
return &dso_names_data[dso->name_index];
8585
}
8686

87+
[[gnu::flatten]]
88+
static auto find_dso_apk_entry (hash_t hash) -> DSOApkEntry*
89+
{
90+
auto equal = [](DSOApkEntry const& entry, hash_t key) -> bool { return entry.name_hash == key; };
91+
auto less_than = [](DSOApkEntry const& entry, hash_t key) -> bool { return entry.name_hash < key; };
92+
ssize_t idx = Search::binary_search<DSOApkEntry, equal, less_than> (
93+
hash,
94+
dso_apk_entries, application_config.number_of_shared_libraries
95+
);
96+
97+
if (idx >= 0) [[likely]] {
98+
return &dso_apk_entries[idx];
99+
}
100+
101+
return nullptr;
102+
}
103+
87104
[[gnu::flatten]]
88105
static auto monodroid_dlopen (DSOCacheEntry *dso, std::string_view const& name, int flags) noexcept -> void*
89106
{
@@ -107,18 +124,13 @@ namespace xamarin::android
107124
StartupAwareLock lock (dso_handle_write_lock);
108125
#if defined (RELEASE)
109126
if (AndroidSystem::is_embedded_dso_mode_enabled ()) {
110-
DSOApkEntry *apk_entry = dso_apk_entries;
111-
for (size_t i = 0uz; i < application_config.number_of_shared_libraries; i++) {
112-
if (apk_entry->name_hash != dso->real_name_hash) {
113-
apk_entry++;
114-
continue;
115-
}
116-
127+
DSOApkEntry *apk_entry = find_dso_apk_entry (dso->real_name_hash);
128+
if (apk_entry != nullptr && apk_entry->fd != -1) {
117129
dso->handle = DsoLoader::load (apk_entry->fd, apk_entry->offset, dso_name, flags, dso->is_jni_library);
118-
if (dso->handle != nullptr) {
119-
return dso->handle;
120-
}
121-
break;
130+
}
131+
132+
if (dso->handle != nullptr) {
133+
return dso->handle;
122134
}
123135
}
124136
#endif

src/native/mono/monodroid/embedded-assemblies-zip.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ EmbeddedAssemblies::zip_load_assembly_store_entries (std::vector<uint8_t> const&
292292
// Since it's not an assembly store, it's a shared library most likely and it is long enough for us not to have
293293
// to check the length
294294
if (Util::ends_with (entry_name, dso_suffix)) {
295-
constexpr size_t apk_lib_prefix_len = apk_lib_prefix.size () - 1;
295+
constexpr size_t apk_lib_prefix_len = apk_lib_prefix.length ();
296296

297297
const char *const name = entry_name.get () + apk_lib_prefix_len;
298298
DSOApkEntry *apk_entry = reinterpret_cast<DSOApkEntry*>(reinterpret_cast<uint8_t*>(dso_apk_entries) + (sizeof(DSOApkEntry) * number_of_zip_dso_entries));

0 commit comments

Comments
 (0)