lazypoline_macros/
lib.rs

1extern crate proc_macro;
2
3use proc_macro::TokenStream;
4use syn::{DeriveInput, parse_macro_input};
5
6mod handlers;
7mod syscall_table;
8
9use handlers::handle_syscall_handler;
10use syscall_table::generate_syscall_enum;
11
12/// Generate a syscall enum from the system's syscall table
13///
14/// This macro generates an enum with variants for all syscalls
15/// on the system, using `ausyscall --dump` to get the syscall
16/// names and numbers.
17#[proc_macro_attribute]
18pub fn syscall_enum(_attr: TokenStream, item: TokenStream) -> TokenStream {
19	let input = parse_macro_input!(item as DeriveInput);
20
21	// Generate the enum content from the syscall table
22	match generate_syscall_enum(&input) {
23		Ok(enum_output) => enum_output.into(),
24		Err(err) => {
25			panic!("Failed to generate syscall enum: {}", err);
26		},
27	}
28}
29
30/// Define a syscall handler function
31///
32/// This macro transforms a regular function into a syscall handler
33/// that implements the `SyscallHandler` trait.
34///
35/// # Example
36///
37/// ```
38/// use lazypoline::{SyscallContext, SyscallAction};
39///
40/// #[lazypoline::syscall_handler]
41/// fn handle_open(ctx: &mut SyscallContext) -> SyscallAction {
42///     println!("Open syscall detected");
43///     SyscallAction::Allow
44/// }
45/// ```
46#[proc_macro_attribute]
47pub fn syscall_handler(attr: TokenStream, item: TokenStream) -> TokenStream {
48	handle_syscall_handler(attr, item)
49}