Debian Codegraph @

third_party/rust/zeitstempel/src/win.rs

raw
1 //! Timestamp implementation for Windows 10+ or Windows Server 2016+.
2 //!
3 //! Lower versions don't have the necessary API and should use the fallback.
4
5 #![cfg(feature = "win10plus")]
6
7 /// [PULONGLONG] is a pointer to [ULONGLONG], a 64-bit unsigned integer.
8 ///
9 /// [PULONGLONG]: https://docs.microsoft.com/en-us/windows/win32/winprog/windows-data-types#PULONGLONG
10 /// [ULONGLONG]: https://docs.microsoft.com/en-us/windows/win32/winprog/windows-data-types#ulonglong
11 type PULONGLONG = *mut u64;
12
13 /// Link against Windows' `mincore`.
14 #[link(name = "mincore")]
15 extern "system" {
16 /// Gets the current interrupt-time count.
17 ///
18 /// See [`QueryInterruptTime`].
19 ///
20 /// [`QueryInterruptTime`]: https://docs.microsoft.com/en-us/windows/win32/api/realtimeapiset/nf-realtimeapiset-queryinterrupttime
21 ///
22 /// Note: we define it ourselves, because it's not actually included in `winapi`.
23 fn QueryInterruptTime(InterruptTime: PULONGLONG);
24 }
25
26 /// Windows counts time in a system time unit of 100 nanoseconds.
27 const SYSTEM_TIME_UNIT: u64 = 100;
28
29 /// The time based on the current interrupt-time count.
30 /// This includes the suspend time.
31 ///
32 /// See [`QueryInterruptTime`].
33 ///
34 /// [`QueryInterruptTime`]: https://docs.microsoft.com/en-us/windows/win32/api/realtimeapiset/nf-realtimeapiset-queryinterrupttime
35 pub fn now_including_suspend() -> u64 {
36 let mut interrupt_time = 0;
37 unsafe {
38 QueryInterruptTime(&mut interrupt_time);
39 }
40
41 interrupt_time * SYSTEM_TIME_UNIT
42 }