Skip to content

Commit 6fe6e2f

Browse files
authored
Merge pull request #1134 from Unity-Technologies/unity-master-fix-1103205
Grow StackSlotInfo array rather than asserting (case 1103205)
2 parents 98e7978 + 547555d commit 6fe6e2f

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

mono/mini/mini.c

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,6 +1157,7 @@ mono_allocate_stack_slots2 (MonoCompile *cfg, gboolean backward, guint32 *stack_
11571157
StackSlotInfo *scalar_stack_slots, *vtype_stack_slots, *slot_info;
11581158
MonoType *t;
11591159
int nvtypes;
1160+
int vtype_stack_slots_size = 256;
11601161
gboolean reuse_slot;
11611162

11621163
LSCAN_DEBUG (printf ("Allocate Stack Slots 2 for %s:\n", mono_method_full_name (cfg->method, TRUE)));
@@ -1235,14 +1236,22 @@ mono_allocate_stack_slots2 (MonoCompile *cfg, gboolean backward, guint32 *stack_
12351236
/* Fall through */
12361237
case MONO_TYPE_VALUETYPE:
12371238
if (!vtype_stack_slots)
1238-
vtype_stack_slots = (StackSlotInfo *)mono_mempool_alloc0 (cfg->mempool, sizeof (StackSlotInfo) * 256);
1239+
vtype_stack_slots = (StackSlotInfo *)mono_mempool_alloc0 (cfg->mempool, sizeof (StackSlotInfo) * vtype_stack_slots_size);
12391240
for (i = 0; i < nvtypes; ++i)
12401241
if (t->data.klass == vtype_stack_slots [i].vtype)
12411242
break;
12421243
if (i < nvtypes)
12431244
slot_info = &vtype_stack_slots [i];
12441245
else {
1245-
g_assert (nvtypes < 256);
1246+
if (nvtypes == vtype_stack_slots_size) {
1247+
int new_slots_size = vtype_stack_slots_size * 2;
1248+
StackSlotInfo* new_slots = (StackSlotInfo *)mono_mempool_alloc0 (cfg->mempool, sizeof (StackSlotInfo) * new_slots_size);
1249+
1250+
memcpy (new_slots, vtype_stack_slots, sizeof (StackSlotInfo) * vtype_stack_slots_size);
1251+
1252+
vtype_stack_slots = new_slots;
1253+
vtype_stack_slots_size = new_slots_size;
1254+
}
12461255
vtype_stack_slots [nvtypes].vtype = t->data.klass;
12471256
slot_info = &vtype_stack_slots [nvtypes];
12481257
nvtypes ++;
@@ -1468,6 +1477,7 @@ mono_allocate_stack_slots (MonoCompile *cfg, gboolean backward, guint32 *stack_s
14681477
StackSlotInfo *scalar_stack_slots, *vtype_stack_slots, *slot_info;
14691478
MonoType *t;
14701479
int nvtypes;
1480+
int vtype_stack_slots_size = 256;
14711481
gboolean reuse_slot;
14721482

14731483
if ((cfg->num_varinfo > 0) && MONO_VARINFO (cfg, 0)->interval)
@@ -1533,14 +1543,22 @@ mono_allocate_stack_slots (MonoCompile *cfg, gboolean backward, guint32 *stack_s
15331543
/* Fall through */
15341544
case MONO_TYPE_VALUETYPE:
15351545
if (!vtype_stack_slots)
1536-
vtype_stack_slots = (StackSlotInfo *)mono_mempool_alloc0 (cfg->mempool, sizeof (StackSlotInfo) * 256);
1546+
vtype_stack_slots = (StackSlotInfo *)mono_mempool_alloc0 (cfg->mempool, sizeof (StackSlotInfo) * vtype_stack_slots_size);
15371547
for (i = 0; i < nvtypes; ++i)
15381548
if (t->data.klass == vtype_stack_slots [i].vtype)
15391549
break;
15401550
if (i < nvtypes)
15411551
slot_info = &vtype_stack_slots [i];
15421552
else {
1543-
g_assert (nvtypes < 256);
1553+
if (nvtypes == vtype_stack_slots_size) {
1554+
int new_slots_size = vtype_stack_slots_size * 2;
1555+
StackSlotInfo* new_slots = (StackSlotInfo *)mono_mempool_alloc0 (cfg->mempool, sizeof (StackSlotInfo) * new_slots_size);
1556+
1557+
memcpy (new_slots, vtype_stack_slots, sizeof (StackSlotInfo) * vtype_stack_slots_size);
1558+
1559+
vtype_stack_slots = new_slots;
1560+
vtype_stack_slots_size = new_slots_size;
1561+
}
15441562
vtype_stack_slots [nvtypes].vtype = t->data.klass;
15451563
slot_info = &vtype_stack_slots [nvtypes];
15461564
nvtypes ++;

0 commit comments

Comments
 (0)