File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -78,3 +78,36 @@ macro_rules! cstr16 {
78
78
unsafe { $crate:: CStr16 :: from_u16_with_nul_unchecked( S ) }
79
79
} } ;
80
80
}
81
+
82
+ /// Set the entry point for a UEFI executable.
83
+ ///
84
+ /// This macro takes one argument, the function to run when the executable is
85
+ /// launched. That function must take no arguments and return a [`uefi::Result`].
86
+ ///
87
+ /// # Example
88
+ ///
89
+ /// ```
90
+ /// uefi::set_main!(main);
91
+ ///
92
+ /// fn main() -> uefi::Result {
93
+ /// Ok(())
94
+ /// }
95
+ /// ```
96
+ #[ macro_export]
97
+ macro_rules! set_main {
98
+ ( $main: ident) => {
99
+ #[ export_name = "efi_main" ]
100
+ fn efi_main(
101
+ image: :: uefi:: Handle ,
102
+ system_table: * mut :: core:: ffi:: c_void,
103
+ ) -> :: uefi:: Status {
104
+ unsafe { :: uefi:: boot:: set_image_handle( image) } ;
105
+ unsafe { :: uefi:: system:: set_system_table( system_table. cast( ) ) } ;
106
+ let result = $main( ) ;
107
+ match result {
108
+ Ok ( ( ) ) => :: uefi:: Status :: SUCCESS ,
109
+ Err ( err) => err. status( ) ,
110
+ }
111
+ }
112
+ } ;
113
+ }
You can’t perform that action at this time.
0 commit comments