We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 5699702 commit b8bede4Copy full SHA for b8bede4
lib/Jsrt/Jsrt.cpp
@@ -479,9 +479,14 @@ CHAKRA_API JsGarbageCollectionClearStack()
479
{
480
// https://github.com/bdwgc/bdwgc/blob/e1042aa86d9403f433a2ab38ee2aab081984fca8/misc.c#L260-L285
481
482
- const int SMALL_CLEAR_SIZE = 256;
+ constexpr int SMALL_CLEAR_SIZE = 256;
483
volatile void *dummy[SMALL_CLEAR_SIZE];
484
- memset((void *)dummy, 0, sizeof(dummy));
+
485
+ // https://news.ycombinator.com/item?id=4711605
486
+ // Zero memory + prevent compiler optimizations
487
+ volatile unsigned char *bp = (unsigned char *)dummy;
488
+ while (bp < (unsigned char *)dummy + sizeof(dummy))
489
+ *bp++ = 0;
490
return JsNoError;
491
}
492
0 commit comments