Skip to content

Commit

Permalink
Fix crash
Browse files Browse the repository at this point in the history
Force keep ByteCodeBlock* pointer in calling function routine.
Some compiler don't keep pointer of ByteCodeBlock* in stack when calling function
If don't keep the pointer, we can lose the ByteCodeBlock while GC

Signed-off-by: Seonghyun Kim <[email protected]>
  • Loading branch information
ksh8281 authored and clover2123 committed Feb 1, 2024
1 parent c884c06 commit 55a36a2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/runtime/FunctionObjectInlines.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ class FunctionObjectProcessCallGenerator {
if (std::is_same<FunctionObjectType, ScriptGeneratorFunctionObject>::value || std::is_same<FunctionObjectType, ScriptAsyncFunctionObject>::value || std::is_same<FunctionObjectType, ScriptAsyncGeneratorFunctionObject>::value) {
registerFile = (Value*)CustomAllocator<Value>().allocate(registerFileSize);
} else {
registerFile = (Value*)alloca((registerFileSize) * sizeof(Value));
// keep ByteCodeBlock pointer in registerFileBuffer
registerFile = (Value*)alloca((registerFileSize) * sizeof(Value) + sizeof(size_t));
memcpy(&registerFile[registerFileSize], &blk, sizeof(size_t));
}

Value* stackStorage = registerFile + generalRegisterSize;
Expand Down
9 changes: 7 additions & 2 deletions src/runtime/ScriptSimpleFunctionObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,11 @@ class ScriptSimpleFunctionObject : public ScriptFunctionObject {
#endif
);

char registerFileBuffer[sizeof(Value) * registerFileSize];
// keep ByteCodeBlock pointer in registerFileBuffer
char registerFileBuffer[sizeof(Value) * registerFileSize + sizeof(size_t)];
Value* registerFile = reinterpret_cast<Value*>(registerFileBuffer);
memcpy(registerFileBuffer + sizeof(Value) * registerFileSize, &blk, sizeof(size_t));

Value* stackStorage = registerFile + registerSize;

ExecutionState newState(ctx, &state, &lexEnv, argc, argv, isStrict);
Expand Down Expand Up @@ -152,8 +155,10 @@ class ScriptSimpleFunctionObject : public ScriptFunctionObject {
#endif
);

char registerFileBuffer[sizeof(Value) * registerFileSize];
// keep ByteCodeBlock pointer in registerFileBuffer
char registerFileBuffer[sizeof(Value) * registerFileSize + sizeof(size_t)];
Value* registerFile = reinterpret_cast<Value*>(registerFileBuffer);
memcpy(registerFileBuffer + sizeof(Value) * registerFileSize, &blk, sizeof(size_t));
Value* stackStorage = registerFile + registerSize;

ExecutionState newState(ctx, &state, &lexEnv, argc, argv, isStrict);
Expand Down

0 comments on commit 55a36a2

Please sign in to comment.