Skip to content

Commit 17c0d59

Browse files
authored
Add code to protect from GC when creating heap block arrays (#2885)
***NO_CI***
1 parent 80605d7 commit 17c0d59

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

src/CLR/Core/CLR_RT_HeapBlock_ArrayList.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ HRESULT CLR_RT_HeapBlock_ArrayList::SetCapacity(CLR_UINT32 newCapacity)
172172
CLR_RT_HeapBlock_Array *newItems;
173173

174174
memset(&newItemsHB, 0, sizeof(struct CLR_RT_HeapBlock));
175+
CLR_RT_ProtectFromGC gc(newItemsHB);
175176

176177
if (newCapacity < size)
177178
NANOCLR_SET_AND_LEAVE(CLR_E_OUT_OF_RANGE);

src/nanoFramework.System.Collections/nf_system_collections_System_Collections_Hashtable.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -408,12 +408,6 @@ HRESULT Library_nf_system_collections_System_Collections_Hashtable::Expand(CLR_R
408408
}
409409
}
410410

411-
if (i == lenghtOfPrimes)
412-
{
413-
// we are not supporting hastables bigger than this size
414-
NANOCLR_SET_AND_LEAVE(CLR_E_NOT_SUPPORTED)
415-
}
416-
417411
// Don't replace any internal state until we've finished adding to the
418412
// new Bucket[]. This serves two purposes:
419413
// 1) Allow concurrent readers to see valid hashtable contents
@@ -426,6 +420,14 @@ HRESULT Library_nf_system_collections_System_Collections_Hashtable::Expand(CLR_R
426420

427421
// create a new array of <Bucket>
428422
memset(&newBucketsHB, 0, sizeof(struct CLR_RT_HeapBlock));
423+
CLR_RT_ProtectFromGC gc(newBucketsHB);
424+
425+
if (i == lenghtOfPrimes)
426+
{
427+
// we are not supporting hastables bigger than this size
428+
NANOCLR_SET_AND_LEAVE(CLR_E_NOT_SUPPORTED)
429+
}
430+
429431
NANOCLR_CHECK_HRESULT(CLR_RT_HeapBlock_Array::CreateInstance(newBucketsHB, newSize, bucketTypeDef))
430432
newBuckets = newBucketsHB.DereferenceArray();
431433

0 commit comments

Comments
 (0)