-
Notifications
You must be signed in to change notification settings - Fork 71
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
Eliminate the need for call_unsafe_wdf_function_binding
via helper lib
#51
base: main
Are you sure you want to change the base?
Conversation
Interesting PR. We are actually planning on using the "cc in build.rs" approach for solving some issues with several things in WDF relying on global variables being declared in headers. These variables wont generate something we can link against, unless they are included in a .c file and compiled. An example of this is WdfMinimumVersionRequired. Right now, windows-drivers-rs works around this by manually redefining some of the symbols in rust. However, I'm wary about doing that for all the inlined WDF functions. The way it's done now with the macro, it mirrors exactly how the calling the function in C/C++ would behave. The change in this PR would add an extra layer of indirection by making a call to the compiled helper lib, which would not be possible for the compiler to optimize away. The bindgen docs specifically call out this perf issue:
|
It also seems that |
Ah neat - I had actually accidentally encountered this fix as well but disabled it because my assumption was that you wanted it the other way around :)
Indeed, I'm aware of the extra layer of indirection. I had hoped that this wouldn't be a concern for you, given that:
Lots of assumptions there :) Additionally, this performance tradeoff doesn't have to be permanent. I was going to generate these wrappers at first, but saw that it would duplicate a lot of functionality from |
This supercedes #50 if you decide to go for this one.
Context: All
Wdf*
functions are simply inline stubs that look up the corresponding function fromWdfFunctions
and call it (with an additionalWdfDriverGlobals
parameter).Normally,
bindgen
will not generate bindings to these functions because they are marked asinline
(and thus have no implementation that Rust can link to).However, we can create a helper object via a C compiler that implements these functions (by hackily disabling the
FORCEINLINE
macro 😉) and then use that as the link target for the Rust declarations.All said and done, this allows us to avoid having to generate code via macro to call the
Wdf*
functions.This makes for a much nicer end-user experience.