From 059898f8c0dbea2c6d0ed2ff30bc1b584af6b439 Mon Sep 17 00:00:00 2001 From: Zoltan Varga Date: Mon, 20 Mar 2023 16:08:25 -0400 Subject: [PATCH] [mono] Fix a race in gparam construction. (#83688) Re: https://github.com/dotnet/runtime/issues/81123. --- src/mono/mono/metadata/metadata.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/mono/mono/metadata/metadata.c b/src/mono/mono/metadata/metadata.c index c2821d49961583..91d8dd9564db56 100644 --- a/src/mono/mono/metadata/metadata.c +++ b/src/mono/mono/metadata/metadata.c @@ -3734,12 +3734,14 @@ publish_anon_gparam_fast (MonoImage *image, MonoGenericContainer *container, gin if (!*cache) { mono_image_lock (image); if (!*cache) { - *cache = (MonoGenericParam*)mono_image_alloc0 (image, sizeof (MonoGenericParam) * FAST_GPARAM_CACHE_SIZE); + MonoGenericParam *new_cache = (MonoGenericParam*)mono_image_alloc0 (image, sizeof (MonoGenericParam) * FAST_GPARAM_CACHE_SIZE); for (guint16 i = 0; i < FAST_GPARAM_CACHE_SIZE; ++i) { - MonoGenericParam *param = &(*cache)[i]; + MonoGenericParam *param = &new_cache[i]; param->owner = container; param->num = i; } + mono_memory_barrier (); + *cache = new_cache; } mono_image_unlock (image); }