Skip to content

Commit

Permalink
Don’t initialize arguments on frame creation, only the stack and locals
Browse files Browse the repository at this point in the history
Though, need to make sure I initialize the bootstrap frame arguments. Otherwise, we may run into uninitialized memory.

Signed-off-by: Stefan Marr <[email protected]>
  • Loading branch information
smarr committed Aug 11, 2024
1 parent 5193b61 commit 4ce1f21
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/vm/Universe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,11 @@ vm_oop_t Universe::interpretMethod(VMObject* receiver, VMInvokable* initialize,
VMMethod* bootstrapMethod = createBootstrapMethod(load_ptr(systemClass), 2);

VMFrame* bootstrapFrame = Interpreter::PushNewFrame(bootstrapMethod);
for (size_t argIdx = 0; argIdx < bootstrapMethod->GetNumberOfArguments();
argIdx += 1) {
bootstrapFrame->SetArgument((long)argIdx, (long)0, load_ptr(nilObject));
}

bootstrapFrame->Push(receiver);

if (argumentsArray != nullptr) {
Expand Down Expand Up @@ -720,7 +725,8 @@ VMFrame* Universe::NewFrame(VMFrame* previousFrame, VMMethod* method) {
method->GetMaximumNumberOfStackElements();

size_t additionalBytes = length * sizeof(VMObject*);
result = new (GetHeap<HEAP_CLS>(), additionalBytes) VMFrame(additionalBytes, method, previousFrame);
result = new (GetHeap<HEAP_CLS>(), additionalBytes)
VMFrame(additionalBytes, method, previousFrame);

LOG_ALLOCATION("VMFrame", result->GetObjectSize());
return result;
Expand Down
4 changes: 2 additions & 2 deletions src/vmobjects/VMFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ class VMFrame : public VMObject {
// --> until end of Frame
gc_oop_t* end = (gc_oop_t*)SHIFTED_PTR(this, totalObjectSize);
size_t i = 0;
while (arguments + i < end) {
arguments[i] = nilObject;
while (locals + i < end) {
locals[i] = nilObject;
i++;
}
}
Expand Down

0 comments on commit 4ce1f21

Please sign in to comment.