-
Notifications
You must be signed in to change notification settings - Fork 4.5k
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
Support P/Invoke to Variadic Functions on Apple Silicon #48752
Comments
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
Nevermind, I see it was discussed in the linked issue. There is another workaround with generating the prototype with fixed number of arguments that go to registers (8 iirc) and then the ones after that are pushed to stack thanks to the way the ABI is defined. That's not really portable though and just exploits an implementation detail. |
@filipnavara Yep, we already do this: |
I agree this is a valid concern that has to be addressed, thanks for rising it. We are hitting this problem with SQLitePCL.raw and SQLite. It has several methods that accept varargs and it breaks horribly on ARM64 ABI on iOS/macOS. |
@k15tfu Thanks for bringing this up. Support for this has been discussed and is on our backlog. The "official way" is it is not supported. However, @filipnavara's suggestion is the best workaround at present. This is something we are looking at for .NET 6 though and will prioritize this accordingly. |
@k15tfu and @filipnavara I see the links above and will get to them eventually. Can one of you provide a blocked scenario without this support? I want to understand the following options:
Edit: After conferring with the JIT team (2) isn't guaranteed to work in all cases. For example, HFA arguments will fail if a specialized P/Invoke signature is written to dispatch to a varargs function. This means that (2) works for some cases but not all. Currently the only correct way to do this on non-Windows is (3). |
Scenario: Suppose I want to bind the Using the workaround above is possible, of course, but it requires me to either |
@filipnavara Thanks for the example - it helps. I've updated my comment above (#48752 (comment)) and for right now the officially supported work around is to use shim libraries and P/Invoke into them. The approach for declaring P/Invoke signatures to varargs functions with specialized signatures works in some cases but not all so that is user discretion. Additional details on native varargs support - #10478. |
Hi!
What is the best way to pass arguments to variadic functions (
sem_open
,open
, etc) from C# on macOS ARM64?There were no problems for the first few arguments for x86_64abi (specifically we used
public static extern IntPtr sem_open(string name, int oflag, ushort mode, uint value)
) because they are also passed via registers (as per https://refspecs.linuxbase.org/elf/x86_64-abi-0.21.pdf), but on Apple Silicon variadic arguments are passed on the stack (https://developer.apple.com/documentation/xcode/writing_arm64_code_for_apple_platforms#3671957). Does CLR support such calling conventions?Linked issue: #9702
The text was updated successfully, but these errors were encountered: