Skip to content

Commit 6189881

Browse files
uefi: Add set_main macro
1 parent 4b00179 commit 6189881

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

uefi/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ pub(crate) mod polyfill;
136136

137137
pub mod helpers;
138138

139+
mod macros;
139140
mod util;
140141

141142
#[cfg(test)]

uefi/src/macros.rs

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/// Set the entry point for a UEFI executable.
2+
///
3+
/// This macro takes one argument, the function to run when the executable is
4+
/// launched. That function must take no arguments and return a [`uefi::Result`].
5+
///
6+
/// # Example
7+
///
8+
/// ```
9+
/// uefi::set_main!(main);
10+
///
11+
/// fn main() -> uefi::Result {
12+
/// Ok(())
13+
/// }
14+
/// ```
15+
#[macro_export]
16+
macro_rules! set_main {
17+
($main:ident) => {
18+
#[export_name = "efi_main"]
19+
fn efi_main(
20+
image: ::uefi::Handle,
21+
system_table: *mut ::core::ffi::c_void,
22+
) -> ::uefi::Status {
23+
unsafe { ::uefi::boot::set_image_handle(image) };
24+
unsafe { ::uefi::system::set_system_table(system_table.cast()) };
25+
let result = $main();
26+
match result {
27+
Ok(()) => ::uefi::Status::SUCCESS,
28+
Err(err) => err.status(),
29+
}
30+
}
31+
};
32+
}

0 commit comments

Comments
 (0)