@@ -200,11 +200,12 @@ pub fn entry(args: TokenStream, input: TokenStream) -> TokenStream {
200
200
201
201
// If the user doesn't specify any arguments to the entry function, fill in
202
202
// 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 {
204
205
f. sig . inputs = parse_quote_spanned ! (
205
206
signature_span=>
206
207
internal_image_handle: :: uefi:: Handle ,
207
- internal_system_table: :: uefi :: table :: SystemTable < :: uefi :: table :: Boot >
208
+ internal_system_table: * const :: core :: ffi :: c_void ,
208
209
) ;
209
210
}
210
211
@@ -225,12 +226,20 @@ pub fn entry(args: TokenStream, input: TokenStream) -> TokenStream {
225
226
// Set the global image handle. If `image_handle_ident` is `None`
226
227
// then the typecheck is going to fail anyway.
227
228
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
+
228
237
f. block . stmts . insert (
229
238
0 ,
230
239
parse_quote ! {
231
240
unsafe {
232
241
:: 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 ) ;
234
243
}
235
244
} ,
236
245
) ;
@@ -249,6 +258,16 @@ pub fn entry(args: TokenStream, input: TokenStream) -> TokenStream {
249
258
} ) ;
250
259
let fn_output = & f. sig . output ;
251
260
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
+
252
271
let fn_type_check = quote_spanned ! { signature_span=>
253
272
// Cast from the function type to a function pointer with the same
254
273
// signature first, then try to assign that to an unnamed constant with
@@ -260,7 +279,7 @@ pub fn entry(args: TokenStream, input: TokenStream) -> TokenStream {
260
279
// specifically in the function signature is incorrect.
261
280
const _:
262
281
// 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 =
264
283
// Cast from a fn item to a function pointer.
265
284
#fn_ident as #unsafety extern "efiapi" fn ( #( #fn_inputs) , * ) #fn_output;
266
285
} ;
0 commit comments