Skip to content

Commit

Permalink
wazevo: adds 16 bytes to the new stack size (#1823)
Browse files Browse the repository at this point in the history
Signed-off-by: Takeshi Yoneda <[email protected]>
  • Loading branch information
mathetake authored Oct 31, 2023
1 parent a4df8d3 commit 546af90
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
3 changes: 1 addition & 2 deletions internal/engine/wazevo/call_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,6 @@ const callStackCeiling = uintptr(5000000) // in uint64 (8 bytes) == 40000000 byt
func (c *callEngine) growStackWithGuarded() (newSP uintptr, err error) {
if wazevoapi.StackGuardCheckEnabled {
wazevoapi.CheckStackGuardPage(c.stack)
c.execCtx.stackGrowRequiredSize += wazevoapi.StackGuardCheckGuardPageSize
}
newSP, err = c.growStack()
if err != nil {
Expand All @@ -420,7 +419,7 @@ func (c *callEngine) growStack() (newSP uintptr, err error) {
return
}

newLen := 2*currentLen + c.execCtx.stackGrowRequiredSize
newLen := 2*currentLen + c.execCtx.stackGrowRequiredSize + 16 // Stack might be aligned to 16 bytes, so add 16 bytes just in case.
newStack := make([]byte, newLen)

relSp := c.stackTop - uintptr(unsafe.Pointer(c.execCtx.stackPointerBeforeGoCall))
Expand Down
2 changes: 1 addition & 1 deletion internal/engine/wazevo/call_engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestCallEngine_growStack(t *testing.T) {
}
newSP, err := c.growStack()
require.NoError(t, err)
require.Equal(t, 160+32*2, len(c.stack))
require.Equal(t, 160+32*2+16, len(c.stack))

require.True(t, c.stackTop%16 == 0)
require.Equal(t, &c.stack[0], c.execCtx.stackBottomPtr)
Expand Down

0 comments on commit 546af90

Please sign in to comment.