Skip to content

Commit a4994b5

Browse files
committed
Add several write barriers needed to comply with strict wbarrier mode
1 parent e65f2b0 commit a4994b5

File tree

5 files changed

+20
-0
lines changed

5 files changed

+20
-0
lines changed

mono/metadata/appdomain.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,13 +198,15 @@ create_domain_objects (MonoDomain *domain)
198198
mono_error_assert_ok (&error);
199199
mono_field_static_set_value (string_vt, string_empty_fld, empty_str);
200200
domain->empty_string = empty_str;
201+
mono_gc_wbarrier_generic_nostore (&domain->empty_string);
201202

202203
/*
203204
* Create an instance early since we can't do it when there is no memory.
204205
*/
205206
arg = mono_string_new_checked (domain, "Out of memory", &error);
206207
mono_error_assert_ok (&error);
207208
domain->out_of_memory_ex = mono_exception_from_name_two_strings_checked (mono_defaults.corlib, "System", "OutOfMemoryException", arg, NULL, &error);
209+
mono_gc_wbarrier_generic_nostore (&domain->out_of_memory_ex);
208210
mono_error_assert_ok (&error);
209211

210212
/*
@@ -214,14 +216,17 @@ create_domain_objects (MonoDomain *domain)
214216
arg = mono_string_new_checked (domain, "A null value was found where an object instance was required", &error);
215217
mono_error_assert_ok (&error);
216218
domain->null_reference_ex = mono_exception_from_name_two_strings_checked (mono_defaults.corlib, "System", "NullReferenceException", arg, NULL, &error);
219+
mono_gc_wbarrier_generic_nostore (&domain->null_reference_ex);
217220
mono_error_assert_ok (&error);
218221
arg = mono_string_new_checked (domain, "The requested operation caused a stack overflow.", &error);
219222
mono_error_assert_ok (&error);
220223
domain->stack_overflow_ex = mono_exception_from_name_two_strings_checked (mono_defaults.corlib, "System", "StackOverflowException", arg, NULL, &error);
224+
mono_gc_wbarrier_generic_nostore (&domain->stack_overflow_ex);
221225
mono_error_assert_ok (&error);
222226

223227
/*The ephemeron tombstone i*/
224228
domain->ephemeron_tombstone = mono_object_new_checked (domain, mono_defaults.object_class, &error);
229+
mono_gc_wbarrier_generic_nostore (&domain->ephemeron_tombstone);
225230
mono_error_assert_ok (&error);
226231

227232
if (domain != old_domain) {
@@ -292,7 +297,9 @@ mono_runtime_init_checked (MonoDomain *domain, MonoThreadStartCB start_cb, MonoT
292297

293298
ad->data = domain;
294299
domain->domain = ad;
300+
mono_gc_wbarrier_generic_nostore (&domain->domain);
295301
domain->setup = setup;
302+
mono_gc_wbarrier_generic_nostore (&domain->setup);
296303

297304
mono_thread_attach (domain);
298305

mono/metadata/domain.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -923,6 +923,7 @@ mono_domain_set_internal_with_options (MonoDomain *domain, gboolean migrate_exce
923923

924924
SET_APPDOMAIN (domain);
925925
SET_APPCONTEXT (domain->default_context);
926+
mono_gc_wbarrier_generic_nostore (&domain->default_context);
926927

927928
if (migrate_exception) {
928929
thread = mono_thread_internal_current ();

mono/metadata/icall.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2479,6 +2479,7 @@ ves_icall_RuntimeType_GetInterfaces (MonoReflectionTypeHandle ref_type, MonoErro
24792479
g_hash_table_destroy (iface_hash);
24802480
if (!domain->empty_types) {
24812481
domain->empty_types = mono_array_new_cached (domain, mono_defaults.runtimetype_class, 0, error);
2482+
mono_gc_wbarrier_generic_nostore (&domain->empty_types);
24822483
goto_if_nok (error, fail);
24832484
}
24842485
return MONO_HANDLE_NEW (MonoArray, domain->empty_types);

mono/metadata/reflection.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,10 @@ mono_type_get_object_checked (MonoDomain *domain, MonoType *type, MonoError *err
534534
mono_g_hash_table_insert (domain->type_hash, type, res);
535535

536536
if (type->type == MONO_TYPE_VOID)
537+
{
537538
domain->typeof_void = (MonoObject*)res;
539+
mono_gc_wbarrier_generic_nostore (&domain->typeof_void);
540+
}
538541

539542
mono_domain_unlock (domain);
540543
mono_loader_unlock ();

mono/metadata/threads.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,7 @@ set_current_thread_for_domain (MonoDomain *domain, MonoInternalThread *thread, M
523523

524524
g_assert (!*current_thread_ptr);
525525
*current_thread_ptr = current;
526+
mono_gc_wbarrier_generic_nostore (current_thread_ptr);
526527
}
527528

528529
static MonoThread*
@@ -1781,6 +1782,7 @@ mono_thread_current (void)
17811782
if (!*current_thread_ptr) {
17821783
g_assert (domain != mono_get_root_domain ());
17831784
*current_thread_ptr = create_thread_object (domain, internal);
1785+
mono_gc_wbarrier_generic_nostore (current_thread_ptr);
17841786
}
17851787
return *current_thread_ptr;
17861788
}
@@ -1798,6 +1800,7 @@ mono_thread_current_for_thread (MonoInternalThread *internal)
17981800
if (!*current_thread_ptr) {
17991801
g_assert (domain != mono_get_root_domain ());
18001802
*current_thread_ptr = create_thread_object (domain, internal);
1803+
mono_gc_wbarrier_generic_nostore (current_thread_ptr);
18011804
}
18021805
return *current_thread_ptr;
18031806
}
@@ -4139,10 +4142,13 @@ mono_alloc_static_data (gpointer **static_data_ptr, guint32 offset, void *alloc_
41394142
if (mono_gc_user_markers_supported ())
41404143
static_data [i] = g_malloc0 (static_data_size [i]);
41414144
else
4145+
{
41424146
static_data [i] = mono_gc_alloc_fixed (static_data_size [i], MONO_GC_DESCRIPTOR_NULL,
41434147
threadlocal ? MONO_ROOT_SOURCE_THREAD_STATIC : MONO_ROOT_SOURCE_CONTEXT_STATIC,
41444148
alloc_key,
41454149
threadlocal ? "ThreadStatic Fields" : "ContextStatic Fields");
4150+
mono_gc_wbarrier_generic_nostore (static_data + i);
4151+
}
41464152
}
41474153
}
41484154

@@ -4221,6 +4227,7 @@ context_adjust_static_data (MonoAppContext *ctx)
42214227
if (context_static_info.offset || context_static_info.idx > 0) {
42224228
guint32 offset = MAKE_SPECIAL_STATIC_OFFSET (context_static_info.idx, context_static_info.offset, 0);
42234229
mono_alloc_static_data (&ctx->static_data, offset, ctx, FALSE);
4230+
mono_gc_wbarrier_generic_nostore (&ctx->static_data);
42244231
ctx->data->static_data = ctx->static_data;
42254232
}
42264233
}
@@ -4250,6 +4257,7 @@ alloc_context_static_data_helper (gpointer key, gpointer value, gpointer user)
42504257

42514258
guint32 offset = GPOINTER_TO_UINT (user);
42524259
mono_alloc_static_data (&ctx->static_data, offset, ctx, FALSE);
4260+
mono_gc_wbarrier_generic_nostore (&ctx->static_data);
42534261
ctx->data->static_data = ctx->static_data;
42544262
}
42554263

0 commit comments

Comments
 (0)