Safecall in Unix/Linux
Original Reporter info from Mantis: JoshyFun @joshyfun
-
Reporter name: José Mejuto
Original Reporter info from Mantis: JoshyFun @joshyfun
- Reporter name: José Mejuto
Description:
Safecall calling convention is not present in Unix/Linux and if present it is being silently replaced by "default" for the platform. Recently I was porting the Gecko interface to Linux and found the the safecall is needed for XPCOM (the COM model crossplatform of Mozilla Foundation).
Safecall in Linux works the same as in Windows, this means same parameter order, const records are being passed as pointer to record instead a record copy, a hidden parameter to receive the function result, exception code is returned in EAX, etc. The only difference is in the clearing stack which in Windows is performed by the callee while in Linux is performed by the caller (just like cdecl).
Almost everything can be "simulated" using cdecl as calling convention but the problem is that when calling functions the extra parameter to return the function result is not poped from the stack, so it remains unstable and raising a SIGSEGV when the procedure is leaved.
This problem can be solved with some assembler, but that's too complicated.
Steps to reproduce:
Compiling the "GeckoPort" in Lazarus CCR under Linux. Current version is not directly compilable because the changes to compile in Linux are in my local computer and I will not commit them unless safecall is supported in Linux because it is too dirty to add a lot of assembler and wrappers.
I can test any safecall changes in my local computer from SVN, trunk or any branch.
Additional information:
IUnknown (in XPCOM nsISupports) methods are stdcall and seems to behave the same in both platforms (Windows/Linux).
More information in the mailing list fpc-pascal thread: "Mozilla XPCOM".
Mantis conversion info:
- Mantis ID: 16685
- OS: Ubuntu Linux
- OS Build: 9.04
- Build: All
- Platform: i386
- Version: 2.5.1
- Fixed in version: 2.6.0
- Fixed in revision: 15913 (#65ab1e82)
- Monitored by: » crossbuilder (Burkhard Carstens), » Joost (Joost van der Sluis)