Skip to content

Commit a454f7f

Browse files
committed
Add Native GC host getter and setter on Recycler.
1 parent 5ec0ca7 commit a454f7f

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

lib/Common/Memory/Recycler.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -937,6 +937,18 @@ Recycler::SetIsInScript(bool isInScript)
937937
this->isInScript = isInScript;
938938
}
939939

940+
bool
941+
Recycler::HasNativeGCHost() const
942+
{
943+
return this->hasNativeGCHost;
944+
}
945+
946+
void
947+
Recycler::SetHasNativeGCHost()
948+
{
949+
this->hasNativeGCHost = true;
950+
}
951+
940952
bool
941953
Recycler::NeedOOMRescan() const
942954
{
@@ -1680,7 +1692,7 @@ Recycler::ScanStack()
16801692

16811693
BEGIN_DUMP_OBJECT(this, _u("Registers"));
16821694
// We will not scan interior pointers on stack if we are not in script or we are in mem-protect mode.
1683-
if (!this->isInScript || this->IsMemProtectMode())
1695+
if (!this->HasNativeGCHost() && (!this->isInScript || this->IsMemProtectMode()))
16841696
{
16851697
if (doSpecialMark)
16861698
{
@@ -1699,7 +1711,7 @@ Recycler::ScanStack()
16991711
{
17001712
// We may have interior pointers on the stack such as pointers in the middle of the character buffers backing a JavascriptString or SubString object.
17011713
// To prevent UAFs of these buffers after the GC we will always do MarkInterior for the pointers on stack. This is necessary only when we are doing a
1702-
// GC while running a script as that is when the possiblity of a UAF after GC exists.
1714+
// GC while running a script or when we have a host who allocates objects on the Chakra heap.
17031715
if (doSpecialMark)
17041716
{
17051717
ScanMemoryInline<true, true /* forceInterior */>(this->savedThreadContext.GetRegisters(), sizeof(void*) * SavedRegisterState::NumRegistersToSave
@@ -1715,7 +1727,7 @@ Recycler::ScanStack()
17151727

17161728
BEGIN_DUMP_OBJECT(this, _u("Stack"));
17171729
// We will not scan interior pointers on stack if we are not in script or we are in mem-protect mode.
1718-
if (!this->isInScript || this->IsMemProtectMode())
1730+
if (!this->HasNativeGCHost() && (!this->isInScript || this->IsMemProtectMode()))
17191731
{
17201732
if (doSpecialMark)
17211733
{
@@ -1732,7 +1744,7 @@ Recycler::ScanStack()
17321744
{
17331745
// We may have interior pointers on the stack such as pointers in the middle of the character buffers backing a JavascriptString or SubString object.
17341746
// To prevent UAFs of these buffers after the GC we will always do MarkInterior for the pointers on stack. This is necessary only when we are doing a
1735-
// GC while running a script as that is when the possiblity of a UAF after GC exists.
1747+
// GC while running a script or when we have a host who allocates objects on the Chakra heap.
17361748
if (doSpecialMark)
17371749
{
17381750
ScanMemoryInline<true, true /* forceInterior */>((void**)stackTop, stackScanned

lib/Common/Memory/Recycler.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -908,6 +908,7 @@ class Recycler
908908
bool inDisposeWrapper;
909909
bool needOOMRescan;
910910
bool hasDisposableObject;
911+
bool hasNativeGCHost;
911912
DWORD tickCountNextDispose;
912913
bool inExhaustiveCollection;
913914
bool hasExhaustiveCandidate;
@@ -1168,6 +1169,8 @@ class Recycler
11681169
void SetIsThreadBound();
11691170
void SetIsScriptActive(bool isScriptActive);
11701171
void SetIsInScript(bool isInScript);
1172+
bool HasNativeGCHost() const;
1173+
void SetHasNativeGCHost();
11711174
bool ShouldIdleCollectOnExit();
11721175
void ScheduleNextCollection();
11731176

0 commit comments

Comments
 (0)