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__ */ 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/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..011792c346b488 100644 --- a/src/mono/mono/mini/jit.h +++ b/src/mono/mono/mini/jit.h @@ -112,7 +112,6 @@ mono_aot_register_module (void **aot_info); MONO_API MONO_RT_EXTERNAL_ONLY MonoDomain* mono_jit_thread_attach (MonoDomain *domain); - MONO_END_DECLS #endif 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/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 05f4dd2c488c96..87eb4bce43e662 100644 --- a/src/mono/netcore/sample/iOS/runtime.m +++ b/src/mono/netcore/sample/iOS/runtime.m @@ -3,8 +3,10 @@ #include #include #include +#include #include #include +#include #import #include @@ -12,13 +14,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 * @@ -272,7 +267,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);