Skip to content

Commit fd3e07f

Browse files
authored
Merge pull request #1348 from Unity-Technologies/unity-master-fix-threadstatic-alignment
Ensure special static slots respect alignment (case 1266322)
2 parents 9c25d81 + 7222336 commit fd3e07f

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
@@ -113,6 +113,7 @@ struct _StaticDataFreeList {
113113
StaticDataFreeList *next;
114114
guint32 offset;
115115
guint32 size;
116+
gint32 align;
116117
};
117118

118119
typedef struct {
@@ -4381,12 +4382,12 @@ alloc_context_static_data_helper (gpointer key, gpointer value, gpointer user)
43814382
}
43824383

43834384
static StaticDataFreeList*
4384-
search_slot_in_freelist (StaticDataInfo *static_data, guint32 size, guint32 align)
4385+
search_slot_in_freelist (StaticDataInfo *static_data, guint32 size, gint32 align)
43854386
{
43864387
StaticDataFreeList* prev = NULL;
43874388
StaticDataFreeList* tmp = static_data->freelist;
43884389
while (tmp) {
4389-
if (tmp->size == size) {
4390+
if (tmp->size == size && tmp->align == align) {
43904391
if (prev)
43914392
prev->next = tmp->next;
43924393
else
@@ -4544,7 +4545,7 @@ free_context_static_data_helper (gpointer key, gpointer value, gpointer user)
45444545
}
45454546

45464547
static void
4547-
do_free_special_slot (guint32 offset, guint32 size)
4548+
do_free_special_slot (guint32 offset, guint32 size, gint32 align)
45484549
{
45494550
guint32 static_type = ACCESS_SPECIAL_STATIC_OFFSET (offset, type);
45504551
MonoBitSet **sets;
@@ -4577,6 +4578,7 @@ do_free_special_slot (guint32 offset, guint32 size)
45774578

45784579
item->offset = offset;
45794580
item->size = size;
4581+
item->align = align;
45804582

45814583
item->next = info->freelist;
45824584
info->freelist = item;
@@ -4591,7 +4593,7 @@ do_free_special (gpointer key, gpointer value, gpointer data)
45914593
gint32 align;
45924594
guint32 size;
45934595
size = mono_type_size (field->type, &align);
4594-
do_free_special_slot (offset, size);
4596+
do_free_special_slot (offset, size, align);
45954597
}
45964598

45974599
void

0 commit comments

Comments
 (0)