[arm64] Allow v8..v15 in unwind info on arm64. Fixes part of #21615.
[mono.git] / mono / metadata / boehm-gc.c
index aba4ae9fa6c67d38b825dc13ae114a7aecd04c0d..af9eff4780f5f1010bce7bb812fc7d90fa5061f1 100644 (file)
@@ -59,6 +59,9 @@ boehm_thread_unregister (MonoThreadInfo *p);
 static void
 register_test_toggleref_callback (void);
 
+#define BOEHM_GC_BIT_FINALIZER_AWARE 1
+static MonoGCFinalizerCallbacks fin_callbacks;
+
 static void
 mono_gc_warning (char *msg, GC_word arg)
 {
@@ -161,7 +164,7 @@ mono_gc_base_init (void)
                for (ptr = opts; *ptr; ++ptr) {
                        char *opt = *ptr;
                        if (g_str_has_prefix (opt, "max-heap-size=")) {
-                               glong max_heap;
+                               size_t max_heap;
 
                                opt = strchr (opt, '=') + 1;
                                if (*opt && mono_gc_parse_environment_string_extract_number (opt, &max_heap)) {
@@ -375,7 +378,8 @@ boehm_thread_unregister (MonoThreadInfo *p)
 
        tid = mono_thread_info_get_tid (p);
 
-       mono_threads_add_joinable_thread ((gpointer)tid);
+       if (p->runtime_thread)
+               mono_threads_add_joinable_thread ((gpointer)tid);
 }
 
 gboolean
@@ -1173,7 +1177,7 @@ mono_gc_conservatively_scan_area (void *start, void *end)
 }
 
 void *
-mono_gc_scan_object (void *obj)
+mono_gc_scan_object (void *obj, void *gc_data)
 {
        g_assert_not_reached ();
        return NULL;
@@ -1241,6 +1245,7 @@ void
 mono_gc_pthread_exit (void *retval)
 {
        pthread_exit (retval);
+       g_assert_not_reached ();
 }
 
 #endif
@@ -1259,6 +1264,10 @@ BOOL APIENTRY mono_gc_dllmain (HMODULE module_handle, DWORD reason, LPVOID reser
 guint
 mono_gc_get_vtable_bits (MonoClass *class)
 {
+       if (fin_callbacks.is_class_finalization_aware) {
+               if (fin_callbacks.is_class_finalization_aware (class))
+                       return BOEHM_GC_BIT_FINALIZER_AWARE;
+       }
        return 0;
 }
 
@@ -1338,4 +1347,29 @@ register_test_toggleref_callback (void)
        mono_gc_toggleref_register_callback (test_toggleref_callback);
 }
 
+static gboolean
+is_finalization_aware (MonoObject *obj)
+{
+       MonoVTable *vt = obj->vtable;
+       return (vt->gc_bits & BOEHM_GC_BIT_FINALIZER_AWARE) == BOEHM_GC_BIT_FINALIZER_AWARE;
+}
+
+static void
+fin_notifier (MonoObject *obj)
+{
+       if (is_finalization_aware (obj))
+               fin_callbacks.object_queued_for_finalization (obj);
+}
+
+void
+mono_gc_register_finalizer_callbacks (MonoGCFinalizerCallbacks *callbacks)
+{
+       if (callbacks->version != MONO_GC_FINALIZER_EXTENSION_VERSION)
+               g_error ("Invalid finalizer callback version. Expected %d but got %d\n", MONO_GC_FINALIZER_EXTENSION_VERSION, callbacks->version);
+
+       fin_callbacks = *callbacks;
+
+       GC_set_finalizer_notify_proc ((void (*) (GC_PTR))fin_notifier);
+}
+
 #endif /* no Boehm GC */