FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix 20170321 x64call by pult · Pull Request #149 · remobjects/pascalscript · GitHub

Fix 20170321 x64call - #149

Open
pult wants to merge 9 commits into
remobjects:masterfrom
pult:fix_20170321_x64call
Open

pult wants to merge 9 commits into
remobjects:masterfrom
pult:fix_20170321_x64call

Conversation

pult commented Mar 21, 2017

Copy link
Copy Markdown

Fixed x64call cause GPF when exception.
Added pure pascal vesion of "x64call".

Added sample "console_rops":

  • sample: {$i inc-file}
  • sample: params 7, 64
  • sample: raise exception ( procedure RaiseExceptionMessage )
  • sample: show current exception: text,file,position
  • sample: emulate reserved word "raise" ( raise current exception )

pult added 2 commits March 21, 2017 19:09
Fixed x64call cause GPF when exception.
Added pure pascal vesion.
- sample: {$i inc-file}
- sample: params 7, 64
- sample: raise exception ( procedure RaiseExceptionMessage )
- sample: show current exception: text,file,position
- sample: emulate reserved word "raise" ( raise current exception )
- TODO: AV: FPC X64 OPENARRAY ( sample "format('%s; %s',['2','2'])" )

Copy link
Copy Markdown
Member

This seems to completely reformat all files, I can't see what actually changed?

pult commented Mar 21, 2017

Copy link
Copy Markdown
Author

A few blank double lines were deleted.

Copy link
Copy Markdown
Member

I'm sorry; I can't accept a pull request that reformats > 500 lines and also does functionality changes. It would completely break the git history

pult commented Mar 21, 2017

Copy link
Copy Markdown
Author

"functionality changes" do not change, but only fixed.

pult commented Mar 21, 2017

Copy link
Copy Markdown
Author

Base code is very poorly formatted (tabs, trailed spaces, duplicated blank lines, line breaks in class declarations). :(

pult commented Mar 21, 2017

Copy link
Copy Markdown
Author

"Beyond compare" can ignore the insignificant differences in formatting.

Copy link
Copy Markdown

Tested, it works fine for me. Thanks

Copy link
Copy Markdown

Errata corrige

There is a problem with function with args and an extended value as result

Program test;
var
AValue : Extended;
begin
AValue := StrToDate('10/10/2017');
writeln(DateToStr(AValue));
end.

the result of StrToDate is always 30/12/1899

david-navigator commented Nov 6, 2019 •
edited
Loading

Copy link
Copy Markdown

Although @pult fix for GPF is brilliant and I'm not sure why it's not in the main branch, though as @albertozen2 detailed it stops any functions that return an extended value in the result from working - they don't need to have arguments, something like NOW just returns 30/12/1899.
Has anyone found a fix for this major issue ?

Copy link
Copy Markdown

i commented two lines into x64.inc code file.

movsd xmm0,[RegInfo].TRegisters._RCX
movsd xmm1,[RegInfo].TRegisters._RDX

Copy link
Copy Markdown

i commented two lines into x64.inc code file.

movsd xmm0,[RegInfo].TRegisters._RCX movsd xmm1,[RegInfo].TRegisters._RDX

Thanks @albertozen2 do you mean you removed them from x64.inc like this ?

@@skip_items:

// mov , [r9]. ; [r9] == [RegInfo]
mov rcx, [RegInfo].TRegisters._RCX
mov rdx, [RegInfo].TRegisters._RDX
mov r8, [RegInfo].TRegisters._R8

// movsd xmm0,[RegInfo].TRegisters._RCX
// movsd xmm1,[RegInfo].TRegisters._RDX
movsd xmm2,[RegInfo].TRegisters._R8
movsd xmm3,[RegInfo].TRegisters._R9

For me the result of StrToDate is still 30/12/1899 :(
Have I understood wrongly ?

Copy link
Copy Markdown

I report the full code block. The commented lines are bold
The code is between line 591 and line 610 (in my x64.inc).
I hope that change can help you

{
Alberto Zen 20/03/2018
movsd xmm0,[RegInfo].TRegisters._RCX
movsd xmm1,[RegInfo].TRegisters._RDX
}

movsd xmm2,[RegInfo].TRegisters._R8
movsd xmm3,[RegInfo].TRegisters._R9

mov r9, [RegInfo].TRegisters._R9 // !!! Overwritten RegInfo (r9)

call [rbp+c_loc_offs_adress]

// make result
mov rdx, [rbp+c_loc_offs__rax] // restore: rdx (@_RDX)
mov [rdx], RAX // fill: _RAX

{
Alberto Zen 20/03/2018
movsd [rdx+c_sz_ptr], XMM0 // fill: _XMM0
}

Copy link
Copy Markdown

i commented two lines into x64.inc code file.

movsd xmm0,[RegInfo].TRegisters._RCX movsd xmm1,[RegInfo].TRegisters._RDX

Do you mean you added to extra lines ? If so where do they go ?

I report the full code block. The commented lines are bold
The code is between line 591 and line 610 (in my x64.inc).
I hope that change can help you

{ Alberto Zen 20/03/2018 movsd xmm0,[RegInfo].TRegisters._RCX movsd xmm1,[RegInfo].TRegisters._RDX }
movsd xmm2,[RegInfo].TRegisters._R8
movsd xmm3,[RegInfo].TRegisters._R9

mov r9, [RegInfo].TRegisters._R9 // !!! Overwritten RegInfo (r9)

call [rbp+c_loc_offs_adress]

// make result
mov rdx, [rbp+c_loc_offs__rax] // restore: rdx (@_RDX)
mov [rdx], RAX // fill: _RAX

{ Alberto Zen 20/03/2018 movsd [rdx+c_sz_ptr], XMM0 // fill: _XMM0 }

I have copied you code exactly, but for me the result is still 30/12/1899 :(

Copy link
Copy Markdown

Sorry, i looked for in my repository but i didn't find other changes.
Have you rebuilt the package?

Copy link
Copy Markdown

Sorry, i looked for in my repository but i didn't find other changes.
Have you rebuilt the package?

I'm not using packages, code is just compiled in to my app. I've confirmed that the updated x64.inc file is being compiled.
Not sure I understand the code well enough to debug further without some help.
Are you using Delphi Rio too ?

Copy link
Copy Markdown

No, Berlin

pult commented Dec 31, 2019

Copy link
Copy Markdown
Author

x64.inc new fixes

Copy link
Copy Markdown

Thank You, now it works :-)

Copy link
Copy Markdown

@pult , your branch works, the official doesn't :-)
this script in official branch of PascalScript doesn't work
**_

program main;
var
myDate : TDateTime;
abuf : string;
begin
myDate := StrToDate('25/09/2020');
aBuf := DateTostr(myDate);
end.

_**
It raises an exception.

Copy link
Copy Markdown
Member

@pult you feel like checking the conflicts? I'll try to merge this next week (I do have to dig into the changes though, I see a lot of changes not relevant to this change, and I have to check them 1 by one).

Copy link
Copy Markdown

@pult @carlokok @albertozen2
Did this get merged in to the master ?
Not sure what I need to Get to build under Sydney ?

martijnlaan added a commit that referenced this pull request Jan 4, 2026
…Delphi is used.

Extracted from https://github.com/pult/pascalscript/blob/pult/Source/x64.inc
Removed many unrelated diffs, except the aType = nil check by rp.
Added SingleBits result handling. Otherwise unchanged.

According to codex, this is why the new version fixes the exception issue:

-It uses a fixed-size stack frame with compiler-described locals instead of ad-hoc pushes, so the unwinder has accurate metadata.
-It keeps RSP aligned and stable across the call, avoiding the “unknown frame” state that previously triggered eedfade when an exception crossed the trampoline.
-Stack arguments are copied into the frame rather than pushed after the prologue, so the frame layout the unwinder knows matches reality.

Also see #149.

martijnlaan commented Jan 4, 2026 •
edited
Loading

Copy link
Copy Markdown
Collaborator

I've committed the new x64call asm version which can handle exceptions, active when Delphi is used.
Extracted from https://github.com/pult/pascalscript/blob/pult/Source/x64.inc
Removed many unrelated diffs, except the aType = nil check by rp.
Added SingleBits result handling. Otherwise unchanged.

See 83b7ad0

Many thanks @pult

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.

6 participants


Back | FazBrowse Home | New Git URL