Skip to content

Commit 87fe728

Browse files
authored
Merge pull request #1000 from nicholasbishop/bishop-raw-variadics
uefi-raw: Fill in [un]install_multiple_protocol_interfaces pointers
2 parents 8be2b8e + 1d4b48b commit 87fe728

File tree

3 files changed

+37
-7
lines changed

3 files changed

+37
-7
lines changed

uefi-raw/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,7 @@
88

99
## Changed
1010
- `{install,reinstall,uninstall}_protocol_interface` now take `const` interface pointers.
11+
- `{un}install_multiple_protocol_interfaces` are now defined as c-variadic
12+
function pointers. The ABI is `extern "C"` until such time as
13+
[`extended_varargs_abi_support`](https://github.com/rust-lang/rust/issues/100189)
14+
is stabilized.

uefi-raw/src/table/boot.rs

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -188,11 +188,28 @@ pub struct BootServices {
188188
out_proto: *mut *mut c_void,
189189
) -> Status,
190190

191-
// These two function pointers require the `c_variadic` feature, which is
192-
// not yet available in stable Rust:
193-
// https://github.com/rust-lang/rust/issues/44930
194-
pub install_multiple_protocol_interfaces: usize,
195-
pub uninstall_multiple_protocol_interfaces: usize,
191+
/// Warning: this function pointer is declared as `extern "C"` rather than
192+
/// `extern "efiapi". That means it will work correctly when called from a
193+
/// UEFI target (`*-unknown-uefi`), but will not work when called from a
194+
/// target with a different calling convention such as
195+
/// `x86_64-unknown-linux-gnu`.
196+
///
197+
/// Support for C-variadics with `efiapi` requires the unstable
198+
/// [`extended_varargs_abi_support`](https://github.com/rust-lang/rust/issues/100189)
199+
/// feature.
200+
pub install_multiple_protocol_interfaces:
201+
unsafe extern "C" fn(handle: *mut Handle, ...) -> Status,
202+
203+
/// Warning: this function pointer is declared as `extern "C"` rather than
204+
/// `extern "efiapi". That means it will work correctly when called from a
205+
/// UEFI target (`*-unknown-uefi`), but will not work when called from a
206+
/// target with a different calling convention such as
207+
/// `x86_64-unknown-linux-gnu`.
208+
///
209+
/// Support for C-variadics with `efiapi` requires the unstable
210+
/// [`extended_varargs_abi_support`](https://github.com/rust-lang/rust/issues/100189)
211+
/// feature.
212+
pub uninstall_multiple_protocol_interfaces: unsafe extern "C" fn(handle: Handle, ...) -> Status,
196213

197214
// CRC services
198215
pub calculate_crc32:

xtask/src/check_raw.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,8 @@ fn check_type(ty: &Type, src: &Path) -> Result<(), Error> {
208208

209209
/// Validate a function pointer.
210210
fn check_fn_ptr(f: &TypeBareFn, src: &Path) -> Result<(), Error> {
211-
// Require `extern efiapi`.
212-
if !is_efiapi(f) {
211+
// Require `extern efiapi`, except for c-variadics.
212+
if !is_efiapi(f) && f.variadic.is_none() {
213213
return Err(Error::new(ErrorKind::ForbiddenAbi, src, f));
214214
}
215215

@@ -433,6 +433,15 @@ mod tests {
433433
)
434434
.is_ok());
435435

436+
// Valid fn ptr with c-variadics.
437+
assert!(check_fn_ptr(
438+
&parse_quote! {
439+
unsafe extern "C" fn(usize, ...)
440+
},
441+
src(),
442+
)
443+
.is_ok());
444+
436445
// Not `extern efiapi`.
437446
check_fn_err(
438447
parse_quote! {

0 commit comments

Comments
 (0)