Skip to content

Commit 089e3e0

Browse files
committed
Add macro for checking type of entry point
1 parent 5a6090f commit 089e3e0

File tree

5 files changed

+32
-7
lines changed

5 files changed

+32
-7
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "uefi"
3-
version = "0.3.0"
3+
version = "0.3.1"
44
authors = ["Gabriel Majeri <[email protected]>"]
55
readme = "README.md"
66
edition = "2018"
@@ -25,7 +25,7 @@ logger = []
2525
bitflags = "1.1.0"
2626
log = { version = "0.4.8", default-features = false }
2727
ucs2 = "0.1.0"
28-
uefi-macros = "0.2.0"
28+
uefi-macros = "0.2.1"
2929

3030
[workspace]
3131
members = [

src/prelude.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22
//!
33
//! This includes the system table types, `Status` codes, etc.
44
5-
pub use crate::{ResultExt, Status};
5+
pub use crate::{Handle, ResultExt, Status};
66

77
// Import the basic table types.
88
pub use crate::table::boot::BootServices;
99
pub use crate::table::runtime::RuntimeServices;
1010
pub use crate::table::{Boot, SystemTable};
11+
12+
// Import the macro for creating the custom entry point.
13+
pub use uefi_macros::entry;

uefi-macros/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "uefi-macros"
3-
version = "0.2.0"
3+
version = "0.2.1"
44
authors = ["Hadrien G. <[email protected]>"]
55
edition = "2018"
66
description = "Procedural macros for the uefi-rs crate"

uefi-macros/src/lib.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ extern crate proc_macro;
55
use proc_macro::TokenStream;
66
use quote::{quote, TokenStreamExt};
77
use syn::parse::{Parse, ParseStream};
8-
use syn::{parse_macro_input, DeriveInput, Generics, Ident, ItemType, LitStr};
8+
use syn::{parse_macro_input, DeriveInput, Generics, Ident, ItemFn, ItemType, LitStr};
99

1010
/// Parses a type definition, extracts its identifier and generic parameters
1111
struct TypeDefinition {
@@ -123,3 +123,25 @@ pub fn derive_protocol(item: TokenStream) -> TokenStream {
123123
};
124124
result.into()
125125
}
126+
127+
/// Custom attribute for a UEFI executable entrypoint
128+
#[proc_macro_attribute]
129+
pub fn entry(args: TokenStream, input: TokenStream) -> TokenStream {
130+
// This code is inspired by the approach in this embedded Rust crate:
131+
// https://github.com/rust-embedded/cortex-m-rt/blob/965bf1e3291571e7e3b34834864117dc020fb391/macros/src/lib.rs#L85
132+
133+
if !args.is_empty() {
134+
panic!("This attribute accepts no arguments");
135+
}
136+
137+
let f = parse_macro_input!(input as ItemFn);
138+
139+
let entry_fn_ident = &f.sig.ident;
140+
141+
let result = quote!(
142+
static _UEFI_ENTRY_POINT_TYPE_CHECK: extern "win64" fn(uefi::Handle, uefi::table::SystemTable<uefi::table::Boot>) -> uefi::Status = #entry_fn_ident;
143+
#[no_mangle]
144+
pub extern "win64" #f
145+
);
146+
result.into()
147+
}

uefi-test-runner/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ mod proto;
2020
#[no_mangle]
2121
pub static _fltused: u32 = 0;
2222

23-
#[no_mangle]
24-
pub extern "C" fn efi_main(image: uefi::Handle, st: SystemTable<Boot>) -> Status {
23+
#[entry]
24+
fn efi_main(image: Handle, st: SystemTable<Boot>) -> Status {
2525
// Initialize utilities (logging, memory allocation...)
2626
uefi_services::init(&st).expect_success("Failed to initialize utilities");
2727

0 commit comments

Comments
 (0)