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
68
69
70
71
//! Windows console-control handler.
//!
//! Registers a `PHANDLER_ROUTINE` via `SetConsoleCtrlHandler`. The handler
//! runs on a Windows-kernel-spawned thread; it is NOT subject to POSIX
//! async-signal-safety constraints (locks and allocations are allowed),
//! but it MUST return within ~5 seconds before the OS force-kills the
//! process. The drain budget in `registry::drain_and_kill` is capped to
//! 1500ms accordingly.
//!
//! Event-to-exit-code map:
//! - `CTRL_C_EVENT` (Ctrl+C from console) -> 130
//! - `CTRL_BREAK_EVENT` (Ctrl+Break) -> 130
//! - `CTRL_CLOSE_EVENT` (console window closed) -> 143
//! - `CTRL_LOGOFF_EVENT` (user logoff) -> 143
//! - `CTRL_SHUTDOWN_EVENT` (system shutdown) -> 143
//!
//! Returning TRUE tells Windows we handled the event; returning FALSE
//! falls back to the next handler in the chain.
use io;
// `BOOL` moved from `Win32::Foundation` to `windows_sys::core` in
// windows-sys 0.61 (matches the `SetConsoleCtrlHandler` signature
// `add: windows_sys::core::BOOL -> windows_sys::core::BOOL`). The old
// `Win32::Foundation::BOOL` path no longer resolves and broke the
// Windows ARM64 native compile on every PR.
use ;
use BOOL;
use handle_signal;
/// Console control handler invoked by the Windows kernel on a dedicated
/// thread.
///
/// # Safety
///
/// Called by the Win32 console subsystem with the documented
/// `PHANDLER_ROUTINE` signature; the only inputs are kernel-supplied
/// control codes. The body delegates to safe Rust immediately.
unsafe extern "system"
/// Install the console control handler.