aboutsummaryrefslogtreecommitdiff
path: root/src/macros.rs
diff options
context:
space:
mode:
authorpravic <[email protected]>2016-04-12 16:39:37 +0300
committerpravic <[email protected]>2016-04-12 16:39:37 +0300
commit28ff216899e95a6a9756bcbe580f28ed8ce61228 (patch)
treebbf00e3c5f3b440db5ddb3f86b6d3a893349cee0 /src/macros.rs
parentgit ignore (diff)
downloadwinapi-kmd-rs-28ff216899e95a6a9756bcbe580f28ed8ce61228.tar.xz
winapi-kmd-rs-28ff216899e95a6a9756bcbe580f28ed8ce61228.zip
Windows Kernel-Mode library
Diffstat (limited to 'src/macros.rs')
-rw-r--r--src/macros.rs34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/macros.rs b/src/macros.rs
new file mode 100644
index 0000000..ba3b24d
--- /dev/null
+++ b/src/macros.rs
@@ -0,0 +1,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
+ }
+ }}
+}