From 92290b154d1d053352c7662e449d33bbf9081e2c Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Wed, 18 Mar 2020 16:30:33 -0400 Subject: [PATCH 1/7] [mini] Move mono_install_load_aot_data_hook to a public header It's already a MONO_API and it is used, for example, by Xamarin.iOS, but it wasn't in a public header. Mark it external only. There are no uses of it inside the runtiem --- src/mono/mono/mini/aot-runtime.h | 10 ---------- src/mono/mono/mini/jit.h | 12 +++++++++++- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/mono/mono/mini/aot-runtime.h b/src/mono/mono/mini/aot-runtime.h index cd399c0ce1b3ba..292c759970e721 100644 --- a/src/mono/mono/mini/aot-runtime.h +++ b/src/mono/mono/mini/aot-runtime.h @@ -273,16 +273,6 @@ gboolean mono_aot_init_llvmonly_method (gpointer amodule, guint32 method_in GHashTable *mono_aot_get_weak_field_indexes (MonoImage *image); MonoAotMethodFlags mono_aot_get_method_flags (guint8 *code); -/* These are used to load the AOT data for aot images compiled with MONO_AOT_FILE_FLAG_SEPARATE_DATA */ -/* - * Return the AOT data for ASSEMBLY. SIZE is the size of the data. OUT_HANDLE should be set to a handle which is later - * passed to the free function. - */ -typedef unsigned char* (*MonoLoadAotDataFunc) (MonoAssembly *assembly, int size, gpointer user_data, void **out_handle); -/* Not yet used */ -typedef void (*MonoFreeAotDataFunc) (MonoAssembly *assembly, int size, gpointer user_data, void *handle); -MONO_API void mono_install_load_aot_data_hook (MonoLoadAotDataFunc load_func, MonoFreeAotDataFunc free_func, gpointer user_data); - #ifdef MONO_ARCH_CODE_EXEC_ONLY typedef guint32 (*MonoAotResolvePltInfoOffset)(gpointer amodule, guint32 plt_entry_index); #endif diff --git a/src/mono/mono/mini/jit.h b/src/mono/mono/mini/jit.h index 9fc6a183facba7..73f2bd836c0fdf 100644 --- a/src/mono/mono/mini/jit.h +++ b/src/mono/mono/mini/jit.h @@ -109,10 +109,20 @@ mono_set_use_llvm (mono_bool use_llvm); MONO_API MONO_RT_EXTERNAL_ONLY void mono_aot_register_module (void **aot_info); +/* These are used to load the AOT data for aot images compiled with MONO_AOT_FILE_FLAG_SEPARATE_DATA */ +/* + * Return the AOT data for ASSEMBLY. SIZE is the size of the data. OUT_HANDLE should be set to a handle which is later + * passed to the free function. + */ +typedef unsigned char* (*MonoLoadAotDataFunc) (MonoAssembly *assembly, int size, void* user_data, void **out_handle); +/* Not yet used */ +typedef void (*MonoFreeAotDataFunc) (MonoAssembly *assembly, int size, void* user_data, void *handle); +MONO_API MONO_RT_EXTERNAL_ONLY void +mono_install_load_aot_data_hook (MonoLoadAotDataFunc load_func, MonoFreeAotDataFunc free_func, void* user_data); + MONO_API MONO_RT_EXTERNAL_ONLY MonoDomain* mono_jit_thread_attach (MonoDomain *domain); - MONO_END_DECLS #endif From f8f4419d3fff935d348f63bf508750877f1798db Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Wed, 18 Mar 2020 16:38:52 -0400 Subject: [PATCH 2/7] [gc] Make mono_gc_init_finalizer_thread a public API It was already used by Xamarin.iOS but wasn't in a public header and required compiling with --disable-visibility-hidden in order to dlsym the symbol. If --with-lazy-gc-thread-creation is used, embedders must call this function to create the finalizer therad. Otherwise the function does nothing and the runtime will create the finalizer thread automatically. --- src/mono/mono/metadata/gc.c | 27 +++++++++++++++++++++------ src/mono/mono/metadata/mono-gc.h | 3 +++ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/mono/mono/metadata/gc.c b/src/mono/mono/metadata/gc.c index d9fe1afbe86f88..f81963be552b9f 100644 --- a/src/mono/mono/metadata/gc.c +++ b/src/mono/mono/metadata/gc.c @@ -999,17 +999,32 @@ finalizer_thread (gpointer unused) return 0; } -#ifndef LAZY_GC_THREAD_CREATION -static -#endif -void -mono_gc_init_finalizer_thread (void) +static void +init_finalizer_thread (void) { ERROR_DECL (error); gc_thread = mono_thread_create_internal (mono_domain_get (), (gpointer)finalizer_thread, NULL, MONO_THREAD_CREATE_FLAGS_NONE, error); mono_error_assert_ok (error); } +/** + * mono_gc_init_finalizer_thread: + * + * If the runtime is compiled with --with-lazy-gc-thread-creation, this + * function must be called by embedders to create the finalizer. Otherwise, the + * function does nothing and the runtime creates the finalizer thread + * automatically. + */ +void +mono_gc_init_finalizer_thread (void) +{ +#ifndef LAZY_GC_THREAD_CREATION + /* do nothing */ +#else + init_finalizer_thread (); +#endif +} + static void reference_queue_mutex_init (void) { @@ -1048,7 +1063,7 @@ mono_gc_init (void) #ifndef LAZY_GC_THREAD_CREATION if (!mono_runtime_get_no_exec ()) - mono_gc_init_finalizer_thread (); + init_finalizer_thread (); #endif } diff --git a/src/mono/mono/metadata/mono-gc.h b/src/mono/mono/metadata/mono-gc.h index 86111ac345b88f..72c768e27d1656 100644 --- a/src/mono/mono/metadata/mono-gc.h +++ b/src/mono/mono/metadata/mono-gc.h @@ -123,6 +123,9 @@ MONO_API int mono_gc_invoke_finalizers (void); /* heap walking is only valid in the pre-stop-world event callback */ MONO_API int mono_gc_walk_heap (int flags, MonoGCReferences callback, void *data); +MONO_API MONO_RT_EXTERNAL_ONLY void +mono_gc_init_finalizer_thread (void); + MONO_END_DECLS #endif /* __METADATA_MONO_GC_H__ */ From a0cc08768e97c7b630ccbf54e48020b06436f874 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Wed, 18 Mar 2020 16:41:25 -0400 Subject: [PATCH 3/7] [utils] Move mono_trace_init to a public header It was already marked as MONO_API, but it was not in a public header. It is used by embedders such as Xamarin.iOS --- src/mono/mono/utils/mono-logger-internals.h | 3 --- src/mono/mono/utils/mono-logger.h | 3 +++ 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/mono/mono/utils/mono-logger-internals.h b/src/mono/mono/utils/mono-logger-internals.h index e6c856951c12d9..d38735a95053c5 100644 --- a/src/mono/mono/utils/mono-logger-internals.h +++ b/src/mono/mono/utils/mono-logger-internals.h @@ -36,9 +36,6 @@ MONO_API_DATA GLogLevelFlags mono_internal_current_level; MONO_API_DATA MonoTraceMask mono_internal_current_mask; MONO_END_DECLS -MONO_API void -mono_trace_init (void); - void mono_trace_cleanup (void); diff --git a/src/mono/mono/utils/mono-logger.h b/src/mono/mono/utils/mono-logger.h index a90e6c54cf365c..01f2312760aca5 100644 --- a/src/mono/mono/utils/mono-logger.h +++ b/src/mono/mono/utils/mono-logger.h @@ -17,6 +17,9 @@ mono_trace_set_mask_string (const char *value); typedef void (*MonoPrintCallback) (const char *string, mono_bool is_stdout); typedef void (*MonoLogCallback) (const char *log_domain, const char *log_level, const char *message, mono_bool fatal, void *user_data); +MONO_API void +mono_trace_init (void); + MONO_API void mono_trace_set_log_handler (MonoLogCallback callback, void *user_data); From 9b80efe97c81f6cc1513b2fd5fcb0bace5235358 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Wed, 18 Mar 2020 17:08:20 -0400 Subject: [PATCH 4/7] Update ios sample --- src/mono/netcore/sample/iOS/runtime.m | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/mono/netcore/sample/iOS/runtime.m b/src/mono/netcore/sample/iOS/runtime.m index 05f4dd2c488c96..36f0a057c30df2 100644 --- a/src/mono/netcore/sample/iOS/runtime.m +++ b/src/mono/netcore/sample/iOS/runtime.m @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -12,13 +13,6 @@ static os_log_t stdout_log; -/* These are not in public headers */ -typedef unsigned char* (*MonoLoadAotDataFunc) (MonoAssembly *assembly, int size, void *user_data, void **out_handle); -typedef void (*MonoFreeAotDataFunc) (MonoAssembly *assembly, int size, void *user_data, void *handle); -void mono_install_load_aot_data_hook (MonoLoadAotDataFunc load_func, MonoFreeAotDataFunc free_func, void *user_data); -void mono_trace_init (void); -void mono_gc_init_finalizer_thread (void); - static char *bundle_path; const char * From c7cf3af0eeef21abdefbca64963e079afd3b54b9 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Mon, 23 Mar 2020 21:18:35 -0400 Subject: [PATCH 5/7] Revert "[utils] Move mono_trace_init to a public header" This reverts commit a0cc08768e97c7b630ccbf54e48020b06436f874. --- src/mono/mono/utils/mono-logger-internals.h | 3 +++ src/mono/mono/utils/mono-logger.h | 3 --- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/mono/mono/utils/mono-logger-internals.h b/src/mono/mono/utils/mono-logger-internals.h index d38735a95053c5..e6c856951c12d9 100644 --- a/src/mono/mono/utils/mono-logger-internals.h +++ b/src/mono/mono/utils/mono-logger-internals.h @@ -36,6 +36,9 @@ MONO_API_DATA GLogLevelFlags mono_internal_current_level; MONO_API_DATA MonoTraceMask mono_internal_current_mask; MONO_END_DECLS +MONO_API void +mono_trace_init (void); + void mono_trace_cleanup (void); diff --git a/src/mono/mono/utils/mono-logger.h b/src/mono/mono/utils/mono-logger.h index 01f2312760aca5..a90e6c54cf365c 100644 --- a/src/mono/mono/utils/mono-logger.h +++ b/src/mono/mono/utils/mono-logger.h @@ -17,9 +17,6 @@ mono_trace_set_mask_string (const char *value); typedef void (*MonoPrintCallback) (const char *string, mono_bool is_stdout); typedef void (*MonoLogCallback) (const char *log_domain, const char *log_level, const char *message, mono_bool fatal, void *user_data); -MONO_API void -mono_trace_init (void); - MONO_API void mono_trace_set_log_handler (MonoLogCallback callback, void *user_data); From 6e3f02f2809d526aa5f252371a6eb08177f223af Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Mon, 23 Mar 2020 21:21:35 -0400 Subject: [PATCH 6/7] [utils] init mono_logger in all public API functions Embedders don't need to call mono_trace_init before calling mono_trace_set_log_handler, mono_trace_set_print_handler or mono_trace_set_printerr_handler --- src/mono/mono/utils/mono-logger.c | 7 +++++++ src/mono/netcore/sample/iOS/runtime.m | 1 - 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/mono/mono/utils/mono-logger.c b/src/mono/mono/utils/mono-logger.c index 174a2277db280e..14661d621a265d 100644 --- a/src/mono/mono/utils/mono-logger.c +++ b/src/mono/mono/utils/mono-logger.c @@ -449,6 +449,9 @@ mono_trace_set_log_handler (MonoLogCallback callback, void *user_data) { g_assert (callback); + if (level_stack == NULL) + mono_trace_init (); + if (logCallback.closer != NULL) logCallback.closer(); UserSuppliedLoggerUserData *ll = (UserSuppliedLoggerUserData*)g_malloc (sizeof (UserSuppliedLoggerUserData)); @@ -514,6 +517,8 @@ void mono_trace_set_print_handler (MonoPrintCallback callback) { g_assert (callback); + if (level_stack == NULL) + mono_trace_init (); print_callback = callback; g_set_print_handler (print_handler); } @@ -527,6 +532,8 @@ void mono_trace_set_printerr_handler (MonoPrintCallback callback) { g_assert (callback); + if (level_stack == NULL) + mono_trace_init (); printerr_callback = callback; g_set_printerr_handler (printerr_handler); } diff --git a/src/mono/netcore/sample/iOS/runtime.m b/src/mono/netcore/sample/iOS/runtime.m index 36f0a057c30df2..24697df9465748 100644 --- a/src/mono/netcore/sample/iOS/runtime.m +++ b/src/mono/netcore/sample/iOS/runtime.m @@ -266,7 +266,6 @@ void mono_ios_setup_execution_mode (void) mono_install_assembly_preload_hook (assembly_preload_hook, NULL); mono_install_load_aot_data_hook (load_aot_data, free_aot_data, NULL); mono_install_unhandled_exception_hook (unhandled_exception_handler, NULL); - mono_trace_init (); mono_trace_set_log_handler (log_callback, NULL); mono_set_signal_chaining (TRUE); mono_set_crash_chaining (TRUE); From 7dfc6efdb85a0c86928aa03f65642aa5418816d2 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Mon, 23 Mar 2020 21:26:24 -0400 Subject: [PATCH 7/7] [jit] Move mono_install_load_aot_data_hook to mono-private-unstable.h We do not guarantee that this API will be stable --- src/mono/mono/mini/aot-runtime.c | 1 + src/mono/mono/mini/jit.h | 11 ----------- src/mono/mono/mini/mono-private-unstable.h | 12 +++++++++++- src/mono/netcore/sample/iOS/runtime.m | 1 + 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/mono/mono/mini/aot-runtime.c b/src/mono/mono/mini/aot-runtime.c index c603e03dae7a9f..c41ee32348c176 100644 --- a/src/mono/mono/mini/aot-runtime.c +++ b/src/mono/mono/mini/aot-runtime.c @@ -71,6 +71,7 @@ #include "aot-runtime.h" #include "jit-icalls.h" #include "mini-runtime.h" +#include "mono-private-unstable.h" #include "llvmonly-runtime.h" #ifndef DISABLE_AOT diff --git a/src/mono/mono/mini/jit.h b/src/mono/mono/mini/jit.h index 73f2bd836c0fdf..011792c346b488 100644 --- a/src/mono/mono/mini/jit.h +++ b/src/mono/mono/mini/jit.h @@ -109,17 +109,6 @@ mono_set_use_llvm (mono_bool use_llvm); MONO_API MONO_RT_EXTERNAL_ONLY void mono_aot_register_module (void **aot_info); -/* These are used to load the AOT data for aot images compiled with MONO_AOT_FILE_FLAG_SEPARATE_DATA */ -/* - * Return the AOT data for ASSEMBLY. SIZE is the size of the data. OUT_HANDLE should be set to a handle which is later - * passed to the free function. - */ -typedef unsigned char* (*MonoLoadAotDataFunc) (MonoAssembly *assembly, int size, void* user_data, void **out_handle); -/* Not yet used */ -typedef void (*MonoFreeAotDataFunc) (MonoAssembly *assembly, int size, void* user_data, void *handle); -MONO_API MONO_RT_EXTERNAL_ONLY void -mono_install_load_aot_data_hook (MonoLoadAotDataFunc load_func, MonoFreeAotDataFunc free_func, void* user_data); - MONO_API MONO_RT_EXTERNAL_ONLY MonoDomain* mono_jit_thread_attach (MonoDomain *domain); diff --git a/src/mono/mono/mini/mono-private-unstable.h b/src/mono/mono/mini/mono-private-unstable.h index 805edd25c4759c..1026ef2dd9ae9f 100644 --- a/src/mono/mono/mini/mono-private-unstable.h +++ b/src/mono/mono/mini/mono-private-unstable.h @@ -13,7 +13,17 @@ #define __MONO_JIT_MONO_PRIVATE_UNSTABLE_H__ #include +#include - +/* These are used to load the AOT data for aot images compiled with MONO_AOT_FILE_FLAG_SEPARATE_DATA */ +/* + * Return the AOT data for ASSEMBLY. SIZE is the size of the data. OUT_HANDLE should be set to a handle which is later + * passed to the free function. + */ +typedef unsigned char* (*MonoLoadAotDataFunc) (MonoAssembly *assembly, int size, void* user_data, void **out_handle); +/* Not yet used */ +typedef void (*MonoFreeAotDataFunc) (MonoAssembly *assembly, int size, void* user_data, void *handle); +MONO_API MONO_RT_EXTERNAL_ONLY void +mono_install_load_aot_data_hook (MonoLoadAotDataFunc load_func, MonoFreeAotDataFunc free_func, void* user_data); #endif /*__MONO_JIT_MONO_PRIVATE_UNSTABLE_H__*/ diff --git a/src/mono/netcore/sample/iOS/runtime.m b/src/mono/netcore/sample/iOS/runtime.m index 24697df9465748..87eb4bce43e662 100644 --- a/src/mono/netcore/sample/iOS/runtime.m +++ b/src/mono/netcore/sample/iOS/runtime.m @@ -6,6 +6,7 @@ #include #include #include +#include #import #include