1 // Licensed under the Apache License, Version 2.0
2 // <LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
3 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
4 // All files in the project carrying such notice may not be copied, modified, or distributed
5 // except according to those terms.
6 //! RestartManager include file
7 use shared::minwindef::{BOOL, DWORD, FILETIME, LPDWORD, PBYTE, UINT, ULONG};
8 use um::winnt::{LPCWSTR, LPWSTR, WCHAR};
9 pub const RM_SESSION_KEY_LEN: usize = 16; // mem::size_of::<GUID>()
10 pub const CCH_RM_SESSION_KEY: usize = RM_SESSION_KEY_LEN * 2;
11 pub const CCH_RM_MAX_APP_NAME: usize = 255;
12 pub const CCH_RM_MAX_SVC_NAME: usize = 63;
13 pub const RM_INVALID_TS_SESSION: DWORD = -1i32 as u32;
14 pub const RM_INVALID_PROCESS: DWORD = -1i32 as u32;
15 ENUM!{enum RM_APP_TYPE {
16     RmUnknownApp = 0,
17     RmMainWindow = 1,
18     RmOtherWindow = 2,
19     RmService = 3,
20     RmExplorer = 4,
21     RmConsole = 5,
22     RmCritical = 1000,
23 }}
24 ENUM!{enum RM_SHUTDOWN_TYPE {
25     RmForceShutdown = 0x1,
26     RmShutdownOnlyRegistered = 0x10,
27 }}
28 ENUM!{enum RM_APP_STATUS {
29     RmStatusUnknown = 0x0,
30     RmStatusRunning = 0x1,
31     RmStatusStopped = 0x2,
32     RmStatusStoppedOther = 0x4,
33     RmStatusRestarted = 0x8,
34     RmStatusErrorOnStop = 0x10,
35     RmStatusErrorOnRestart = 0x20,
36     RmStatusShutdownMasked = 0x40,
37     RmStatusRestartMasked = 0x80,
38 }}
39 ENUM!{enum RM_REBOOT_REASON {
40     RmRebootReasonNone = 0x0,
41     RmRebootReasonPermissionDenied = 0x1,
42     RmRebootReasonSessionMismatch = 0x2,
43     RmRebootReasonCriticalProcess = 0x4,
44     RmRebootReasonCriticalService = 0x8,
45     RmRebootReasonDetectedSelf = 0x10,
46 }}
47 STRUCT!{struct RM_UNIQUE_PROCESS {
48     dwProcessId: DWORD,
49     ProcessStartTime: FILETIME,
50 }}
51 pub type PRM_UNIQUE_PROCESS = *mut RM_UNIQUE_PROCESS;
52 STRUCT!{struct RM_PROCESS_INFO {
53     Process: RM_UNIQUE_PROCESS,
54     strAppName: [WCHAR; CCH_RM_MAX_APP_NAME + 1],
55     strServiceShortName: [WCHAR; CCH_RM_MAX_SVC_NAME + 1],
56     ApplicationType: RM_APP_TYPE,
57     AppStatus: ULONG,
58     TSSessionId: DWORD,
59     bRestartable: BOOL,
60 }}
61 pub type PRM_PROCESS_INFO = *mut RM_PROCESS_INFO;
62 ENUM!{enum RM_FILTER_TRIGGER {
63     RmFilterTriggerInvalid = 0,
64     RmFilterTriggerFile,
65     RmFilterTriggerProcess,
66     RmFilterTriggerService,
67 }}
68 ENUM!{enum RM_FILTER_ACTION {
69     RmInvalidFilterAction = 0,
70     RmNoRestart = 1,
71     RmNoShutdown = 2,
72 }}
73 UNION!{union RM_FILTER_INFO_u {
74     [u32; 3] [u64; 2],
75     strFilename strFilename_mut: LPWSTR,
76     Process Process_mut: RM_UNIQUE_PROCESS,
77     strServiceShortName strServiceShortName_mut: LPWSTR,
78 }}
79 STRUCT!{struct RM_FILTER_INFO {
80     FilterAction: RM_FILTER_ACTION,
81     FilterTrigger: RM_FILTER_TRIGGER,
82     cbNextOffset: DWORD,
83     u: RM_FILTER_INFO_u,
84 }}
85 pub type PRM_FILTER_INFO = *mut RM_FILTER_INFO;
86 FN!{cdecl RM_WRITE_STATUS_CALLBACK(
87     nPercentComplete: u32,
88 ) -> ()}
89 extern "system" {
RmStartSession( pSessionHandle: *mut DWORD, dwSessionFlags: DWORD, strSessionKey: *mut WCHAR, ) -> DWORD90     pub fn RmStartSession(
91         pSessionHandle: *mut DWORD,
92         dwSessionFlags: DWORD,
93         strSessionKey: *mut WCHAR,
94     ) -> DWORD;
RmJoinSession( pSessionHandle: *mut DWORD, strSessionKey: *const WCHAR, ) -> DWORD95     pub fn RmJoinSession(
96         pSessionHandle: *mut DWORD,
97         strSessionKey: *const WCHAR,
98     ) -> DWORD;
RmEndSession( dwSessionHandle: DWORD, ) -> DWORD99     pub fn RmEndSession(
100         dwSessionHandle: DWORD,
101     ) -> DWORD;
RmRegisterResources( dwSessionHandle: DWORD, nFiles: UINT, rgsFileNames: *mut LPCWSTR, nApplications: UINT, rgApplications: *mut RM_UNIQUE_PROCESS, nServices: UINT, rgsServiceNames: *mut LPCWSTR, ) -> DWORD102     pub fn RmRegisterResources(
103         dwSessionHandle: DWORD,
104         nFiles: UINT,
105         rgsFileNames: *mut LPCWSTR,
106         nApplications: UINT,
107         rgApplications: *mut RM_UNIQUE_PROCESS,
108         nServices: UINT,
109         rgsServiceNames: *mut LPCWSTR,
110     ) -> DWORD;
RmGetList( dwSessionHandle: DWORD, pnProcInfoNeeded: *mut UINT, pnProcInfo: *mut UINT, rgAffectedApps: *mut RM_PROCESS_INFO, lpdwRebootReasons: LPDWORD, ) -> DWORD111     pub fn RmGetList(
112         dwSessionHandle: DWORD,
113         pnProcInfoNeeded: *mut UINT,
114         pnProcInfo: *mut UINT,
115         rgAffectedApps: *mut RM_PROCESS_INFO,
116         lpdwRebootReasons: LPDWORD,
117     ) -> DWORD;
RmShutdown( dwSessionHandle: DWORD, lActionFlags: ULONG, fnStatus: RM_WRITE_STATUS_CALLBACK, ) -> DWORD118     pub fn RmShutdown(
119         dwSessionHandle: DWORD,
120         lActionFlags: ULONG,
121         fnStatus: RM_WRITE_STATUS_CALLBACK,
122     ) -> DWORD;
RmRestart( dwSessionHandle: DWORD, dwRestartFlags: DWORD, fnStatus: RM_WRITE_STATUS_CALLBACK, ) -> DWORD123     pub fn RmRestart(
124         dwSessionHandle: DWORD,
125         dwRestartFlags: DWORD,
126         fnStatus: RM_WRITE_STATUS_CALLBACK,
127     ) -> DWORD;
RmCancelCurrentTask( dwSessionHandle: DWORD, ) -> DWORD128     pub fn RmCancelCurrentTask(
129         dwSessionHandle: DWORD,
130     ) -> DWORD;
RmAddFilter( dwSessionHandle: DWORD, strModuleName: LPCWSTR, pProcess: *mut RM_UNIQUE_PROCESS, strServiceShortName: LPCWSTR, FilterAction: RM_FILTER_ACTION, ) -> DWORD131     pub fn RmAddFilter(
132         dwSessionHandle: DWORD,
133         strModuleName: LPCWSTR,
134         pProcess: *mut RM_UNIQUE_PROCESS,
135         strServiceShortName: LPCWSTR,
136         FilterAction: RM_FILTER_ACTION,
137     ) -> DWORD;
RmRemoveFilter( dwSessionHandle: DWORD, strModuleName: LPCWSTR, pProcess: *mut RM_UNIQUE_PROCESS, strServiceShortName: LPCWSTR, ) -> DWORD138     pub fn RmRemoveFilter(
139         dwSessionHandle: DWORD,
140         strModuleName: LPCWSTR,
141         pProcess: *mut RM_UNIQUE_PROCESS,
142         strServiceShortName: LPCWSTR,
143     ) -> DWORD;
RmGetFilterList( dwSessionHandle: DWORD, pbFilterBuf: PBYTE, cbFilterBuf: DWORD, cbFilterBufNeeded: LPDWORD, ) -> DWORD144     pub fn RmGetFilterList(
145         dwSessionHandle: DWORD,
146         pbFilterBuf: PBYTE,
147         cbFilterBuf: DWORD,
148         cbFilterBufNeeded: LPDWORD,
149     ) -> DWORD;
150 }
151