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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// use wdk::println;
// use wdk_sys::{
// ntddk::{ExAcquireFastMutex, ExReleaseFastMutex, KeInitializeEvent},
// FAST_MUTEX, FM_LOCK_BIT,
// _EVENT_TYPE::SynchronizationEvent,
// };
// pub struct MutexLock {
// mutex: FAST_MUTEX,
// started: bool,
// }
// fn write_raw(dst: *mut i32, value: i32) {
// unsafe { *dst = value };
// }
// /// # Safety
// ///
// /// call system func
// pub unsafe fn ex_initialize_fast_mutex(fast_mutex: *mut FAST_MUTEX) {
// let fast_mutex = fast_mutex.as_mut().unwrap();
// write_raw(&mut fast_mutex.Count, FM_LOCK_BIT as _);
// fast_mutex.Owner = core::ptr::null_mut();
// fast_mutex.Contention = 0;
// KeInitializeEvent(&mut fast_mutex.Event, SynchronizationEvent, 0);
// }
// impl Default for MutexLock {
// fn default() -> Self {
// Self::new()
// }
// }
// impl MutexLock {
// pub fn new() -> Self {
// let mut mutex = FAST_MUTEX::default();
// unsafe { ex_initialize_fast_mutex(&mut mutex) };
// MutexLock {
// mutex,
// started: false,
// }
// }
// pub fn acquire(&mut self) {
// unsafe {
// ExAcquireFastMutex(&mut self.mutex);
// self.started = true;
// }
// }
// pub fn release(&mut self) {
// unsafe {
// ExReleaseFastMutex(&mut self.mutex);
// self.started = false;
// }
// }
// }
// impl Drop for MutexLock {
// fn drop(&mut self) {
// if self.started {
// println!("Forget to release mutex lock");
// self.release();
// }
// }
// }