Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit ae5551b

Browse files
committed
Additional parameter validation for StartNoGCRegion
1 parent 376814d commit ae5551b

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

src/gc/gc.cpp

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15882,14 +15882,42 @@ start_no_gc_region_status gc_heap::prepare_for_no_gc_region (uint64_t total_size
1588215882
save_data_for_no_gc();
1588315883
settings.pause_mode = pause_no_gc;
1588415884
current_no_gc_region_info.start_status = start_no_gc_success;
15885-
15885+
1588615886
size_t allocation_no_gc_loh = 0;
1588715887
size_t allocation_no_gc_soh = 0;
1588815888
size_t size_per_heap = 0;
1588915889

15890+
// requested sizes of 0 make no sense.
15891+
if (total_size == 0)
15892+
{
15893+
status = start_no_gc_too_large;
15894+
goto done;
15895+
}
15896+
15897+
if (loh_size_known)
15898+
{
15899+
if (loh_size == 0)
15900+
{
15901+
status = start_no_gc_too_large;
15902+
goto done;
15903+
}
15904+
15905+
// According to the documentation, TryStartNoGCRegion must fail if
15906+
// it can't allocate total_size - loh_size for the SOH. This only makes
15907+
// any kind of sense if total_size > loh_size.
15908+
if ((total_size - loh_size) > total_size)
15909+
{
15910+
status = start_no_gc_too_large;
15911+
goto done;
15912+
}
15913+
}
15914+
15915+
assert(total_size != 0);
1589015916
total_size = (size_t)((float)total_size * 1.05);
1589115917
if (loh_size_known)
1589215918
{
15919+
assert(loh_size != 0);
15920+
assert(total_size >= loh_size);
1589315921
loh_size = (size_t)((float)loh_size * 1.05);
1589415922
allocation_no_gc_loh = (size_t)loh_size;
1589515923
allocation_no_gc_soh = (size_t)(total_size - loh_size);

0 commit comments

Comments
 (0)