[CONSOLE.CPL-KERNEL32-USER32-NTDLL-CSRSRV-CONSRV-BASESRV-WINSRV]
[reactos.git] / win32ss / user / user32 / misc / exit.c
1 /*
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
7 */
8
9 #include <user32.h>
10
11 #include <wine/debug.h>
12
13 /*
14 * Sequence of events:
15 *
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.
62 */
63 /*
64 * @implemented
65 */
66 BOOL WINAPI
67 ExitWindowsEx(UINT uFlags,
68 DWORD dwReserved)
69 {
70 NTSTATUS Status;
71 USER_API_MESSAGE ApiMessage;
72
73 ApiMessage.Data.ExitReactosRequest.Flags = uFlags;
74 ApiMessage.Data.ExitReactosRequest.Reserved = dwReserved;
75
76 Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
77 NULL,
78 CSR_CREATE_API_NUMBER(USERSRV_SERVERDLL_INDEX, UserpExitWindowsEx),
79 sizeof(USER_EXIT_REACTOS));
80 if (!NT_SUCCESS(Status))
81 {
82 SetLastError(RtlNtStatusToDosError(Status));
83 return FALSE;
84 }
85
86 return TRUE;
87 }
88
89
90 /*
91 * @implemented
92 */
93 BOOL WINAPI
94 RegisterServicesProcess(DWORD ServicesProcessId)
95 {
96 NTSTATUS Status;
97 USER_API_MESSAGE ApiMessage;
98
99 ApiMessage.Data.RegisterServicesProcessRequest.ProcessId = ServicesProcessId;
100
101 Status = CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage,
102 NULL,
103 CSR_CREATE_API_NUMBER(USERSRV_SERVERDLL_INDEX, UserpRegisterServicesProcess),
104 sizeof(USER_REGISTER_SERVICES_PROCESS));
105 if (!NT_SUCCESS(Status))
106 {
107 SetLastError(RtlNtStatusToDosError(Status));
108 return FALSE;
109 }
110
111 return TRUE;
112 }
113
114 /* EOF */