Skip to content

Commit fc26521

Browse files
uefi-macros: Use raw pointer for system table when generating args
When applying `entry` to a no-arg main, generate the system table pointer as `*const c_void` rather than `SystemTable<Boot>`. This will avoid unwanted deprecation warnings after `SystemTable` is deprecated.
1 parent 9518cd1 commit fc26521

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

uefi-macros/src/lib.rs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,12 @@ pub fn entry(args: TokenStream, input: TokenStream) -> TokenStream {
200200

201201
// If the user doesn't specify any arguments to the entry function, fill in
202202
// the image handle and system table arguments automatically.
203-
if f.sig.inputs.is_empty() {
203+
let generated_args = f.sig.inputs.is_empty();
204+
if generated_args {
204205
f.sig.inputs = parse_quote_spanned!(
205206
signature_span=>
206207
internal_image_handle: ::uefi::Handle,
207-
internal_system_table: ::uefi::table::SystemTable<::uefi::table::Boot>
208+
internal_system_table: *const ::core::ffi::c_void,
208209
);
209210
}
210211

@@ -225,12 +226,20 @@ pub fn entry(args: TokenStream, input: TokenStream) -> TokenStream {
225226
// Set the global image handle. If `image_handle_ident` is `None`
226227
// then the typecheck is going to fail anyway.
227228
if let Some(image_handle_ident) = image_handle_ident {
229+
// Convert the system table arg (either `SystemTable<Boot>` or
230+
// `*const c_void`) to a pointer of the correct type.
231+
let system_table_ptr = if generated_args {
232+
quote!(#system_table_ident.cast())
233+
} else {
234+
quote!(#system_table_ident.as_ptr().cast())
235+
};
236+
228237
f.block.stmts.insert(
229238
0,
230239
parse_quote! {
231240
unsafe {
232241
::uefi::boot::set_image_handle(#image_handle_ident);
233-
::uefi::table::set_system_table(#system_table_ident.as_ptr().cast());
242+
::uefi::table::set_system_table(#system_table_ptr);
234243
}
235244
},
236245
);
@@ -249,6 +258,16 @@ pub fn entry(args: TokenStream, input: TokenStream) -> TokenStream {
249258
});
250259
let fn_output = &f.sig.output;
251260

261+
// Get the expected argument types for the main function.
262+
let expected_args = if generated_args {
263+
quote!(::uefi::Handle, *const core::ffi::c_void)
264+
} else {
265+
quote!(
266+
::uefi::Handle,
267+
::uefi::table::SystemTable<::uefi::table::Boot>
268+
)
269+
};
270+
252271
let fn_type_check = quote_spanned! {signature_span=>
253272
// Cast from the function type to a function pointer with the same
254273
// signature first, then try to assign that to an unnamed constant with
@@ -260,7 +279,7 @@ pub fn entry(args: TokenStream, input: TokenStream) -> TokenStream {
260279
// specifically in the function signature is incorrect.
261280
const _:
262281
// The expected fn pointer type.
263-
#unsafety extern "efiapi" fn(::uefi::Handle, ::uefi::table::SystemTable<::uefi::table::Boot>) -> ::uefi::Status =
282+
#unsafety extern "efiapi" fn(#expected_args) -> ::uefi::Status =
264283
// Cast from a fn item to a function pointer.
265284
#fn_ident as #unsafety extern "efiapi" fn(#(#fn_inputs),*) #fn_output;
266285
};

0 commit comments

Comments
 (0)