2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS user32.dll
4 * FILE: lib/user32/misc/exit.c
5 * PURPOSE: Shutdown related functions
6 * PROGRAMMER: Eric Kohl
11 #include <wine/debug.h>
16 * - App (usually explorer) calls ExitWindowsEx()
17 * - ExitWindowsEx() sends a message to CSRSS
18 * - CSRSS impersonates the caller and sends a message to a hidden WinLogon window
19 * - WinLogon checks if the caller has the required privileges
20 * - WinLogon enters pending log-out state
21 * - WinLogon impersonates the interactive user and calls ExitWindowsEx() again,
22 * passing some special internal flags
23 * - CSRSS loops over all processes of the interactive user (sorted by their
24 * SetProcessShutdownParameters() level), sending WM_QUERYENDSESSION and
25 * WM_ENDSESSION messages to its top-level windows. If the messages aren't
26 * processed within the timeout period (registry key HKCU\Control Panel\Desktop\HungAppTimeout)
27 * CSRSS will put up a dialog box asking if the process should be terminated.
28 * Using the registry key HKCU\Control Panel\Desktop\AutoEndTask you can
29 * specify that the dialog box shouldn't be shown and CSRSS should just
30 * terminate the thread. If the the WM_ENDSESSION message is processed
31 * but the thread doesn't terminate within the timeout specified by
32 * HKCU\Control Panel\Desktop\WaitToKillAppTimeout CSRSS will terminate
33 * the thread. When all the top-level windows have been destroyed CSRSS
34 * will terminate the process.
35 * If the process is a console process, CSRSS will send a CTRL_LOGOFF_EVENT
36 * to the console control handler on logoff. No event is sent on shutdown.
37 * If the handler doesn't respond in time the same activities as for GUI
38 * apps (i.e. display dialog box etc) take place. This also happens if
39 * the handler returns TRUE.
40 * - This ends the processing for the first ExitWindowsEx() call from WinLogon.
41 * Execution continues in WinLogon, which calls ExitWindowsEx() again to
42 * terminate COM processes in the interactive user's session.
43 * - WinLogon stops impersonating the interactive user (whos processes are
44 * all dead by now). and enters log-out state
45 * - If the ExitWindowsEx() request was for a logoff, WinLogon sends a SAS
46 * event (to display the "press ctrl+alt+del") to the GINA. WinLogon then
47 * waits for the GINA to send a SAS event to login.
48 * - If the ExitWindowsEx() request was for shutdown/restart, WinLogon calls
49 * ExitWindowsEx() again in the system process context.
50 * - CSRSS goes through the motions of sending WM_QUERYENDSESSION/WM_ENDSESSION
51 * to GUI processes running in the system process context but won't display
52 * dialog boxes or kill threads/processes. Same for console processes,
53 * using the CTRL_SHUTDOWN_EVENT. The Service Control Manager is one of
54 * these console processes and has a special timeout value WaitToKillServiceTimeout.
55 * - WinLogon issues a "InitiateSystemShutdown" request to the SM (SMSS API # 1)
56 * - the SM propagates the shutdown request to every environment subsystem it
57 * started since bootstrap time (still active ones, of course)
58 * - each environment subsystem, on shutdown request, releases every resource
59 * it aquired during its life (processes, memory etc), then dies
60 * - when every environment subsystem has gone to bed, the SM actually initiates
61 * the kernel and executive shutdown by calling NtShutdownSystem.
67 ExitWindowsEx(UINT uFlags
,
70 USER_API_MESSAGE ApiMessage
;
73 ApiMessage
.Data
.ExitReactosRequest
.Flags
= uFlags
;
74 ApiMessage
.Data
.ExitReactosRequest
.Reserved
= dwReserved
;
76 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
78 CSR_CREATE_API_NUMBER(USERSRV_SERVERDLL_INDEX
, UserpExitWindowsEx
),
79 sizeof(CSRSS_EXIT_REACTOS
));
80 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= ApiMessage
.Status
))
82 SetLastError(RtlNtStatusToDosError(Status
));
94 RegisterServicesProcess(DWORD ServicesProcessId
)
96 USER_API_MESSAGE ApiMessage
;
99 ApiMessage
.Data
.RegisterServicesProcessRequest
.ProcessId
= UlongToHandle(ServicesProcessId
);
101 Status
= CsrClientCallServer((PCSR_API_MESSAGE
)&ApiMessage
,
103 CSR_CREATE_API_NUMBER(USERSRV_SERVERDLL_INDEX
, UserpRegisterServicesProcess
),
104 sizeof(CSRSS_REGISTER_SERVICES_PROCESS
));
105 if (!NT_SUCCESS(Status
) || !NT_SUCCESS(Status
= ApiMessage
.Status
))
107 SetLastError(RtlNtStatusToDosError(Status
));