Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions src/monodroid/jni/android-system.cc
Original file line number Diff line number Diff line change
Expand Up @@ -356,15 +356,22 @@ AndroidSystem::create_update_dir (char *override_dir)
char*
AndroidSystem::get_full_dso_path (const char *base_dir, const char *dso_path, bool &needs_free)
{
log_warn (LOG_DEFAULT, "%s called", __PRETTY_FUNCTION__);
log_warn (LOG_DEFAULT, " base_dir == %s", base_dir);
log_warn (LOG_DEFAULT, " dso_path == %s", dso_path);
needs_free = false;
if (dso_path == nullptr)
return nullptr;

if (base_dir == nullptr || utils.is_path_rooted (dso_path))
if (base_dir == nullptr || utils.is_path_rooted (dso_path)) {
log_warn (LOG_DEFAULT, " no base dir or dso_path rooted, returning: %s", dso_path);
return const_cast<char*>(dso_path); // Absolute path or no base path, can't do much with it
}

needs_free = true;
return utils.path_combine (base_dir, dso_path);
char *ret = utils.path_combine (base_dir, dso_path);
log_warn (LOG_DEFAULT, " returning %s", ret);
return ret;
}

void*
Expand All @@ -373,21 +380,24 @@ AndroidSystem::load_dso (const char *path, int dl_flags, bool skip_exists_check)
if (path == nullptr || *path == '\0')
return nullptr;

log_info (LOG_ASSEMBLY, "Trying to load shared library '%s'", path);
log_warn (LOG_ASSEMBLY, "Trying to load shared library '%s'", path);
if (!skip_exists_check && !is_embedded_dso_mode_enabled () && !utils.file_exists (path)) {
log_info (LOG_ASSEMBLY, "Shared library '%s' not found", path);
log_warn (LOG_ASSEMBLY, "Shared library '%s' not found", path);
return nullptr;
}

void *handle = dlopen (path, dl_flags);
if (handle == nullptr && utils.should_log (LOG_ASSEMBLY))
log_info_nocheck (LOG_ASSEMBLY, "Failed to load shared library '%s'. %s", path, dlerror ());
if (handle == nullptr)
log_warn (LOG_ASSEMBLY, "Failed to load shared library '%s'. %s", path, dlerror ());
return handle;
}

void*
AndroidSystem::load_dso_from_specified_dirs (const char **directories, size_t num_entries, const char *dso_name, int dl_flags)
{
log_warn (LOG_DEFAULT, "%s called", __PRETTY_FUNCTION__);
log_warn (LOG_DEFAULT, " dso_name == %s", dso_name);
log_warn (LOG_DEFAULT, " num_entries == %u", num_entries);
assert (directories != nullptr);
if (dso_name == nullptr)
return nullptr;
Expand All @@ -396,6 +406,7 @@ AndroidSystem::load_dso_from_specified_dirs (const char **directories, size_t nu
char *full_path = nullptr;
for (size_t i = 0; i < num_entries; i++) {
full_path = get_full_dso_path (directories [i], dso_name, needs_free);
log_warn (LOG_DEFAULT, " trying %s", full_path);
void *handle = load_dso (full_path, dl_flags, false);
if (needs_free)
delete[] full_path;
Expand Down
23 changes: 18 additions & 5 deletions src/monodroid/jni/basic-android-system.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,30 @@ size_t BasicAndroidSystem::app_lib_directories_size = 0;
void
BasicAndroidSystem::setup_app_library_directories (JNIEnv *env, jstring_array_wrapper& runtimeApks, jstring_array_wrapper& appDirs, int androidApiLevel)
{
log_warn (LOG_DEFAULT, "%s called", __PRETTY_FUNCTION__);
log_warn (LOG_DEFAULT, " API level == %d", androidApiLevel);
log_warn (LOG_DEFAULT, " is_embedded_dso_mode_enabled == %s", is_embedded_dso_mode_enabled () ? "true" : "false");
if (androidApiLevel < 23 || !is_embedded_dso_mode_enabled ()) {
log_info (LOG_DEFAULT, "Setting up for DSO lookup in app data directories");
log_warn (LOG_DEFAULT, "Setting up for DSO lookup in app data directories");
BasicAndroidSystem::app_lib_directories_size = 1;
BasicAndroidSystem::app_lib_directories = reinterpret_cast<const char**>(new char[app_lib_directories_size]());
BasicAndroidSystem::app_lib_directories [0] = utils.strdup_new (appDirs[2].get_cstr ());
BasicAndroidSystem::app_lib_directories = new const char*[app_lib_directories_size]();
BasicAndroidSystem::app_lib_directories [0] = utils.strdup_new (appDirs[2].get_cstr());
} else {
log_info (LOG_DEFAULT, "Setting up for DSO lookup directly in the APK");
log_warn (LOG_DEFAULT, "Setting up for DSO lookup directly in the APK");
BasicAndroidSystem::app_lib_directories_size = runtimeApks.get_length ();
BasicAndroidSystem::app_lib_directories = reinterpret_cast<const char**>(new char[app_lib_directories_size]());
BasicAndroidSystem::app_lib_directories = new const char*[app_lib_directories_size]();

unsigned short built_for_cpu = 0, running_on_cpu = 0;
unsigned char is64bit = 0;
_monodroid_detect_cpu_and_architecture (&built_for_cpu, &running_on_cpu, &is64bit);
setup_apk_directories (env, running_on_cpu, runtimeApks);
}

log_warn (LOG_DEFAULT, " app_lib_directories_size == %u", app_lib_directories_size);
log_warn (LOG_DEFAULT, " directories:");
for (size_t i = 0; i < app_lib_directories_size; i++) {
log_warn (LOG_DEFAULT, " app_lib_directories [%u] == %s", i, BasicAndroidSystem::app_lib_directories [i]);
}
}

void
Expand All @@ -46,7 +55,11 @@ BasicAndroidSystem::add_apk_libdir (const char *apk, size_t index, size_t apk_co
{
assert (user_data != nullptr);
assert (index >= 0 && index < app_lib_directories_size);
log_warn (LOG_DEFAULT, "%s called", __PRETTY_FUNCTION__);
log_warn (LOG_DEFAULT, " apk #%u out of %u == %s", index, apk_count, apk);
log_warn (LOG_DEFAULT, " user_data == %s", static_cast<const char*>(user_data));
app_lib_directories [index] = utils.string_concat (apk, "!/lib/", static_cast<const char*>(user_data));
log_warn (LOG_DEFAULT, " added path: %s", app_lib_directories [index]);
}

void
Expand Down
9 changes: 9 additions & 0 deletions src/monodroid/jni/monodroid-glue.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1052,28 +1052,35 @@ MonodroidRuntime::monodroid_dlopen_log_and_return (void *handle, char **err, con
delete[] full_name;
}

log_warn (LOG_DEFAULT, " returning handle == %p", handle);
return handle;
}

void*
MonodroidRuntime::monodroid_dlopen (const char *name, int flags, char **err, void *user_data)
{
log_warn (LOG_DEFAULT, "%s called", __PRETTY_FUNCTION__);
log_warn (LOG_DEFAULT, " name == %s; flags == 0x%X; err == %p", name == nullptr ? "<null>" : name, flags, err);

int dl_flags = monodroidRuntime.convert_dl_flags (flags);
bool libmonodroid_fallback = false;

/* name is nullptr when we're P/Invoking __Internal, so remap to libmonodroid */
if (name == nullptr) {
name = "libmonodroid.so";
libmonodroid_fallback = TRUE;
log_warn (LOG_DEFAULT, " internal call, name remapped to %s", name);
}

void *h = androidSystem.load_dso_from_any_directories (name, dl_flags);
log_warn (LOG_DEFAULT, " first load attempt, h == %p", h);
if (h != nullptr) {
return monodroid_dlopen_log_and_return (h, err, name, false);
}

if (libmonodroid_fallback) {
char *full_name = utils.path_combine (AndroidSystem::SYSTEM_LIB_PATH, "libmonodroid.so");
log_warn (LOG_DEFAULT," fallback, looking in %s", full_name);
h = androidSystem.load_dso (full_name, dl_flags, false);
return monodroid_dlopen_log_and_return (h, err, full_name, true);
}
Expand Down Expand Up @@ -1385,6 +1392,8 @@ MonodroidRuntime::Java_mono_android_Runtime_initInternal (JNIEnv *env, jclass kl
jobjectArray externalStorageDirs, jobjectArray assembliesJava,
jint apiLevel, jboolean embeddedDSOsEnabled, jboolean isEmulator)
{
log_warn (LOG_DEFAULT, "%s called", __PRETTY_FUNCTION__);
log_warn (LOG_DEFAULT, " embeddedDSOsEnabled == %u", embeddedDSOsEnabled);
init_logging_categories ();

timing_period total_time;
Expand Down
4 changes: 4 additions & 0 deletions tests/Runtime-AppBundle/Environment.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
debug.mono.debug=1
MONO_LOG_LEVEL=debug
MONO_LOG_MASK=asm
MONO_XDEBUG=1
1 change: 1 addition & 0 deletions tests/Runtime-AppBundle/Mono.Android-TestsAppBundle.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
<AndroidAsset Include="$(_MonoAndroidTest)Assets\subfolder\accept_request.png">
<Link>Assets\subfolder\accept_request.png</Link>
</AndroidAsset>
<AndroidEnvironment Include="Environment.txt" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
<Import Project="Mono.Android-TestsAppBundle.targets" />
Expand Down