1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
//! Macros for Kernel-Mode drivers.

/// Macro to send a message to the kernel debugger.
///
/// # Example
///
/// ```no_run
/// KdPrint!("NTSTATUS is 0x%X\n", status);
/// ```
#[macro_export]
macro_rules! KdPrint {
	($msg:expr $(, $arg:expr)*) => { unsafe { $crate::debug::DbgPrint( concat!($msg, "\0").as_ptr() $(, $arg )* )} };
}

/// Macro to send a message to the kernel debugger for unsafe blocks.
///
/// Used in `unsafe {}` blocks.
#[macro_export]
macro_rules! KdPrint_u {
	($msg:expr $(, $arg:expr)*) => { $crate::debug::DbgPrint( concat!($msg, "\0").as_ptr() $(, $arg )* ) };
}

#[macro_export]
macro_rules! check_unsafe {
	($expr:expr) => {{
		let st: $crate::status::Status = unsafe { $expr };
		if st.is_err() {
			KdPrint!("[km] error: status 0x%X\n", st);
			return st;
		} else {
			st
		}
	}}
}