@@ -8,8 +8,8 @@ use proc_macro2::TokenStream as TokenStream2;
88use quote:: { quote, quote_spanned, TokenStreamExt } ;
99use syn:: spanned:: Spanned ;
1010use syn:: {
11- parse_macro_input, parse_quote, Error , Expr , ExprLit , ExprPath , FnArg , Ident , ItemFn ,
12- ItemStruct , Lit , Pat , Visibility ,
11+ parse_macro_input, parse_quote, parse_quote_spanned , Error , Expr , ExprLit , ExprPath , FnArg ,
12+ Ident , ItemFn , ItemStruct , Lit , Pat , Visibility ,
1313} ;
1414
1515macro_rules! err {
@@ -121,18 +121,34 @@ fn get_function_arg_name(f: &ItemFn, arg_index: usize, errors: &mut TokenStream2
121121/// Custom attribute for a UEFI executable entry point.
122122///
123123/// This attribute modifies a function to mark it as the entry point for
124- /// a UEFI executable. The function must have two parameters, [`Handle`]
125- /// and [`SystemTable<Boot>`], and return a [`Status`]. The function can
126- /// optionally be `unsafe`.
124+ /// a UEFI executable. The function:
125+ /// * Must return [`Status`].
126+ /// * Must have either zero parameters or two: [`Handle`] and [`SystemTable<Boot>`].
127+ /// * Can optionally be `unsafe`.
127128///
128129/// Due to internal implementation details the parameters must both be
129130/// named, so `arg` or `_arg` are allowed, but not `_`.
130131///
131- /// The [`BootServices::set_image_handle`] function will be called
132- /// automatically with the image [`Handle`] argument .
132+ /// The global system table pointer and global image handle will be set
133+ /// automatically.
133134///
134135/// # Examples
135136///
137+ /// With no arguments:
138+ ///
139+ /// ```no_run
140+ /// #![no_main]
141+ ///
142+ /// use uefi::prelude::*;
143+ ///
144+ /// #[entry]
145+ /// fn main() -> Status {
146+ /// Status::SUCCESS
147+ /// }
148+ /// ```
149+ ///
150+ /// With two arguments:
151+ ///
136152/// ```no_run
137153/// #![no_main]
138154///
@@ -180,6 +196,18 @@ pub fn entry(args: TokenStream, input: TokenStream) -> TokenStream {
180196 ) ) ;
181197 }
182198
199+ let signature_span = f. sig . span ( ) ;
200+
201+ // If the user doesn't specify any arguments to the entry function, fill in
202+ // the image handle and system table arguments automatically.
203+ if f. sig . inputs . is_empty ( ) {
204+ f. sig . inputs = parse_quote_spanned ! (
205+ signature_span=>
206+ image_handle: :: uefi:: Handle ,
207+ system_table: :: uefi:: table:: SystemTable <:: uefi:: table:: Boot >
208+ ) ;
209+ }
210+
183211 let image_handle_ident = get_function_arg_name ( & f, 0 , & mut errors) ;
184212 let system_table_ident = get_function_arg_name ( & f, 1 , & mut errors) ;
185213
@@ -188,8 +216,6 @@ pub fn entry(args: TokenStream, input: TokenStream) -> TokenStream {
188216 return errors. into ( ) ;
189217 }
190218
191- let signature_span = f. sig . span ( ) ;
192-
193219 f. sig . abi = Some ( syn:: parse2 ( quote_spanned ! ( signature_span=> extern "efiapi" ) ) . unwrap ( ) ) ;
194220
195221 // allow the entry function to be unsafe (by moving the keyword around so that it actually works)
0 commit comments