diff --git a/src/Java.Interop/Java.Interop/JniRuntime.cs b/src/Java.Interop/Java.Interop/JniRuntime.cs index d61bd172a..973af4210 100644 --- a/src/Java.Interop/Java.Interop/JniRuntime.cs +++ b/src/Java.Interop/Java.Interop/JniRuntime.cs @@ -9,6 +9,8 @@ using System.Runtime.InteropServices; using System.Threading; +[assembly: DefaultDllImportSearchPathsAttribute (DllImportSearchPath.SafeDirectories | DllImportSearchPath.AssemblyDirectory)] + namespace Java.Interop { delegate int DestroyJavaVMDelegate (IntPtr javavm); diff --git a/src/Java.Runtime.Environment/Java.Interop/JreRuntime.cs b/src/Java.Runtime.Environment/Java.Interop/JreRuntime.cs index d495226dc..21eb5d35a 100644 --- a/src/Java.Runtime.Environment/Java.Interop/JreRuntime.cs +++ b/src/Java.Runtime.Environment/Java.Interop/JreRuntime.cs @@ -7,6 +7,8 @@ using System.Runtime.InteropServices; using System.Threading; +[assembly: DefaultDllImportSearchPathsAttribute (DllImportSearchPath.SafeDirectories | DllImportSearchPath.AssemblyDirectory)] + namespace Java.Interop { struct JavaVMInitArgs { diff --git a/src/java-interop/java-interop-dlfcn.cc b/src/java-interop/java-interop-dlfcn.cc new file mode 100644 index 000000000..15fa8c6cb --- /dev/null +++ b/src/java-interop/java-interop-dlfcn.cc @@ -0,0 +1,173 @@ +#include "java-interop.h" +#include "java-interop-dlfcn.h" +#include "java-interop-util.h" + +#ifdef WINDOWS +#include +#include +#include +#include +#else +#include +#endif + +static char * +_get_last_dlerror () +{ +#ifdef WINDOWS + + DWORD error = GetLastError (); + if (error == ERROR_SUCCESS /* 0 */) { + return nullptr; + } + + wchar_t *buf = nullptr; + + DWORD size = FormatMessageW ( + /* dwFlags */ FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |FORMAT_MESSAGE_IGNORE_INSERTS, + /* lpSource */ NULL, + /* dwMessageId */ error, + /* dwLanguageId */ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + /* lpBuffer */ (LPWSTR) &buf, + /* nSize */ 0, + /* Arguments */ NULL + ); + if (size == 0) + return nullptr; + + char *message = utf16_to_utf8 (buf); + LocalFree (buf); + + return message; + +#else // ndef WINDOWS + + return java_interop_strdup (dlerror ()); + +#endif // ndef WINDOWS +} + +void* +java_interop_load_library (const char *path, unsigned int flags, char **error) +{ + if (error != nullptr) { + java_interop_free (*error); + *error = nullptr; + } + if (path == nullptr) { + if (error != nullptr) + *error = java_interop_strdup ("path=nullptr is not supported"); + return nullptr; + } + if (flags != 0) { + if (error != nullptr) + *error = java_interop_strdup ("flags has unsupported value"); + return nullptr; + } + + void *handle = nullptr; + +#ifdef WINDOWS + + wchar_t *wpath = utf8_to_utf16 (path); + if (path == nullptr) { + if (error != nullptr) + *error = java_interop_strdup ("could not convert path to UTF-16"); + return nullptr; + } + HMODULE module = LoadLibraryExW ( + /* lpLibFileName */ wpath, + /* hFile */ nullptr, + /* dwFlags */ LOAD_LIBRARY_SEARCH_APPLICATION_DIR | LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR | LOAD_LIBRARY_SEARCH_USER_DIRS + ); + java_interop_free (wpath); + + handle = reinterpret_cast(module); + +#else // ndef WINDOWS + + handle = dlopen (path, RTLD_LAZY | RTLD_LOCAL); + +#endif // ndef WINDOWS + + if (handle == nullptr && error != nullptr) { + *error = _get_last_dlerror (); + } + + return handle; +} + +void* +java_interop_get_symbol_address (void *library, const char *symbol, char **error) +{ + if (error != nullptr) { + java_interop_free (*error); + *error = nullptr; + } + + if (library == nullptr) { + if (error != nullptr) + *error = java_interop_strdup ("library=nullptr"); + return nullptr; + } + if (symbol == nullptr) { + if (error != nullptr) + *error = java_interop_strdup ("symbol=nullptr"); + return nullptr; + } + + void *address = nullptr; + +#ifdef WINDOWS + + HMODULE module = reinterpret_cast(library); + FARPROC a = GetProcAddress (module, symbol); + address = reinterpret_cast(a); + +#else // ndef WINDOWS + + address = dlsym (library, symbol); + +#endif // ndef WINDOWS + + if (address == nullptr && error != nullptr) { + *error = _get_last_dlerror (); + } + + return address; +} + +int +java_interop_close_library (void* library, char **error) +{ + if (error != nullptr) { + java_interop_free (*error); + *error = nullptr; + } + if (library == nullptr) { + if (error != nullptr) + *error = java_interop_strdup ("library=nullptr"); + return JAVA_INTEROP_LIBRARY_INVALID_PARAM; + } + + int r = 0; + +#ifdef WINDOWS + HMODULE h = reinterpret_cast(library); + BOOL v = FreeLibrary (h); + if (!v) { + r = JAVA_INTEROP_LIBRARY_CLOSE_FAILED; + } +#else // ndef WINDOWS + r = dlclose (library); + if (r != 0) { + r = JAVA_INTEROP_LIBRARY_CLOSE_FAILED; + } +#endif // ndef WINDOWS + + if (r != 0 && error != nullptr) { + *error = _get_last_dlerror (); + } + + return r; +} diff --git a/src/java-interop/java-interop-dlfcn.h b/src/java-interop/java-interop-dlfcn.h new file mode 100644 index 000000000..0a5cd03dc --- /dev/null +++ b/src/java-interop/java-interop-dlfcn.h @@ -0,0 +1,20 @@ +#ifndef INC_JAVA_INTEROP_DLFCN_H +#define INC_JAVA_INTEROP_DLFCN_H + +#include "java-interop.h" + +JAVA_INTEROP_BEGIN_DECLS + +// Possible error codes from java_interop_close_library +constexpr int JAVA_INTEROP_LIBRARY_FAILED = -1000; +constexpr int JAVA_INTEROP_LIBRARY_CLOSE_FAILED = JAVA_INTEROP_LIBRARY_FAILED-1; +constexpr int JAVA_INTEROP_LIBRARY_INVALID_PARAM = JAVA_INTEROP_LIBRARY_FAILED-2; + + +JAVA_INTEROP_API void* java_interop_load_library (const char *path, unsigned int flags, char **error); +JAVA_INTEROP_API void* java_interop_get_symbol_address (void* library, const char *symbol, char **error); +JAVA_INTEROP_API int java_interop_close_library (void* library, char **error); + +JAVA_INTEROP_END_DECLS + +#endif /* INC_JAVA_INTEROP_DLFCN_H */ diff --git a/src/java-interop/java-interop-gc-bridge-mono.cc b/src/java-interop/java-interop-gc-bridge-mono.cc index ceac33a42..4f921f032 100644 --- a/src/java-interop/java-interop-gc-bridge-mono.cc +++ b/src/java-interop/java-interop-gc-bridge-mono.cc @@ -24,8 +24,6 @@ #include "logger.h" #endif /* !defined (ANDROID) */ -#include - #if defined (ANDROID) || defined (XAMARIN_ANDROID_DYLIB_MONO) using namespace xamarin::android; #endif @@ -76,23 +74,6 @@ struct JavaInteropGCBridge { int gref_cleanup, lref_cleanup; }; -typedef char* (*MonoThreadGetNameUtf8)(MonoThread*); -typedef int32_t (*MonoThreadGetManagedId)(MonoThread*); - -static MonoThreadGetManagedId _mono_thread_get_managed_id; -static MonoThreadGetNameUtf8 _mono_thread_get_name_utf8; - -static void -lookup_optional_mono_thread_functions (void) -{ - void *h = dlopen (NULL, RTLD_LAZY); - if (!h) - return; - - _mono_thread_get_managed_id = reinterpret_cast(dlsym (h, "mono_thread_get_managed_id")); - _mono_thread_get_name_utf8 = reinterpret_cast(dlsym (h, "mono_thread_get_name_utf8")); -} - static jobject lref_to_gref (JNIEnv *env, jobject lref) { @@ -275,8 +256,6 @@ java_interop_gc_bridge_new (JavaVM *jvm) } #endif /* defined (XAMARIN_ANDROID_DYLIB_MONO) */ - lookup_optional_mono_thread_functions (); - JavaInteropGCBridge bridge = {0}; bridge.jvm = jvm; @@ -1237,26 +1216,15 @@ gc_is_bridge_object (MonoObject *object) static char * get_thread_name (void) { - if (_mono_thread_get_name_utf8) { - MonoThread *thread = mono_thread_current (); - return _mono_thread_get_name_utf8 (thread); - } - return strdup ("finalizer"); + MonoThread *thread = mono_thread_current (); + return mono_thread_get_name_utf8 (thread); } static int64_t get_thread_id (void) { - if (_mono_thread_get_managed_id) { - MonoThread *thread = mono_thread_current (); - return _mono_thread_get_managed_id (thread); - } -#if __linux__ - int64_t tid = (int64_t)((pid_t)syscall(SYS_gettid)); -#else - int64_t tid = (int64_t) pthread_self (); -#endif - return tid; + MonoThread *thread = mono_thread_current (); + return mono_thread_get_managed_id (thread); } static void diff --git a/src/java-interop/java-interop-gc-bridge.h b/src/java-interop/java-interop-gc-bridge.h index e188c039f..8c8444cb6 100644 --- a/src/java-interop/java-interop-gc-bridge.h +++ b/src/java-interop/java-interop-gc-bridge.h @@ -19,41 +19,41 @@ struct JavaInterop_System_RuntimeTypeHandle { void *value; }; -MONO_API JavaInteropGCBridge *java_interop_gc_bridge_get_current (void); -MONO_API int java_interop_gc_bridge_set_current_once (JavaInteropGCBridge *bridge); +JAVA_INTEROP_API JavaInteropGCBridge *java_interop_gc_bridge_get_current (void); +JAVA_INTEROP_API int java_interop_gc_bridge_set_current_once (JavaInteropGCBridge *bridge); -MONO_API JavaInteropGCBridge *java_interop_gc_bridge_new (JavaVM *jvm); -MONO_API int java_interop_gc_bridge_free (JavaInteropGCBridge *bridge); +JAVA_INTEROP_API JavaInteropGCBridge *java_interop_gc_bridge_new (JavaVM *jvm); +JAVA_INTEROP_API int java_interop_gc_bridge_free (JavaInteropGCBridge *bridge); -MONO_API int java_interop_gc_bridge_register_hooks (JavaInteropGCBridge *bridge, int weak_ref_kind); -MONO_API int java_interop_gc_bridge_wait_for_bridge_processing (JavaInteropGCBridge *bridge); +JAVA_INTEROP_API int java_interop_gc_bridge_register_hooks (JavaInteropGCBridge *bridge, int weak_ref_kind); +JAVA_INTEROP_API int java_interop_gc_bridge_wait_for_bridge_processing (JavaInteropGCBridge *bridge); -MONO_API int java_interop_gc_bridge_add_current_app_domain (JavaInteropGCBridge *bridge); -MONO_API int java_interop_gc_bridge_remove_current_app_domain (JavaInteropGCBridge *bridge); +JAVA_INTEROP_API int java_interop_gc_bridge_add_current_app_domain (JavaInteropGCBridge *bridge); +JAVA_INTEROP_API int java_interop_gc_bridge_remove_current_app_domain (JavaInteropGCBridge *bridge); -MONO_API int java_interop_gc_bridge_set_bridge_processing_field (JavaInteropGCBridge *bridge, struct JavaInterop_System_RuntimeTypeHandle type_handle, char *field_name); -MONO_API int java_interop_gc_bridge_register_bridgeable_type (JavaInteropGCBridge *bridge, struct JavaInterop_System_RuntimeTypeHandle type_handle); -MONO_API int java_interop_gc_bridge_enable (JavaInteropGCBridge *bridge, int enable); +JAVA_INTEROP_API int java_interop_gc_bridge_set_bridge_processing_field (JavaInteropGCBridge *bridge, struct JavaInterop_System_RuntimeTypeHandle type_handle, char *field_name); +JAVA_INTEROP_API int java_interop_gc_bridge_register_bridgeable_type (JavaInteropGCBridge *bridge, struct JavaInterop_System_RuntimeTypeHandle type_handle); +JAVA_INTEROP_API int java_interop_gc_bridge_enable (JavaInteropGCBridge *bridge, int enable); -MONO_API int java_interop_gc_bridge_get_gref_count (JavaInteropGCBridge *bridge); -MONO_API int java_interop_gc_bridge_get_weak_gref_count (JavaInteropGCBridge *bridge); +JAVA_INTEROP_API int java_interop_gc_bridge_get_gref_count (JavaInteropGCBridge *bridge); +JAVA_INTEROP_API int java_interop_gc_bridge_get_weak_gref_count (JavaInteropGCBridge *bridge); -MONO_API int java_interop_gc_bridge_lref_set_log_file (JavaInteropGCBridge *bridge, const char *gref_log_file); -MONO_API FILE* java_interop_gc_bridge_lref_get_log_file (JavaInteropGCBridge *bridge); -MONO_API int java_interop_gc_bridge_lref_set_log_level (JavaInteropGCBridge *bridge, int level); -MONO_API void java_interop_gc_bridge_lref_log_message (JavaInteropGCBridge *bridge, int level, const char *message); -MONO_API void java_interop_gc_bridge_lref_log_new (JavaInteropGCBridge *bridge, int lref_count, jobject curHandle, char curType, jobject newHandle, char newType, const char *thread_name, int64_t thread_id, const char *from); -MONO_API void java_interop_gc_bridge_lref_log_delete (JavaInteropGCBridge *bridge, int lref_count, jobject handle, char type, const char *thread_name, int64_t thread_id, const char *from); +JAVA_INTEROP_API int java_interop_gc_bridge_lref_set_log_file (JavaInteropGCBridge *bridge, const char *gref_log_file); +JAVA_INTEROP_API FILE* java_interop_gc_bridge_lref_get_log_file (JavaInteropGCBridge *bridge); +JAVA_INTEROP_API int java_interop_gc_bridge_lref_set_log_level (JavaInteropGCBridge *bridge, int level); +JAVA_INTEROP_API void java_interop_gc_bridge_lref_log_message (JavaInteropGCBridge *bridge, int level, const char *message); +JAVA_INTEROP_API void java_interop_gc_bridge_lref_log_new (JavaInteropGCBridge *bridge, int lref_count, jobject curHandle, char curType, jobject newHandle, char newType, const char *thread_name, int64_t thread_id, const char *from); +JAVA_INTEROP_API void java_interop_gc_bridge_lref_log_delete (JavaInteropGCBridge *bridge, int lref_count, jobject handle, char type, const char *thread_name, int64_t thread_id, const char *from); -MONO_API int java_interop_gc_bridge_gref_set_log_file (JavaInteropGCBridge *bridge, const char *gref_log_file); -MONO_API FILE* java_interop_gc_bridge_gref_get_log_file (JavaInteropGCBridge *bridge); -MONO_API int java_interop_gc_bridge_gref_set_log_level (JavaInteropGCBridge *bridge, int level); -MONO_API void java_interop_gc_bridge_gref_log_message (JavaInteropGCBridge *bridge, int level, const char *message); -MONO_API int java_interop_gc_bridge_gref_log_new (JavaInteropGCBridge *bridge, jobject curHandle, char curType, jobject newHandle, char newType, const char *thread_name, int64_t thread_id, const char *from); -MONO_API int java_interop_gc_bridge_gref_log_delete (JavaInteropGCBridge *bridge, jobject handle, char type, const char *thread_name, int64_t thread_id, const char *from); +JAVA_INTEROP_API int java_interop_gc_bridge_gref_set_log_file (JavaInteropGCBridge *bridge, const char *gref_log_file); +JAVA_INTEROP_API FILE* java_interop_gc_bridge_gref_get_log_file (JavaInteropGCBridge *bridge); +JAVA_INTEROP_API int java_interop_gc_bridge_gref_set_log_level (JavaInteropGCBridge *bridge, int level); +JAVA_INTEROP_API void java_interop_gc_bridge_gref_log_message (JavaInteropGCBridge *bridge, int level, const char *message); +JAVA_INTEROP_API int java_interop_gc_bridge_gref_log_new (JavaInteropGCBridge *bridge, jobject curHandle, char curType, jobject newHandle, char newType, const char *thread_name, int64_t thread_id, const char *from); +JAVA_INTEROP_API int java_interop_gc_bridge_gref_log_delete (JavaInteropGCBridge *bridge, jobject handle, char type, const char *thread_name, int64_t thread_id, const char *from); -MONO_API int java_interop_gc_bridge_weak_gref_log_new (JavaInteropGCBridge *bridge, jobject curHandle, char curType, jobject newHandle, char newType, const char *thread_name, int64_t thread_id, const char *from); -MONO_API int java_interop_gc_bridge_weak_gref_log_delete (JavaInteropGCBridge *bridge, jobject handle, char type, const char *thread_name, int64_t thread_id, const char *from); +JAVA_INTEROP_API int java_interop_gc_bridge_weak_gref_log_new (JavaInteropGCBridge *bridge, jobject curHandle, char curType, jobject newHandle, char newType, const char *thread_name, int64_t thread_id, const char *from); +JAVA_INTEROP_API int java_interop_gc_bridge_weak_gref_log_delete (JavaInteropGCBridge *bridge, jobject handle, char type, const char *thread_name, int64_t thread_id, const char *from); JAVA_INTEROP_END_DECLS diff --git a/src/java-interop/java-interop-jvm.cc b/src/java-interop/java-interop-jvm.cc index c3a62846c..2546342b7 100644 --- a/src/java-interop/java-interop-jvm.cc +++ b/src/java-interop/java-interop-jvm.cc @@ -1,7 +1,7 @@ #include -#include #include "java-interop-jvm.h" +#include "java-interop-dlfcn.h" #include "java-interop-logger.h" #include "java-interop-util.h" @@ -33,11 +33,13 @@ java_interop_jvm_load_with_error_message (const char *path, char **error_message return JAVA_INTEROP_JVM_FAILED_OOM; } - jvm->dl_handle = dlopen (path, RTLD_LAZY); + char *error = nullptr; + jvm->dl_handle = java_interop_load_library (path, 0, &error); if (!jvm->dl_handle) { if (error_message) { - *error_message = java_interop_strdup (dlerror ()); + *error_message = java_interop_strdup (error); } + free (error); free (jvm); jvm = NULL; return JAVA_INTEROP_JVM_FAILED_NOT_LOADED; @@ -46,10 +48,12 @@ java_interop_jvm_load_with_error_message (const char *path, char **error_message int symbols_missing = 0; #define LOAD_SYMBOL_CAST(symbol, Type) do { \ - jvm->symbol = reinterpret_cast(dlsym (jvm->dl_handle, #symbol)); \ + error = nullptr; \ + jvm->symbol = reinterpret_cast(java_interop_get_symbol_address (jvm->dl_handle, #symbol, &error)); \ if (!jvm->symbol) { \ - log_error (LOG_DEFAULT, "Failed to load JVM symbol: %s", #symbol); \ + log_error (LOG_DEFAULT, "Failed to load JVM symbol: %s: %s", #symbol, error); \ symbols_missing = 1; \ + free (error); \ } \ } while (0) #define LOAD_SYMBOL(symbol) LOAD_SYMBOL_CAST(symbol, java_interop_ ## symbol ## _fptr) @@ -61,7 +65,7 @@ java_interop_jvm_load_with_error_message (const char *path, char **error_message #undef LOAD_SYMBOL if (symbols_missing) { - dlclose (jvm->dl_handle); + java_interop_close_library (jvm->dl_handle, nullptr); free (jvm); jvm = NULL; return JAVA_INTEROP_JVM_FAILED_SYMBOL_MISSING; diff --git a/src/java-interop/java-interop-jvm.h b/src/java-interop/java-interop-jvm.h index 1b083ca1c..1086a92fb 100644 --- a/src/java-interop/java-interop-jvm.h +++ b/src/java-interop/java-interop-jvm.h @@ -13,10 +13,10 @@ JAVA_INTEROP_BEGIN_DECLS #define JAVA_INTEROP_JVM_FAILED_OOM (JAVA_INTEROP_JVM_FAILED-3) #define JAVA_INTEROP_JVM_FAILED_SYMBOL_MISSING (JAVA_INTEROP_JVM_FAILED-4) -MONO_API int java_interop_jvm_load (const char *path); -MONO_API int java_interop_jvm_load_with_error_message (const char *path, char **error); -MONO_API int java_interop_jvm_create (JavaVM **p_vm, void **p_env, void *vm_args); -MONO_API int java_interop_jvm_list (JavaVM **vmBuf, int bufLen, int *nVMs); +JAVA_INTEROP_API int java_interop_jvm_load (const char *path); +JAVA_INTEROP_API int java_interop_jvm_load_with_error_message (const char *path, char **error); +JAVA_INTEROP_API int java_interop_jvm_create (JavaVM **p_vm, void **p_env, void *vm_args); +JAVA_INTEROP_API int java_interop_jvm_list (JavaVM **vmBuf, int bufLen, int *nVMs); JAVA_INTEROP_END_DECLS diff --git a/src/java-interop/java-interop-mono.h b/src/java-interop/java-interop-mono.h index f27eeaa23..4cfb6a3a1 100644 --- a/src/java-interop/java-interop-mono.h +++ b/src/java-interop/java-interop-mono.h @@ -3,43 +3,13 @@ #include "java-interop.h" -#if defined (XAMARIN_ANDROID_DYLIB_MONO) - - #include "dylib-mono.h" - #include "monodroid-glue.h" - - #define mono_class_from_mono_type (monodroid_get_dylib ()->class_from_mono_type) - #define mono_class_from_name (monodroid_get_dylib ()->class_from_name) - #define mono_class_get_field_from_name (monodroid_get_dylib ()->class_get_field_from_name) - #define mono_class_get_name (monodroid_get_dylib ()->class_get_name) - #define mono_class_get_namespace (monodroid_get_dylib ()->class_get_namespace) - #define mono_class_is_subclass_of (monodroid_get_dylib ()->class_is_subclass_of) - #define mono_class_vtable (monodroid_get_dylib ()->class_vtable) - #define mono_domain_get (monodroid_get_dylib ()->domain_get) - #define mono_field_get_value (monodroid_get_dylib ()->field_get_value) - #define mono_field_set_value (monodroid_get_dylib ()->field_set_value) - #define mono_field_static_set_value (monodroid_get_dylib ()->field_static_set_value) - #define mono_object_get_class (monodroid_get_dylib ()->object_get_class) - #define mono_thread_attach (monodroid_get_dylib ()->thread_attach) - #define mono_thread_current (monodroid_get_dylib ()->thread_current) - #define mono_gc_register_bridge_callbacks (monodroid_get_dylib ()->gc_register_bridge_callbacks) - #define mono_gc_wait_for_bridge_processing (monodroid_get_dylib ()->gc_wait_for_bridge_processing) - -#else /* !defined (XAMARIN_ANDROID_DYLIB_MONO) */ - - #undef MONO_API_EXPORT - #undef MONO_API_IMPORT - #undef MONO_API - - #include - #include - #include - #include - #include - #include - #include - -#endif /* !defined (XAMARIN_ANDROID_DYLIB_MONO) */ +#include +#include +#include +#include +#include +#include +#include JAVA_INTEROP_BEGIN_DECLS diff --git a/src/java-interop/java-interop-util.h b/src/java-interop/java-interop-util.h index 50d52cd89..64f8dc1a6 100644 --- a/src/java-interop/java-interop-util.h +++ b/src/java-interop/java-interop-util.h @@ -1,6 +1,8 @@ #ifndef __JAVA_INTEROP_UTIL_H__ #define __JAVA_INTEROP_UTIL_H__ +#include + #ifdef WINDOWS /* Those two conversion functions are only properly implemented on Windows * because that's the only place where they should be useful. @@ -44,7 +46,7 @@ _assert_valid_pointer (void *p, size_t size) } log_fatal (LOG_DEFAULT, "Out of memory!"); - exit (FATAL_EXIT_OUT_OF_MEMORY); + std::exit (FATAL_EXIT_OUT_OF_MEMORY); } return p; diff --git a/src/java-interop/java-interop.csproj b/src/java-interop/java-interop.csproj index 404807066..9654add4b 100644 --- a/src/java-interop/java-interop.csproj +++ b/src/java-interop/java-interop.csproj @@ -4,7 +4,7 @@ $(ToolOutputFullPath) $(BuildToolOutputFullPath) java-interop - JI_DLL_EXPORT MONODEVELOP MONO_DLL_EXPORT + JI_DLL_EXPORT MONODEVELOP JAVA_INTEROP_DLL_EXPORT . @@ -18,8 +18,12 @@ + + + + @@ -37,6 +41,7 @@ + diff --git a/src/java-interop/java-interop.h b/src/java-interop/java-interop.h index e0f3a44c4..1a2051215 100644 --- a/src/java-interop/java-interop.h +++ b/src/java-interop/java-interop.h @@ -5,26 +5,26 @@ #if defined(_MSC_VER) - #define MONO_API_EXPORT __declspec(dllexport) - #define MONO_API_IMPORT __declspec(dllimport) + #define JAVA_INTEROP_API_EXPORT __declspec(dllexport) + #define JAVA_INTEROP_API_IMPORT __declspec(dllimport) #else /* defined(_MSC_VER */ #ifdef __GNUC__ - #define MONO_API_EXPORT __attribute__ ((visibility ("default"))) + #define JAVA_INTEROP_API_EXPORT __attribute__ ((visibility ("default"))) #else - #define MONO_API_EXPORT + #define JAVA_INTEROP_API_EXPORT #endif - #define MONO_API_IMPORT + #define JAVA_INTEROP_API_IMPORT #endif /* !defined(_MSC_VER) */ -#if defined(MONO_DLL_EXPORT) - #define MONO_API MONO_API_EXPORT -#elif defined(MONO_DLL_IMPORT) - #define MONO_API MONO_API_IMPORT -#else /* !defined(MONO_DLL_IMPORT) && !defined(MONO_API_IMPORT) */ - #define MONO_API +#if defined(MONO_DLL_EXPORT) || defined(JAVA_INTEROP_DLL_EXPORT) + #define JAVA_INTEROP_API JAVA_INTEROP_API_EXPORT +#elif defined(MONO_DLL_IMPORT) || defined(JAVA_INTEROP_DLL_IMPORT) + #define JAVA_INTEROP_API JAVA_INTEROP_API_IMPORT +#else /* !defined(MONO_DLL_IMPORT) && !defined(MONO_DLL_EXPORT) */ + #define JAVA_INTEROP_API #endif /* MONO_DLL_EXPORT... */ #ifdef __cplusplus @@ -37,8 +37,8 @@ JAVA_INTEROP_BEGIN_DECLS -MONO_API char *java_interop_strdup (const char* value); -MONO_API void java_interop_free (void *p); +JAVA_INTEROP_API char *java_interop_strdup (const char* value); +JAVA_INTEROP_API void java_interop_free (void *p); JAVA_INTEROP_END_DECLS diff --git a/src/java-interop/java-interop.targets b/src/java-interop/java-interop.targets index 87f5ec272..06e5370f3 100644 --- a/src/java-interop/java-interop.targets +++ b/src/java-interop/java-interop.targets @@ -9,43 +9,60 @@ <_MacLib>$(OutputPath)/lib$(OutputName).dylib + <_UnixLib>$(OutputPath)/lib$(OutputName).so - + + $([MSBuild]::Unescape($(DefineSymbols.Replace(' ', ';')))) + $([MSBuild]::Unescape($(_MonoIncludePath)));$([MSBuild]::Unescape($(_JdkIncludePath))) + obj/$(Configuration)/%(Filename).o + + + + + Inputs="@(ClCompile);@(ClInclude)" + Outputs="%(ClCompile.Obj)"> + <_Cl Include="@(ClCompile)"> + gcc -std=c99 -fPIC + g++ -std=c++17 -fPIC + <_Defines Include="%(ClCompile.PreprocessorDefinitions)" /> <_Includes Include="%(ClCompile.AdditionalIncludeDirectories)" /> <_Arch Condition=" Exists ('/Library/Frameworks/') ">-m64 - <_Cc Condition=" '%(ClCompile.Extension)' == '.c' ">gcc -std=c99 -fPIC - <_Cc Condition=" '%(ClCompile.Extension)' == '.cc' ">g++ -std=c++11 -fPIC <_Def>@(_Defines->'-D%(Identity)', ' ') <_Inc>@(_Includes->'-I "%(Identity)"', ' ') + + <_Objs Include="%(ClCompile.Obj)" /> + <_LinkFlags>-fvisibility=hidden -Wl,-undefined -Wl,suppress -Wl,-flat_namespace <_Libs>$(MonoLibs) - <_Files>@(ClCompile->'obj\$(Configuration)\%(Filename).o', ' ') + <_Files>@(_Objs->'%(Identity)', ' ') - + @@ -53,28 +70,25 @@ - - <_FixedDefines>$(DefineSymbols.Split(' ')) - + DependsOnTargets="_CompileUnixObjectFiles" + Inputs="@(ClCompile->'%(Obj)')" + Outputs="$(_UnixLib)"> - <_Defines Include="$(_FixedDefines)" /> + <_Objs Include="%(ClCompile.Obj)" /> <_LinkFlags>-fvisibility=hidden -Wl,-undefined -Wl,suppress -Wl,-flat_namespace -fPIC <_Libs>$(MonoLibs) - <_Files>@(ClCompile->'obj\$(Configuration)\%(Filename).o', ' ') + <_Files>@(_Objs->'%(Identity)', ' ') - +