pharo-users@lists.pharo.org

Any question about pharo is welcome

View all threads

Re: uFFI: Calling conventions?

E
egarrulo
Fri, Aug 27, 2021 4:50 PM

Yesterday we have implemented the image side part in P10 to correctly

   honour the calling convention.

Does this imply that uFFI doesn't work correctly on current images?
Because uFFI should have been available since Pharo 8, according to the
uFFI manual.  Or is it a revamped implementation?

On the other hand, you are asking about ThisCall. This calling

   conventionis only relevant in 32bits systems. What is your target
   system/library? Does it not exist as 64-bit library?

Unfortunately it is a legacy library with no 64 bit version. No problem,
because I can write a wrapper, yet I was wondering if Pharo offered any
facilities to avoid that.

Thank you for the information.


Message: 1
Date: Thu, 26 Aug 2021 15:38:48 +0200
From: "tesonep@gmail.com" tesonep@gmail.com
Subject: [Pharo-users] Re: uFFI: Calling conventions?
To: Any question about pharo is welcome pharo-users@lists.pharo.org
Message-ID:
CAM9-ED+DYAJdOF0GfBcypmV9cQqufmSzUmC51EaLRzS2ycsPWQ@mail.gmail.com
Content-Type: multipart/alternative;
boundary="0000000000004711e205ca767def"

Hi All,
The answer is yes and no.
Let's go step by step.
To declare the calling convention a class can override the method
#ffiCallingConvention. Returning a Symbol representing the Calling
Convention.

Yesterday we have implemented the image side part in P10 to correctly
honour the calling convention.
I have implemented it for X86 but this can be easily extended to ARM32
(ARM64 has a single calling convention).
If this fix is useful, it can be backported to P9.

However, this only works for X86_64 as it depends on the new FFI
implementation. We still do not have an X86 32 bits VM, it is possible to
compile it from sources, but we are not distributing it.

In X86_64 only exists the Windows and the GNU calling convention, we are
supporting both.

On the other hand, you are asking about ThisCall. This calling convention
is only relevant in 32bits systems. What is your target system/library?
Does it not exist as 64-bit library?

Thanks

On Tue, Aug 24, 2021 at 9:33 PM egarrulo egarrulo@gmail.com wrote:

Hi all,

I haven't found any information on calling conventions in the "Unified
FFI - Calling Foreign Functions from Pharo" manual. What conventions are
available, please?

If the ThisCall[1] convention isn't supported, could it be implemented
in code with some boilerplate?

Thank you.

--

[1] ThisCall works like StdCall, but the first parameter - the "this"
pointer - is passed via the ECX register.

>> Yesterday we have implemented the image side part in P10 to correctly    honour the calling convention. Does this imply that uFFI doesn't work correctly on current images? Because uFFI should have been available since Pharo 8, according to the uFFI manual.  Or is it a revamped implementation? >> On the other hand, you are asking about ThisCall. This calling    conventionis only relevant in 32bits systems. What is your target    system/library? Does it not exist as 64-bit library? Unfortunately it is a legacy library with no 64 bit version. No problem, because I can write a wrapper, yet I was wondering if Pharo offered any facilities to avoid that. Thank you for the information. ---------------------------------------------------------------------- > Message: 1 > Date: Thu, 26 Aug 2021 15:38:48 +0200 > From: "tesonep@gmail.com" <tesonep@gmail.com> > Subject: [Pharo-users] Re: uFFI: Calling conventions? > To: Any question about pharo is welcome <pharo-users@lists.pharo.org> > Message-ID: > <CAM9-ED+DYAJdOF0GfBcypmV9cQqufmSzUmC51EaLRzS2ycsPWQ@mail.gmail.com> > Content-Type: multipart/alternative; > boundary="0000000000004711e205ca767def" > > Hi All, > The answer is yes and no. > Let's go step by step. > To declare the calling convention a class can override the method > #ffiCallingConvention. Returning a Symbol representing the Calling > Convention. > > Yesterday we have implemented the image side part in P10 to correctly > honour the calling convention. > I have implemented it for X86 but this can be easily extended to ARM32 > (ARM64 has a single calling convention). > If this fix is useful, it can be backported to P9. > > However, this only works for X86_64 as it depends on the new FFI > implementation. We still do not have an X86 32 bits VM, it is possible to > compile it from sources, but we are not distributing it. > > In X86_64 only exists the Windows and the GNU calling convention, we are > supporting both. > > On the other hand, you are asking about ThisCall. This calling convention > is only relevant in 32bits systems. What is your target system/library? > Does it not exist as 64-bit library? > > Thanks > > On Tue, Aug 24, 2021 at 9:33 PM egarrulo <egarrulo@gmail.com> wrote: > >> Hi all, >> >> I haven't found any information on calling conventions in the "Unified >> FFI - Calling Foreign Functions from Pharo" manual. What conventions are >> available, please? >> >> If the ThisCall[1] convention isn't supported, could it be implemented >> in code with some boilerplate? >> >> Thank you. >> >> -- >> >> [1] ThisCall works like StdCall, but the first parameter - the "this" >> pointer - is passed via the ECX register. >> >>
GP
Guillermo Polito
Mon, Aug 30, 2021 7:52 AM

Hi egarrulo,

El 27 ago 2021, a las 18:50, egarrulo egarrulo@gmail.com escribió:

Yesterday we have implemented the image side part in P10 to correctly

honour the calling convention.

Does this imply that uFFI doesn't work correctly on current images?
Because uFFI should have been available since Pharo 8, according to the
uFFI manual.  Or is it a revamped implementation?

Calling conventions are properly working, but I think that what Pablo means is something else.
The current implementation just uses the most common (which is the sole in most cases) calling convention for the platform.
What Pablo meant I think is that the current implementation does not allow users to redefine the calling convention.

On the other hand, you are asking about ThisCall. This calling

conventionis only relevant in 32bits systems. What is your target
system/library? Does it not exist as 64-bit library?

Unfortunately it is a legacy library with no 64 bit version. No problem,
because I can write a wrapper, yet I was wondering if Pharo offered any
facilities to avoid that.

Check Pablo’s PR https://github.com/pharo-project/pharo/pull/9826

The class TFUFFIDifferentCallingConventionFunctionCallTest uses the ffiCallingConvention hook to decide what calling convention to use.
Check the list in initializeABIMapping to see the available calling conventions.

Cheers,
G

Thank you for the information.


Message: 1
Date: Thu, 26 Aug 2021 15:38:48 +0200
From: "tesonep@gmail.com" tesonep@gmail.com
Subject: [Pharo-users] Re: uFFI: Calling conventions?
To: Any question about pharo is welcome pharo-users@lists.pharo.org
Message-ID:
CAM9-ED+DYAJdOF0GfBcypmV9cQqufmSzUmC51EaLRzS2ycsPWQ@mail.gmail.com
Content-Type: multipart/alternative;
boundary="0000000000004711e205ca767def"

Hi All,
The answer is yes and no.
Let's go step by step.
To declare the calling convention a class can override the method
#ffiCallingConvention. Returning a Symbol representing the Calling
Convention.

Yesterday we have implemented the image side part in P10 to correctly
honour the calling convention.
I have implemented it for X86 but this can be easily extended to ARM32
(ARM64 has a single calling convention).
If this fix is useful, it can be backported to P9.

However, this only works for X86_64 as it depends on the new FFI
implementation. We still do not have an X86 32 bits VM, it is possible to
compile it from sources, but we are not distributing it.

In X86_64 only exists the Windows and the GNU calling convention, we are
supporting both.

On the other hand, you are asking about ThisCall. This calling convention
is only relevant in 32bits systems. What is your target system/library?
Does it not exist as 64-bit library?

Thanks

On Tue, Aug 24, 2021 at 9:33 PM egarrulo egarrulo@gmail.com wrote:

Hi all,

I haven't found any information on calling conventions in the "Unified
FFI - Calling Foreign Functions from Pharo" manual. What conventions are
available, please?

If the ThisCall[1] convention isn't supported, could it be implemented
in code with some boilerplate?

Thank you.

--

[1] ThisCall works like StdCall, but the first parameter - the "this"
pointer - is passed via the ECX register.

Hi egarrulo, > El 27 ago 2021, a las 18:50, egarrulo <egarrulo@gmail.com> escribió: > > >> Yesterday we have implemented the image side part in P10 to correctly > honour the calling convention. > > Does this imply that uFFI doesn't work correctly on current images? > Because uFFI should have been available since Pharo 8, according to the > uFFI manual. Or is it a revamped implementation? Calling conventions are properly working, but I think that what Pablo means is something else. The current implementation just uses the most common (which is the sole in most cases) calling convention for the platform. What Pablo meant I think is that the current implementation does not allow users to redefine the calling convention. > >> On the other hand, you are asking about ThisCall. This calling > conventionis only relevant in 32bits systems. What is your target > system/library? Does it not exist as 64-bit library? > > Unfortunately it is a legacy library with no 64 bit version. No problem, > because I can write a wrapper, yet I was wondering if Pharo offered any > facilities to avoid that. Check Pablo’s PR https://github.com/pharo-project/pharo/pull/9826 The class TFUFFIDifferentCallingConventionFunctionCallTest uses the ffiCallingConvention hook to decide what calling convention to use. Check the list in initializeABIMapping to see the available calling conventions. Cheers, G > > Thank you for the information. > > ---------------------------------------------------------------------- >> Message: 1 >> Date: Thu, 26 Aug 2021 15:38:48 +0200 >> From: "tesonep@gmail.com" <tesonep@gmail.com> >> Subject: [Pharo-users] Re: uFFI: Calling conventions? >> To: Any question about pharo is welcome <pharo-users@lists.pharo.org> >> Message-ID: >> <CAM9-ED+DYAJdOF0GfBcypmV9cQqufmSzUmC51EaLRzS2ycsPWQ@mail.gmail.com> >> Content-Type: multipart/alternative; >> boundary="0000000000004711e205ca767def" >> >> Hi All, >> The answer is yes and no. >> Let's go step by step. >> To declare the calling convention a class can override the method >> #ffiCallingConvention. Returning a Symbol representing the Calling >> Convention. >> >> Yesterday we have implemented the image side part in P10 to correctly >> honour the calling convention. >> I have implemented it for X86 but this can be easily extended to ARM32 >> (ARM64 has a single calling convention). >> If this fix is useful, it can be backported to P9. >> >> However, this only works for X86_64 as it depends on the new FFI >> implementation. We still do not have an X86 32 bits VM, it is possible to >> compile it from sources, but we are not distributing it. >> >> In X86_64 only exists the Windows and the GNU calling convention, we are >> supporting both. >> >> On the other hand, you are asking about ThisCall. This calling convention >> is only relevant in 32bits systems. What is your target system/library? >> Does it not exist as 64-bit library? >> >> Thanks >> >> On Tue, Aug 24, 2021 at 9:33 PM egarrulo <egarrulo@gmail.com> wrote: >> >>> Hi all, >>> >>> I haven't found any information on calling conventions in the "Unified >>> FFI - Calling Foreign Functions from Pharo" manual. What conventions are >>> available, please? >>> >>> If the ThisCall[1] convention isn't supported, could it be implemented >>> in code with some boilerplate? >>> >>> Thank you. >>> >>> -- >>> >>> [1] ThisCall works like StdCall, but the first parameter - the "this" >>> pointer - is passed via the ECX register. >>> >>>