-
Notifications
You must be signed in to change notification settings - Fork 162
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
Investigate efiapi!{} macro #41
Comments
But that's the thing, this is supposed to be
Using a macro seems to sort of go around the real problem. I would rather raise an issue upstream about this. In this old-ish comment it is mentioned that the only reason Rust even exposes the I'm sure the Rust devs would be open to a proposal to add an |
Sounds like a good idea! I opened an issue on rust-lang to test waters, let's see how this goes... |
After further investigation, this is too much for declarative macros (as they cannot expand into types, but only into items, the whole struct definition would need to be parsed, which is too much work) and too little to justify a procedural macro, so I'll live with the code duplication for now 😉 |
In Rust, I think resolving #38 entails generating different
extern "<something>"
statements depending on the target architecture. The pointer wrapping discussed in #40, if it ends up being implemented, could also use a bit of code generation to automatically turn*const T
intoEfiPtr<T>
and*mut T
intoEfiPtrMut<T>
.A general solution to handle this kind of EFI API boilerplate would be to borrow the EFIAPI design from the UEFI spec and turn it into a Rust macro. For example, this code...
...would generate this code on x86_64:
...and this code on i386:
There are limitations to what a declarative macro can generate in Rust (IIRC they can't generate types), and we probably don't want to go for procedural macros on a task this simple, so the final design may be modified to accomodate these limitations. But I think the general idea could portably address the issue of EFI calling conventions without bringing too much boilerplate in the declaration of each individual API entry point.
The text was updated successfully, but these errors were encountered: