ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

poshtdwn.c
Go to the documentation of this file.
00001 /*
00002  * PROJECT:         ReactOS Kernel
00003  * LICENSE:         BSD - See COPYING.ARM in the top level directory
00004  * FILE:            ntoskrnl/po/poshtdwn.c
00005  * PURPOSE:         Power Manager Shutdown Code
00006  * PROGRAMMERS:     ReactOS Portable Systems Group
00007  */
00008 
00009 /* INCLUDES ******************************************************************/
00010 
00011 #include <ntoskrnl.h>
00012 #ifdef NEWCC
00013 #include "../cache/newcc.h"
00014 #endif
00015 #define NDEBUG
00016 #include <debug.h>
00017 
00018 /* GLOBALS *******************************************************************/
00019 
00020 ULONG PopShutdownPowerOffPolicy;
00021 
00022 /* PRIVATE FUNCTIONS *********************************************************/
00023 
00024 VOID
00025 NTAPI
00026 PopShutdownHandler(VOID)
00027 {
00028     PUCHAR Logo1, Logo2;
00029     ULONG i;
00030     
00031     /* Stop all interrupts */
00032     KeRaiseIrqlToDpcLevel();
00033     _disable();
00034 
00035     /* Do we have boot video */
00036     if (InbvIsBootDriverInstalled())
00037     {
00038         /* Yes we do, cleanup for shutdown screen */
00039         if (!InbvCheckDisplayOwnership()) InbvAcquireDisplayOwnership();
00040         InbvResetDisplay();
00041         InbvSolidColorFill(0, 0, 639, 479, 0);
00042         InbvEnableDisplayString(TRUE);
00043         InbvSetScrollRegion(0, 0, 639, 479);
00044 
00045         /* Display shutdown logo and message */
00046         Logo1 = InbvGetResourceAddress(IDB_SHUTDOWN_LOGO);
00047         Logo2 = InbvGetResourceAddress(IDB_LOGO);
00048         if ((Logo1) && (Logo2))
00049         {
00050             InbvBitBlt(Logo1, 215, 352);
00051             InbvBitBlt(Logo2, 217, 111);
00052         }
00053     }
00054     else
00055     {
00056         /* Do it in text-mode */
00057         for (i = 0; i < 25; i++) InbvDisplayString("\n");
00058         InbvDisplayString("                       ");
00059         InbvDisplayString("The system may be powered off now.\n");
00060     }
00061 
00062     /* Hang the system */
00063     for (;;) HalHaltSystem();
00064 }
00065 
00066 VOID
00067 NTAPI
00068 PopShutdownSystem(IN POWER_ACTION SystemAction)
00069 {
00070     /* Note should notify caller of NtPowerInformation(PowerShutdownNotification) */
00071 
00072     /* Unload symbols */
00073     DPRINT1("It's the final countdown...%lx\n", SystemAction);
00074     DbgUnLoadImageSymbols(NULL, (PVOID)-1, 0);
00075     
00076     /* Run the thread on the boot processor */
00077     KeSetSystemAffinityThread(1);
00078 
00079     /* Now check what the caller wants */
00080     switch (SystemAction)
00081     {
00082         /* Reset */
00083         case PowerActionShutdownReset:
00084 
00085             /* Try platform driver first, then legacy */
00086             //PopInvokeSystemStateHandler(PowerStateShutdownReset, NULL);
00087             PopSetSystemPowerState(PowerSystemShutdown, SystemAction);
00088             HalReturnToFirmware(HalRebootRoutine);
00089             break;
00090 
00091         case PowerActionShutdown:
00092 
00093             /* Check for group policy that says to use "it is now safe" screen */
00094             if (PopShutdownPowerOffPolicy)
00095             {
00096                 /* FIXFIX: Switch to legacy shutdown handler */
00097                 //PopPowerStateHandlers[PowerStateShutdownOff].Handler = PopShutdownHandler;
00098             }
00099 
00100         case PowerActionShutdownOff:
00101 
00102             /* Call shutdown handler */
00103             //PopInvokeSystemStateHandler(PowerStateShutdownOff, NULL);
00104             
00105             /* ReactOS Hack */
00106             PopSetSystemPowerState(PowerSystemShutdown, SystemAction);
00107             PopShutdownHandler();
00108 
00109             /* If that didn't work, call the HAL */
00110             HalReturnToFirmware(HalPowerDownRoutine);
00111             break;
00112 
00113         default:
00114             break;
00115     }
00116 
00117     /* Anything else should not happen */
00118     KeBugCheckEx(INTERNAL_POWER_ERROR, 5, 0, 0, 0);
00119 }
00120 
00121 VOID
00122 NTAPI
00123 PopGracefulShutdown(IN PVOID Context)
00124 {
00125     PEPROCESS Process = NULL;
00126 
00127     /* Loop every process */
00128     Process = PsGetNextProcess(Process);
00129     while (Process)
00130     {
00131         /* Make sure this isn't the idle or initial process */
00132         if ((Process != PsInitialSystemProcess) && (Process != PsIdleProcess))
00133         {
00134             /* Print it */
00135             DPRINT1("%15s is still RUNNING (%lx)\n", Process->ImageFileName, Process->UniqueProcessId);
00136         }
00137 
00138         /* Get the next process */
00139         Process = PsGetNextProcess(Process);
00140     }
00141 
00142     /* First, the HAL handles any "end of boot" special functionality */
00143     DPRINT1("HAL shutting down\n");
00144     HalEndOfBoot();
00145 
00146     /* In this step, the I/O manager does first-chance shutdown notification */
00147     DPRINT1("I/O manager shutting down in phase 0\n");    
00148     IoShutdownSystem(0);
00149     
00150     /* In this step, all workers are killed and hives are flushed */
00151     DPRINT1("Configuration Manager shutting down\n");
00152     CmShutdownSystem();
00153     
00154     /* Note that modified pages should be written here (MiShutdownSystem) */
00155 #ifdef NEWCC
00156     /* Flush all user files before we start shutting down IO */
00157     /* This is where modified pages are written back by the IO manager */
00158     CcShutdownSystem();
00159 #endif
00160 
00161     /* In this step, the I/O manager does last-chance shutdown notification */
00162     DPRINT1("I/O manager shutting down in phase 1\n"); 
00163     IoShutdownSystem(1);
00164     CcWaitForCurrentLazyWriterActivity();
00165 
00166     /* Note that here, we should broadcast the power IRP to devices */
00167 
00168     /* In this step, the HAL disables any wake timers */
00169     DPRINT1("Disabling wake timers\n");
00170     HalSetWakeEnable(FALSE);
00171     
00172     /* And finally the power request is sent */
00173     DPRINT1("Taking the system down\n");
00174     PopShutdownSystem(PopAction.Action);
00175 }
00176 
00177 VOID
00178 NTAPI
00179 PopReadShutdownPolicy(VOID)
00180 {
00181     UNICODE_STRING KeyString;
00182     OBJECT_ATTRIBUTES ObjectAttributes;
00183     NTSTATUS Status;
00184     HANDLE KeyHandle;
00185     ULONG Length;
00186     UCHAR Buffer[sizeof(KEY_VALUE_PARTIAL_INFORMATION) + sizeof(ULONG)];
00187     PKEY_VALUE_PARTIAL_INFORMATION Info = (PVOID)Buffer;
00188     
00189     /* Setup object attributes */
00190     RtlInitUnicodeString(&KeyString,
00191                          L"\\Registry\\Machine\\Software\\Policies\\Microsoft\\Windows NT");
00192     InitializeObjectAttributes(&ObjectAttributes,
00193                                &KeyString,
00194                                OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE,
00195                                NULL,
00196                                NULL);
00197 
00198     /* Open the key */
00199     Status = ZwOpenKey(&KeyHandle, KEY_READ, &ObjectAttributes);
00200     if (NT_SUCCESS(Status))
00201     {
00202         /* Open the policy value and query it */
00203         RtlInitUnicodeString(&KeyString, L"DontPowerOffAfterShutdown");
00204         Status = ZwQueryValueKey(KeyHandle,
00205                                  &KeyString,
00206                                  KeyValuePartialInformation,
00207                                  &Info,
00208                                  sizeof(Info),
00209                                  &Length);
00210         if ((NT_SUCCESS(Status)) && (Info->Type == REG_DWORD))
00211         {
00212             /* Read the policy */
00213             PopShutdownPowerOffPolicy = *Info->Data == 1;
00214         }
00215 
00216         /* Close the key */
00217         ZwClose(KeyHandle);
00218     }
00219 }
00220 
00221 /* PUBLIC FUNCTIONS **********************************************************/
00222 

Generated on Fri May 25 2012 04:36:05 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.