summaryrefslogtreecommitdiff
path: root/crates/windows-kernel-sys/examples/generate_bindings/src/lib.rs
blob: 636cadb1fb095f237c25a7d376b7c1fe051a2808 (plain) (blame)
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
35
36
37
38
39
40
41
42
43
#![no_std]
#![feature(lang_items, const_extern_fn)]
#![deny(
  warnings,
  nonstandard_style,
  unused,
  future_incompatible,
  rust_2018_idioms
)]
#![deny(clippy::all, clippy::nursery, clippy::pedantic)]

use windows_kernel_sys::{
  base::{DRIVER_OBJECT, NTSTATUS, STATUS_SUCCESS, UNICODE_STRING},
  ntoskrnl::DbgPrint,
};

#[panic_handler]
const fn panic(_info: &core::panic::PanicInfo<'_>) -> ! { loop {} }

#[lang = "eh_personality"]
const extern "C" fn eh_personality() {}

/// # Safety
/// `unsafe`
#[no_mangle]
pub unsafe extern "system" fn driver_entry(
  driver: &mut DRIVER_OBJECT,
  _: &UNICODE_STRING,
) -> NTSTATUS {
  // DbgPrint("driver_entry()\0".as_ptr() as _);
  DbgPrint("driver_entry()\0".as_ptr().cast());

  driver.DriverUnload = Some(driver_exit);

  STATUS_SUCCESS
}

/// # Safety
/// `unsafe`
#[no_mangle]
pub unsafe extern "C" fn driver_exit(_driver: *mut DRIVER_OBJECT) {
  DbgPrint("driver_exit()\0".as_ptr().cast());
}