Skip to content

Commit 14e5681

Browse files
Clear ghost-refs from old stack area
1 parent b8e02b3 commit 14e5681

File tree

4 files changed

+22
-0
lines changed

4 files changed

+22
-0
lines changed

bin/NativeTests/JsRTApiTest.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ namespace JsRTApiTest
128128
valueRef = JS_INVALID_REFERENCE;
129129
valueRefFromWeakRef = JS_INVALID_REFERENCE;
130130

131+
CHECK(JsPrivateClearStack() == JsNoError);
131132
CHECK(JsCollectGarbage(runtime) == JsNoError);
132133

133134
// JsGetWeakReferenceValue should return an invalid reference after the value was GC'd.

lib/Jsrt/ChakraCore.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2017,6 +2017,16 @@ JsGetEmbedderData(_In_ JsValueRef instance, _Out_ JsValueRef* embedderData);
20172017
CHAKRA_API
20182018
JsSetEmbedderData(_In_ JsValueRef instance, _In_ JsValueRef embedderData);
20192019

2020+
/// <summary>
2021+
/// Clear some of the inaccessible part of the stack.
2022+
/// </summary>
2023+
/// <returns>
2024+
/// The code <c>JsNoError</c> if the operation succeeded, a failure code
2025+
/// otherwise.
2026+
/// </returns>
2027+
CHAKRA_API
2028+
JsPrivateClearStack();
2029+
20202030
#ifdef _WIN32
20212031
#include "ChakraCoreWindows.h"
20222032
#endif // _WIN32

lib/Jsrt/Jsrt.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,16 @@ CHAKRA_API JsCollectGarbage(_In_ JsRuntimeHandle runtimeHandle)
475475
}
476476

477477
#ifdef ENABLE_DEBUG_CONFIG_OPTIONS
478+
CHAKRA_API JsPrivateClearStack()
479+
{
480+
// https://github.com/bdwgc/bdwgc/blob/e1042aa86d9403f433a2ab38ee2aab081984fca8/misc.c#L260-L285
481+
482+
const int SMALL_CLEAR_SIZE = 256;
483+
volatile void* dummy[SMALL_CLEAR_SIZE];
484+
std::memset((void*)dummy, 0, sizeof(dummy));
485+
return JsNoError;
486+
}
487+
478488
CHAKRA_API JsPrivateCollectGarbageSkipStack(_In_ JsRuntimeHandle runtimeHandle)
479489
{
480490
return JsCollectGarbageCommon<CollectNowExhaustiveSkipStack>(runtimeHandle);

lib/Jsrt/JsrtCommonExports.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
JsSetObjectBeforeCollectCallback
22
JsCreateRuntime
33
JsCollectGarbage
4+
JsPrivateClearStack
45
JsDisposeRuntime
56
JsAddRef
67
JsRelease

0 commit comments

Comments
 (0)