@@ -8,8 +8,8 @@ use proc_macro2::TokenStream as TokenStream2;
8
8
use quote:: { quote, quote_spanned, TokenStreamExt } ;
9
9
use syn:: spanned:: Spanned ;
10
10
use 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 ,
13
13
} ;
14
14
15
15
macro_rules! err {
@@ -121,18 +121,34 @@ fn get_function_arg_name(f: &ItemFn, arg_index: usize, errors: &mut TokenStream2
121
121
/// Custom attribute for a UEFI executable entry point.
122
122
///
123
123
/// 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`.
127
128
///
128
129
/// Due to internal implementation details the parameters must both be
129
130
/// named, so `arg` or `_arg` are allowed, but not `_`.
130
131
///
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.
133
134
///
134
135
/// # Examples
135
136
///
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
+ ///
136
152
/// ```no_run
137
153
/// #![no_main]
138
154
///
@@ -180,6 +196,18 @@ pub fn entry(args: TokenStream, input: TokenStream) -> TokenStream {
180
196
) ) ;
181
197
}
182
198
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
+
183
211
let image_handle_ident = get_function_arg_name ( & f, 0 , & mut errors) ;
184
212
let system_table_ident = get_function_arg_name ( & f, 1 , & mut errors) ;
185
213
@@ -188,8 +216,6 @@ pub fn entry(args: TokenStream, input: TokenStream) -> TokenStream {
188
216
return errors. into ( ) ;
189
217
}
190
218
191
- let signature_span = f. sig . span ( ) ;
192
-
193
219
f. sig . abi = Some ( syn:: parse2 ( quote_spanned ! ( signature_span=> extern "efiapi" ) ) . unwrap ( ) ) ;
194
220
195
221
// allow the entry function to be unsafe (by moving the keyword around so that it actually works)
0 commit comments