🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

ScriptFunctionData::stackNeeded does not account for asBC_ALLOC potential stack push

Started by
3 comments, last by Asu 4 years, 1 month ago

Hi,

I found a possible problem in the compiler/VM while working on my JIT.
While I can work around it easily (so it is low priority for me), I'm suspecting this could (very rarely) cause issues in AS.

The following code:

class Foo
{
    Foo() {}

    string s;
}

void repro()
{
    Foo f;
}

Gives the following:

Function Foo::Foo()
scriptData.variableSpace: 0
scriptData.stackNeeded: 2
Disassembly:
0007: PshVPtr 0
0008: ADDSi 32
000a: ALLOC 93874889212816 19
0015: RET 2

In the VM, in the asBC_ALLOC handler, when the object to allocate is not a script object, the pointer to the allocated value is pushed to the stack. That means that at that point, two pointers have been pushed to the stack.
This is in 64-bit. Both pointers should require 4 DWORDs on the stack, yet, scriptData.stackNeeded == 2.

Since my JIT relies on scriptData.stackNeeded to determine the size of the local stack allocation, I believe I will just add the pointer size in DWORDs to that, which should suffice to work around the issue.

Advertisement

Thanks for bringing this up.

I'll look into this as soon as I can.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

What the context does when reserving stack space for a function call, it always adds space for 2 pointers beyond the stackNeeded informed in the function. You can see this done in asCContext::ReserveStackSpace.

The space for the two extra pointers is used precisely for cases like asBC_ALLOC that use a temporary stack space but also for exception handling that may require a little bit of space too.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

@WitchLord Thanks! I did not notice that. I'll have to fix my code accordingly since I only reserved one extra pointer rather than two, since that seems to be required for EH according to the RESERVE_STACK constant.

This topic is closed to new replies.

Advertisement