Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Runtime optimization + x64 bug fix #107

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

velter
Copy link
Contributor

@velter velter commented Jun 10, 2015

Two changes :

  • Passing of procptr parameters is broken on x64 (at least for delphi / windows). Technicaly it is a record and a record must be passed by ref not on the stack. Current code lead to AV. I don't know how free pascal handle this.
    Calling of proc parameter is not supported on x64 right now because of missing implementation, but this proposed change at least prevent a crash.
  • Optimization to create the CallData List only if needed. It's only used for some array (and now for procptr params)

Two changes :
* Passing of procptr parameters is broken (at least on delphi / windows). Technicaly it is a record and a record must be passed by ref not on the stack. Current code lead to AV.
Calling of proc parameter is not supported on x64 right now because of missing implementation, but this proposed change at least prevent a crash.
* Optimization to create the CallData List only if needed. It's only used for some array (and now for procptr params)
@carlokok
Copy link
Member

  •        TMethodCallData(p^).AType:=255; <<
    

Is that specific to newer delphi versions? Call records didn't use have a field like that.

@velter
Copy link
Contributor Author

velter commented Oct 20, 2015

TMethodCallData.AType is only used inside pascal script to handle destruction of CallData list after the call. A pointer to TMethodCallData.Data is passed to the called function.
CallData list can contain Array which need to be properly freed with DestroyOpenArray and TMethodCallData which need to be freed. The AType member is used to discriminate between these two cases.

@carlokok
Copy link
Member

the calldata change looks fine, and so does the 255 change. But previously we stored 2 pointers on the stack (ptr + data); According to this: http://docwiki.embarcadero.com/RADStudio/Seattle/en/Program_Control

it's passed as two pointers.

@velter
Copy link
Contributor Author

velter commented Nov 17, 2015

You are right, but the current implementation crash in the function call prolog. The link you reference seem to be only for 32bit and I can't find any documentation about this.
I come up with this change by doing some reverse analysis with the debugger and it seems that under delphi x64, method pointer parameter are treated as a record. The delphi compiler allocate the record on the calling function stack but pass a pointer on it to the called function (either in a register or on the stack as any other pointer depending on the parameter number).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants