Skip to content
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

generated bindings should use extern "system" instead of extern "C" #156

Open
HoShiMin opened this issue May 11, 2024 · 3 comments
Open

Comments

@HoShiMin
Copy link

As we know, almost all Windows functions have stdcall convention, so, this is strange that all generated bindings are marked as extern "C". It seems that the convention should be changed to extern "stdcall", isn't it? Of course, for functions that are really "stdcall".

For example, ZwCreateFile.
It has the following prototype:

NTSYSAPI
NTSTATUS
NTAPI // <-- Here it is!
ZwCreateFile(...);
@wmmc88
Copy link
Collaborator

wmmc88 commented May 13, 2024

Are you encountering any buggy behavior that is affected by this? Technically, I think the most correct solution here is that bindgen generates extern system:

extern "system" -- Usually the same as extern "C", except on Win32, in which case it's "stdcall", or what you should use to link to the Windows API itself
--From https://doc.rust-lang.org/reference/items/external-blocks.html

Functionally, there should be no difference in behavior here because on ARM and x64 processors, __stdcall is accepted and ignored by the compiler. 64-bit targets use the x64 calling convention. On Windows targets, extern "C" is equivalent to extern "win64", which is Rust's moniker for Window's x64 calling convention

@HoShiMin
Copy link
Author

HoShiMin commented May 13, 2024

@wmmc88, sure, there are no problems in x64, but for the correctness it would be great to use "stdcall" or "system" as you stated above - for example, for cases of building a 32-bit driver for legacy Windows. And just because it's just correct 🙂

@wmmc88 wmmc88 changed the title Why extern "C"? generated bindings should use extern "system" instead of extern "C" May 13, 2024
@wmmc88
Copy link
Collaborator

wmmc88 commented May 13, 2024

Per our current support policy:

This project was built with support of WDM, KMDF, and UMDF drivers in mind, as well as Win32 Services. This includes support for all versions of WDF included in WDK 22H2 and newer.

Since NI WDK (22H2) does not support 32-bit drivers, we do not currently have plans to support this scenario. However, if the change to emit extern "system" instead of extern "C" is minimally invasive, then we would consider a PR.

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

No branches or pull requests

2 participants