winwrap/um/
winnt.rs

1use crate::*;
2use winapi::shared::basetsd::{KAFFINITY, ULONG_PTR};
3use winapi::shared::minwindef::{BYTE, WORD};
4use winapi::shared::ntdef::GROUP_AFFINITY;
5use winapi::um::winnt::{PROCESSOR_NUMBER, EXCEPTION_RECORD, PVOID, EXCEPTION_MAXIMUM_PARAMETERS, EXCEPTION_POINTERS, CONTEXT};
6
7make_struct! {PROCESSOR_NUMBER,
8#[derive(Debug)]
9pub struct ProcessorNumber {
10    group_number: WORD,
11    number: BYTE,
12    reserved: BYTE,
13}}
14
15make_struct! {GROUP_AFFINITY,
16#[derive(Debug)]
17pub struct GroupAffinity {
18    mask: KAFFINITY,
19    group: WORD,
20    reserved: [WORD; 3],
21}}
22
23/// # Examples
24///
25/// ```no_run
26/// use winwrap::handle::HModule;
27/// use winwrap::um::winnt::DllReason;
28/// use winwrap::winapi::shared::minwindef::{HINSTANCE, DWORD, LPVOID, BOOL};
29///
30/// #[no_mangle]
31/// #[allow(non_snake_case)]
32/// pub unsafe extern "system" fn DllMain(
33///     hinstDLL: HINSTANCE,
34///     fdwReason: DWORD,
35///     _lpReserved: LPVOID
36/// ) -> BOOL {
37///     dll_main(HModule::new(hinstDLL), DllReason::from(fdwReason)).into()
38/// }
39///
40/// fn dll_main(dll_instance: HModule, reason: DllReason) -> bool {
41///     match reason {
42///         DllReason::PROCESS_ATTACH => { /* Write your code */ }
43///         DllReason::PROCESS_DETACH => { /* Write your code */ }
44///         DllReason::THREAD_ATTACH => { /* Write your code */ }
45///         DllReason::THREAD_DETACH => { /* Write your code */ }
46///     }
47///     true
48/// }
49/// ```
50#[repr(u32)]
51#[allow(non_camel_case_types)]
52pub enum DllReason {
53    /// DLL_PROCESS_ATTACH
54    PROCESS_ATTACH = 1,
55    /// DLL_PROCESS_DETACH
56    PROCESS_DETACH = 0,
57    /// DLL_THREAD_ATTACH
58    THREAD_ATTACH = 2,
59    /// DLL_THREAD_DETACH
60    THREAD_DETACH = 3,
61}
62
63impl From<DWORD> for DllReason {
64    fn from(x: u32) -> Self {
65        match x {
66            1 => Self::PROCESS_ATTACH,
67            0 => Self::PROCESS_DETACH,
68            2 => Self::THREAD_ATTACH,
69            3 => Self::THREAD_DETACH,
70            e => panic!("Unknown DLL reason: {}", e)
71        }
72    }
73}
74
75make_struct! {EXCEPTION_POINTERS,
76pub struct ExceptionPointers<'a> {
77    pub exception_record:&'a mut ExceptionRecord<'a>,
78    pub context_record:&'a mut CONTEXT,
79}}
80
81make_struct! {EXCEPTION_RECORD,
82pub struct ExceptionRecord<'a>{
83    pub exception_code: DWORD,
84    pub exception_flags: DWORD,
85    pub exception_record: Option<&'a mut EXCEPTION_RECORD>,
86    pub exception_address: PVOID,
87    pub number_parameters: DWORD,
88    pub exception_information: [ULONG_PTR; EXCEPTION_MAXIMUM_PARAMETERS],
89}}