Skip to content

Commit d76a27d

Browse files
authored
Merge pull request #84 from Unity-Technologies/fix-root-overflow
Fix mark stack overflow with roots (case DOTS-8962).
2 parents 63dccb9 + d0a8081 commit d76a27d

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

include/gc_mark.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,14 @@ GC_API struct GC_ms_entry * GC_CALL GC_mark_and_push(void * /* obj */,
152152
(GC_word)(obj) <= (GC_word)GC_greatest_plausible_heap_addr ? \
153153
GC_mark_and_push(obj, msp, lim, src) : (msp))
154154

155+
GC_API struct GC_ms_entry * GC_CALL GC_custom_push_range(void * /* bottom */, void * /* top */,
156+
struct GC_ms_entry * /* mark_stack_ptr */,
157+
struct GC_ms_entry * /* mark_stack_limit */);
158+
159+
GC_API struct GC_ms_entry * GC_CALL GC_custom_push_proc(GC_word /* proc */, void * /* start */,
160+
struct GC_ms_entry * /* mark_stack_ptr */,
161+
struct GC_ms_entry * /* mark_stack_limit */);
162+
155163
GC_API size_t GC_debug_header_size;
156164
/* The size of the header added to objects allocated through */
157165
/* the GC_debug routines. */
@@ -287,6 +295,9 @@ GC_API void GC_CALL GC_push_conditional(void * /* bottom */, void * /* top */,
287295
int /* bool all */);
288296
GC_API void GC_CALL GC_push_finalizer_structures(void);
289297

298+
299+
GC_API void GC_CALL GC_push_proc(GC_word /* proc */, void * /* start */);
300+
290301
/* Set and get the client push-other-roots procedure. A client */
291302
/* supplied procedure should also call the original procedure. */
292303
/* Note that both the setter and getter require some external */

mark.c

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,6 +1384,55 @@ GC_API void GC_CALL GC_push_all(void *bottom, void *top)
13841384
GC_mark_stack_top -> mse_descr.w = length;
13851385
}
13861386

1387+
GC_API void GC_CALL GC_push_proc(GC_word proc , void * start)
1388+
{
1389+
GC_mark_stack_top++;
1390+
if ((word)GC_mark_stack_top >= (word)GC_mark_stack_limit) {
1391+
GC_mark_stack_top = GC_signal_mark_stack_overflow (GC_mark_stack_top);
1392+
}
1393+
GC_mark_stack_top -> mse_descr.w = proc;
1394+
GC_mark_stack_top -> mse_start = (ptr_t)start;
1395+
}
1396+
1397+
GC_API struct GC_ms_entry * GC_CALL GC_custom_push_range(void * bottom , void * top,
1398+
struct GC_ms_entry * mark_stack_ptr,
1399+
struct GC_ms_entry * mark_stack_limit)
1400+
{
1401+
word length;
1402+
1403+
bottom = (void *)(((word)bottom + ALIGNMENT-1) & ~(ALIGNMENT-1));
1404+
top = (void *)((word)top & ~(ALIGNMENT-1));
1405+
if ((word)bottom >= (word)top) return mark_stack_ptr;
1406+
1407+
mark_stack_ptr++;
1408+
if ((word)mark_stack_ptr >= (word)mark_stack_limit) {
1409+
mark_stack_ptr = GC_signal_mark_stack_overflow (mark_stack_ptr);
1410+
}
1411+
length = (word)top - (word)bottom;
1412+
# if GC_DS_TAGS > ALIGNMENT - 1
1413+
length += GC_DS_TAGS;
1414+
length &= ~GC_DS_TAGS;
1415+
# endif
1416+
mark_stack_ptr -> mse_start = (ptr_t)bottom;
1417+
mark_stack_ptr -> mse_descr.w = length;
1418+
1419+
return mark_stack_ptr;
1420+
}
1421+
1422+
GC_API struct GC_ms_entry * GC_CALL GC_custom_push_proc(GC_word proc , void * start,
1423+
struct GC_ms_entry * mark_stack_ptr,
1424+
struct GC_ms_entry * mark_stack_limit)
1425+
{
1426+
mark_stack_ptr++;
1427+
if ((word)mark_stack_ptr >= (word)mark_stack_limit) {
1428+
mark_stack_ptr = GC_signal_mark_stack_overflow (mark_stack_ptr);
1429+
}
1430+
mark_stack_ptr -> mse_descr.w = proc;
1431+
mark_stack_ptr -> mse_start = (ptr_t)start;
1432+
1433+
return mark_stack_ptr;
1434+
}
1435+
13871436
#ifndef GC_DISABLE_INCREMENTAL
13881437

13891438
/* Analogous to the above, but push only those pages h with */

0 commit comments

Comments
 (0)