Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2018-01

question about _fpc_local_unwind

7 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Matias Vara

Hello eveyryone,

in my rtl for torokernel, I have to implement "_fpc_local_unwind()" however I am not sure about the expected behavior of this function. It appers in the code when I use "Exit" inside a "try finally" structure. I would like to know what this function should do. So if someone can point me to some documetation would be very helpful,

Thanks, Matias.

Reply by email

Matias Vara
to Matias Vara

Hello,
I partial answered my question by reading
https://www.freepascal.org/docs-html/ref/refse114.html. So I think _fpc_local_unwind() is used to call the finally section when "Exit" is executed in the "Try" section. It is not clear yet what the parameters "frame,target: Pointer" are meant to. I checked the code generated in Linux and is a bit different. It is base on the functions FPC_PUSHEXCEPTADDR and FPC_POPADDRSTACK, which It seems much more clear. Is it possible to generate a similar code in the case of Win64? In other words, is it possible to tell the compiler "generate the 'try-finally-end' block as in Linux"? I don't think so but It is worth to ask.

Thanks, Matias.

2018-01-31 11:17 GMT+01:00 Matias Vara :

Show quoted text 11 lines
Hello eveyryone, in my rtl for torokernel, I have to implement "_fpc_local_unwind()" however I am not sure about the expected behavior of this function. It appers in the code when I use "Exit" inside a "try finally" structure. I would like to know what this function should do. So if someone can point me to some documetation would be very helpful, Thanks, Matias.

Reply by email

Jonas Maebe
to Matias Vara
Matias Vara wrote 11 lines
I partial answered my question by reading https://www.freepascal.org/docs-html/ref/refse114.html. So I think _fpc_local_unwind() is used to call the finally section when "Exit" is executed in the "Try" section. It is not clear yet what the parameters "frame,target: Pointer" are meant to. I checked the code generated in Linux and is a bit different. It is base on the functions FPC_PUSHEXCEPTADDR and FPC_POPADDRSTACK, which It seems much more clear. Is it possible to generate a similar code in the case of Win64? In other words, is it possible to tell the compiler "generate the 'try-finally-end' block as in Linux"? I don't think so but It is worth to ask.

No, it is not possible. On Win64 the compiler and RTL use so-called structured exception handling (SEH), which is required to interoperate with code generated by other compilers. See
https://msdn.microsoft.com/en-us/library/windows/desktop/ms680657(v=vs.85).aspx for more information.

Jonas

Reply by email

Matias Vara
to Jonas Maebe

Thanks for the answer, I will imitate in Toro the behavior of Win64.

Matias

2018-02-01 20:49 GMT+01:00 Jonas Maebe :

Show quoted text 24 lines
On 01/02/18 16:24, Matias Vara wrote: > I partial answered my question by reading https://www.freepascal.org/doc > s-html/ref/refse114.html. So I think _fpc_local_unwind() is used to call > the finally section when "Exit" is executed in the "Try" section. It is not > clear yet what the parameters "frame,target: Pointer" are meant to. I > checked the code generated in Linux and is a bit different. It is base on > the functions FPC_PUSHEXCEPTADDR and FPC_POPADDRSTACK, which It seems much > more clear. Is it possible to generate a similar code in the case of Win64? > In other words, is it possible to tell the compiler "generate the > 'try-finally-end' block as in Linux"? I don't think so but It is worth to > ask. > No, it is not possible. On Win64 the compiler and RTL use so-called structured exception handling (SEH), which is required to interoperate with code generated by other compilers. See https://msdn.microsoft.com/en- us/library/windows/desktop/ms680657(v=vs.85).aspx for more information. Jonas _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply by email

Sven Barth
to Matias Vara

Am 02.02.2018 15:50 schrieb "Matias Vara" :

Thanks for the answer, I will imitate in Toro the behavior of Win64.

Maybe it wound be better if you try to use the i386-embedded or x86_64-embedded targets. The non-embedded targets are simply not geared towards usage on a bare platform.

Regards,
Sven

Reply by email

Matias Vara
to Sven Barth

Hello,

2018-02-02 17:17 GMT+01:00 Sven Barth via fpc-pascal <

Show quoted text 13 lines
: Am 02.02.2018 15 <02%2002%2020%2018%2015>:50 schrieb "Matias Vara" < >: Thanks for the answer, I will imitate in Toro the behavior of Win64. Maybe it wound be better if you try to use the i386-embedded or x86_64-embedded targets. The non-embedded targets are simply not geared towards usage on a bare platform

Thanks for the suggestion, I don't think I am able to do that since the whole kernel compiles well by using the Win64 target. So I am not planing to change the target. I notice that the code is in rtl/win64/seh64.inc so I am starting to try to understand it.

Matias

Show quoted text 7 lines
Regards, Sven _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply by email

Sven Barth
to Matias Vara

Am 02.02.2018 18:12 schrieb "Matias Vara" :

Hello,

2018-02-02 17:17 GMT+01:00 Sven Barth via fpc-pascal <

Show quoted text 13 lines
: Am 02.02.2018 15 <02%2002%2020%2018%2015>:50 schrieb "Matias Vara" < >: Thanks for the answer, I will imitate in Toro the behavior of Win64. Maybe it wound be better if you try to use the i386-embedded or x86_64-embedded targets. The non-embedded targets are simply not geared towards usage on a bare platform

Thanks for the suggestion, I don't think I am able to do that since the whole kernel compiles well by using the Win64 target. So I am not planing to change the target. I notice that the code is in rtl/win64/seh64.inc so I am starting to try to understand it.

Most of the exception handling and unwinding is done by Windows, relying on specific sections in the binary. You essentially picked one of the worst targets to implement your kernel with...
Another plus of the embedded target: you can disable RTL features that you don't need (e.g. RTTI, threading, etc.).

Regards,
Sven

Regards,
Sven

Reply by email