gpointer
mono_lookup_pinvoke_call_internal (MonoMethod *method, MonoError *error);
+#ifdef ENABLE_NETCORE
+void
+mono_set_pinvoke_search_directories (int dir_count, char **dirs);
+#endif
+
#endif
*/
static MonoNativeTlsKey loader_lock_nest_id;
+#if ENABLE_NETCORE
+static int pinvoke_search_directories_count;
+static char **pinvoke_search_directories;
+#endif
+
static void dllmap_cleanup (void);
static void cached_module_cleanup(void);
return module;
}
+#if ENABLE_NETCORE
+void
+mono_set_pinvoke_search_directories (int dir_count, char **dirs)
+{
+ pinvoke_search_directories_count = dir_count;
+ pinvoke_search_directories = dirs;
+}
+#endif
+
static MonoDl*
pinvoke_probe_for_module_relative_directories (MonoImage *image, const char *file_name, char **found_name_out)
{
g_assert (found_name_out);
- int j;
- void *iter;
- char *mdirname;
+ int j;
+ void *iter;
+ char *mdirname;
+
+#if ENABLE_NETCORE
+ mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_DLLIMPORT, "netcore DllImport handler: wanted '%s'", file_name);
+
+ for (j = 0; j < pinvoke_search_directories_count + 1 && module == NULL; ++j) {
+ if (j < pinvoke_search_directories_count) {
+ mdirname = pinvoke_search_directories[j];
+ } else {
+ // TODO: Check DefaultDllImportSearchPathsAttribute, NativeLibrary callback
+ mdirname = g_path_get_dirname (image->name);
+ if (!mdirname)
+ continue;
+ }
+
+ iter = NULL;
+ while ((full_name = mono_dl_build_path (mdirname, file_name, &iter)) && module == NULL) {
+ char *error_msg;
+ module = cached_module_load (full_name, MONO_DL_LAZY, &error_msg);
+ if (!module) {
+ mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_DLLIMPORT, "DllImport error loading library '%s': '%s'.", full_name, error_msg);
+ g_free (error_msg);
+ } else {
+ found_name = g_strdup (full_name);
+ }
+ g_free (full_name);
+ }
+ if (j >= pinvoke_search_directories_count) {
+ g_free (mdirname);
+ }
+ }
+#else
for (j = 0; j < 3; ++j) {
iter = NULL;
mdirname = NULL;
if (module)
break;
}
+#endif
- *found_name_out = found_name;
- return module;
+ *found_name_out = found_name;
+ return module;
}
#include "mini-runtime.h"
#include <mono/metadata/assembly.h>
#include <mono/metadata/assembly-internals.h>
+#include <mono/metadata/loader-internals.h>
#include <mono/utils/mono-logger-internals.h>
MONO_API int coreclr_initialize (const char* exePath, const char* appDomainFriendlyName,
static MonoCoreTrustedPlatformAssemblies *trusted_platform_assemblies;
static MonoCoreNativeLibPaths *native_lib_paths;
-static MonoDlFallbackHandler *dl_fallback_handler;
static void
mono_core_trusted_platform_assemblies_free (MonoCoreTrustedPlatformAssemblies *a)
mono_install_assembly_preload_hook (mono_core_preload_hook, (void*)trusted_platform_assemblies);
}
-static void*
-mono_core_dl_load (const char *name, int flags, char **error_msg, void *user_data)
-{
- mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_DLLIMPORT, "netcore DllImport fallback handler: wanted '%s'", name);
-
- if (g_path_is_absolute(name)) {
- return mono_dl_open_file (name, flags);
- } else if (native_lib_paths != NULL) {
- for (int i = 0; i < native_lib_paths->dir_count; ++i) {
- char *fullpath = g_build_filename (native_lib_paths->dirs[i], name);
- mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_DLLIMPORT, "netcore DllImport fallback handler: trying '%s'", fullpath);
- void *lib = mono_dl_open_file (fullpath, flags);
- g_free (fullpath);
- if (lib)
- return lib;
- }
- }
- return NULL;
-}
-
-static void*
-mono_core_dl_symbol (void *handle, const char *name, char **err, void *user_data)
-{
- return mono_dl_symbol_default ((MonoDl*)handle, name);
-}
-
-static void*
-mono_core_dl_close (void *module, void* usr_data)
-{
- mono_dl_close_handle ((MonoDl*)module);
- return NULL;
-}
-
-static void
-install_dl_fallback_handlers (void)
-{
- dl_fallback_handler = mono_dl_fallback_register_internal (&mono_core_dl_load, &mono_core_dl_symbol, &mono_core_dl_close, NULL);
-}
-
-static void
-cleanup_dl_fallback_handlers (void)
-{
- mono_dl_fallback_unregister (dl_fallback_handler);
- dl_fallback_handler = NULL;
-}
-
static gboolean
parse_properties (int propertyCount, const char** propertyKeys, const char** propertyValues)
{
return 0x80004005; /* E_FAIL */
install_assembly_loader_hooks ();
- install_dl_fallback_handlers ();
+ if (native_lib_paths != NULL)
+ mono_set_pinvoke_search_directories (native_lib_paths->dir_count, native_lib_paths->dirs);
return 0;
}
//
int coreclr_shutdown_2 (void* hostHandle, unsigned int domainId, int* latchedExitCode)
{
- cleanup_dl_fallback_handlers ();
+ mono_set_pinvoke_search_directories (0, NULL);
MonoCoreNativeLibPaths *dl = native_lib_paths;
native_lib_paths = NULL;
mono_core_native_lib_paths_free (dl);
}
/**
- * mono_dl_symbol_default:
- * \param module a MonoDl pointer
- * \param name symbol name
- * Load the address of symbol \p name from the given \p module.
- * \returns Address of the symbol or NULL on failure
- */
-void*
-mono_dl_symbol_default (MonoDl *module, const char *name)
-{
- void * sym;
- {
-#if MONO_DL_NEED_USCORE
- {
- char *usname = g_malloc (strlen (name) + 2);
- *usname = '_';
- strcpy (usname + 1, name);
- sym = mono_dl_lookup_symbol (module, usname);
- g_free (usname);
- }
-#else
- sym = mono_dl_lookup_symbol (module, name);
-#endif
- }
- return sym;
-}
-
-/**
* mono_dl_symbol:
* \param module a MonoDl pointer
* \param name symbol name
if (module->dl_fallback) {
sym = module->dl_fallback->symbol_func (module->handle, name, &err, module->dl_fallback->user_data);
} else {
- sym = mono_dl_symbol_default (module, name);
+#if MONO_DL_NEED_USCORE
+ {
+ char *usname = g_malloc (strlen (name) + 2);
+ *usname = '_';
+ strcpy (usname + 1, name);
+ sym = mono_dl_lookup_symbol (module, usname);
+ g_free (usname);
+ }
+#else
+ sym = mono_dl_lookup_symbol (module, name);
+#endif
}
if (sym) {
{
MonoDlFallbackHandler *handler = NULL;
MONO_ENTER_GC_UNSAFE;
- handler = mono_dl_fallback_register_internal (load_func, symbol_func, close_func, user_data);
- MONO_EXIT_GC_UNSAFE;
- return handler;
-}
-
-MonoDlFallbackHandler *
-mono_dl_fallback_register_internal (MonoDlFallbackLoad load_func, MonoDlFallbackSymbol symbol_func, MonoDlFallbackClose close_func, void *user_data)
-{
- MonoDlFallbackHandler *handler = NULL;
if (load_func == NULL || symbol_func == NULL)
goto leave;
fallback_handlers = g_slist_prepend (fallback_handlers, handler);
leave:
+ MONO_EXIT_GC_UNSAFE;
return handler;
}
int mono_dl_get_executable_path (char *buf, int buflen);
const char* mono_dl_get_system_dir (void);
-void* mono_dl_symbol_default (MonoDl *module, const char *name);
-MonoDlFallbackHandler* mono_dl_fallback_register_internal (MonoDlFallbackLoad load_func, MonoDlFallbackSymbol symbol_func, MonoDlFallbackClose close_func, void *user_data);
-
#endif /* __MONO_UTILS_DL_H__ */