Skip to content

Commit 93a7fe7

Browse files
monojenkinsjoncham
andauthored
Ensure special static slots respect alignment. (#20506)
Without proper alignment, this may lead to reference types being stored at non-pointer aligned offsets. Among other issues this may lead to the GC not scanning those pointers properly. Co-authored-by: Jonathan Chambers <joncham@gmail.com>
1 parent 3db5b35 commit 93a7fe7

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

mono/metadata/threads.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ struct _StaticDataFreeList {
125125
StaticDataFreeList *next;
126126
guint32 offset;
127127
guint32 size;
128+
gint32 align;
128129
};
129130

130131
typedef struct {
@@ -4744,12 +4745,12 @@ alloc_context_static_data_helper (gpointer key, gpointer value, gpointer user)
47444745
}
47454746

47464747
static StaticDataFreeList*
4747-
search_slot_in_freelist (StaticDataInfo *static_data, guint32 size, guint32 align)
4748+
search_slot_in_freelist (StaticDataInfo *static_data, guint32 size, gint32 align)
47484749
{
47494750
StaticDataFreeList* prev = NULL;
47504751
StaticDataFreeList* tmp = static_data->freelist;
47514752
while (tmp) {
4752-
if (tmp->size == size) {
4753+
if (tmp->size == size && tmp->align == align) {
47534754
if (prev)
47544755
prev->next = tmp->next;
47554756
else
@@ -4907,7 +4908,7 @@ free_context_static_data_helper (gpointer key, gpointer value, gpointer user)
49074908
}
49084909

49094910
static void
4910-
do_free_special_slot (guint32 offset, guint32 size)
4911+
do_free_special_slot (guint32 offset, guint32 size, gint32 align)
49114912
{
49124913
guint32 static_type = ACCESS_SPECIAL_STATIC_OFFSET (offset, type);
49134914
MonoBitSet **sets;
@@ -4940,6 +4941,7 @@ do_free_special_slot (guint32 offset, guint32 size)
49404941

49414942
item->offset = offset;
49424943
item->size = size;
4944+
item->align = align;
49434945

49444946
item->next = info->freelist;
49454947
info->freelist = item;
@@ -4954,7 +4956,7 @@ do_free_special (gpointer key, gpointer value, gpointer data)
49544956
gint32 align;
49554957
guint32 size;
49564958
size = mono_type_size (field->type, &align);
4957-
do_free_special_slot (offset, size);
4959+
do_free_special_slot (offset, size, align);
49584960
}
49594961

49604962
void

0 commit comments

Comments
 (0)