ReactOS 0.4.15-dev-8614-gbc76250
power.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  tagWIN32POWERCALLOUT
 

Macros

#define ASSERT_POWER_CALLOUT_LOCK_ACQUIRED()    ASSERT(gpPowerCalloutMutexOwnerThread == KeGetCurrentThread())
 

Typedefs

typedef enum tagPOWER_CALLOUT_TYPE POWER_CALLOUT_TYPE
 
typedef struct tagWIN32POWERCALLOUT WIN32POWERCALLOUT
 
typedef struct tagWIN32POWERCALLOUTPWIN32POWERCALLOUT
 

Enumerations

enum  tagPOWER_CALLOUT_TYPE { POWER_CALLOUT_EVENT = 0 , POWER_CALLOUT_STATE }
 

Functions

NTSTATUS NTAPI IntInitWin32PowerManagement (_In_ HANDLE hPowerRequestEvent)
 Initializes the power management side of Win32 kernel-mode subsystem component. This enables communication between the power manager of the NT kernel and Win32k.
 
NTSTATUS NTAPI IntWin32PowerManagementCleanup (VOID)
 Cleanup procedure that frees all the allocated resources by the power manager. It is triggered during Win32k subsystem unloading.
 
NTSTATUS NTAPI IntHandlePowerEvent (_In_ PWIN32_POWEREVENT_PARAMETERS pWin32PwrEventParams)
 Handles an incoming power event callout from the NT power manager.
 
NTSTATUS NTAPI IntHandlePowerState (_In_ PWIN32_POWERSTATE_PARAMETERS pWin32PwrStateParams)
 Handles an incoming power state callout from the NT power manager.
 
FORCEINLINE VOID IntAcquirePowerCalloutLock (VOID)
 
FORCEINLINE VOID IntReleasePowerCalloutLock (VOID)
 
FORCEINLINE BOOL IntIsThreadWin32Thread (_In_ PETHREAD Thread)
 

Variables

LIST_ENTRY gPowerCalloutsQueueList
 
PFAST_MUTEX gpPowerCalloutMutexLock
 
PKEVENT gpPowerRequestCalloutEvent
 
PKTHREAD gpPowerCalloutMutexOwnerThread
 

Macro Definition Documentation

◆ ASSERT_POWER_CALLOUT_LOCK_ACQUIRED

#define ASSERT_POWER_CALLOUT_LOCK_ACQUIRED ( )     ASSERT(gpPowerCalloutMutexOwnerThread == KeGetCurrentThread())

Definition at line 40 of file power.h.

Typedef Documentation

◆ POWER_CALLOUT_TYPE

◆ PWIN32POWERCALLOUT

◆ WIN32POWERCALLOUT

Enumeration Type Documentation

◆ tagPOWER_CALLOUT_TYPE

Enumerator
POWER_CALLOUT_EVENT 
POWER_CALLOUT_STATE 

Definition at line 13 of file power.h.

14{
@ POWER_CALLOUT_EVENT
Definition: power.h:15
@ POWER_CALLOUT_STATE
Definition: power.h:16
enum tagPOWER_CALLOUT_TYPE POWER_CALLOUT_TYPE

Function Documentation

◆ IntAcquirePowerCalloutLock()

FORCEINLINE VOID IntAcquirePowerCalloutLock ( VOID  )

Definition at line 78 of file power.h.

79{
83}
#define KeGetCurrentThread
Definition: hal.h:55
#define KeEnterCriticalRegion()
Definition: ke_x.h:88
VOID FASTCALL ExAcquireFastMutexUnsafe(IN OUT PFAST_MUTEX FastMutex)
Definition: fmutex.c:75
PFAST_MUTEX gpPowerCalloutMutexLock
Definition: power.c:16
PKTHREAD gpPowerCalloutMutexOwnerThread
Definition: power.c:18

Referenced by IntDeployPowerCallout(), and IntEnlistPowerCallout().

◆ IntHandlePowerEvent()

NTSTATUS NTAPI IntHandlePowerEvent ( _In_ PWIN32_POWEREVENT_PARAMETERS  pWin32PwrEventParams)

Handles an incoming power event callout from the NT power manager.

Parameters
[in]pWin32PwrEventParamsA pointer to power event parameters that is given by the NT power manager of the kernel.
Returns
Returns STATUS_UNSUCCESSFUL if the Client/Server subsystem is not running, of which power callouts cannot be handled. Returns STATUS_INVALID_PARAMETER if the provided power event parameters are not valid. Returns STATUS_INSUFFICIENT_RESOURCES if there is a lack of memory to allocate for the power callout. Otherwise it returns STATUS_SUCCESS to indicate the power callout was handled successfully.

Definition at line 362 of file power.c.

364{
365 PWIN32POWERCALLOUT pWin32PwrCallout;
367
368 /*
369 * CSRSS is not running. As a consequence, the USER subsystem is neither
370 * up and running as the Client/Server subsystem is responsible to fire
371 * up other subsystems. Another case is that the system undergoes shutdown
372 * and Win32k cleanup is currently in effect. Either way, just quit.
373 */
374 if (!gpepCSRSS)
375 {
376 TRACE("CSRSS is not running, bailing out\n");
377 return STATUS_UNSUCCESSFUL;
378 }
379
380 /* Validate the power event parameters, just to be sure we have not gotten anything else */
381 Status = IntValidateWin32PowerParams(pWin32PwrEventParams);
382 if (!NT_SUCCESS(Status))
383 {
384 ERR("Could not deploy power callout, invalid Win32 power parameters!\n");
385 return Status;
386 }
387
388 /* Allocate pool of memory for this power callout */
389 pWin32PwrCallout = ExAllocatePoolZero(NonPagedPool,
390 sizeof(WIN32POWERCALLOUT),
392 if (pWin32PwrCallout == NULL)
393 {
394 ERR("Allocating memory for Win32 power callout failed\n");
396 }
397
398 /* Fill the necessary power datum */
399 pWin32PwrCallout->Type = POWER_CALLOUT_EVENT;
400 pWin32PwrCallout->Params.EventNumber = pWin32PwrEventParams->EventNumber;
401 pWin32PwrCallout->Params.Code = pWin32PwrEventParams->Code;
402
403 /* Enqueue this power request for later processing */
404 IntEnlistPowerCallout(pWin32PwrCallout);
405 return STATUS_SUCCESS;
406}
LONG NTSTATUS
Definition: precomp.h:26
#define ERR(fmt,...)
Definition: precomp.h:57
PEPROCESS gpepCSRSS
Definition: csr.c:15
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define NonPagedPool
Definition: env_spec_w32.h:307
Status
Definition: gdiplustypes.h:25
FORCEINLINE PVOID ExAllocatePoolZero(ULONG PoolType, SIZE_T NumberOfBytes, ULONG Tag)
Definition: precomp.h:45
#define STATUS_SUCCESS
Definition: shellext.h:65
#define TRACE(s)
Definition: solgame.cpp:4
PSPOWEREVENTTYPE EventNumber
Definition: pstypes.h:1616
POWER_CALLOUT_TYPE Type
Definition: power.h:31
WIN32_POWEREVENT_PARAMETERS Params
Definition: power.h:34
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
static VOID IntEnlistPowerCallout(_In_ PWIN32POWERCALLOUT pPowerCallout)
Enlists a newly allocated power callout into the queue list for later processing.
Definition: power.c:212
static NTSTATUS IntValidateWin32PowerParams(_In_ PWIN32_POWEREVENT_PARAMETERS pParameters)
Validates the power event parameters that come from a power callout from the kernel power manager.
Definition: power.c:82
#define USERTAG_POWER
Definition: tags.h:263

Referenced by DriverEntry().

◆ IntHandlePowerState()

NTSTATUS NTAPI IntHandlePowerState ( _In_ PWIN32_POWERSTATE_PARAMETERS  pWin32PwrStateParams)

Handles an incoming power state callout from the NT power manager.

Parameters
[in]pWin32PwrStateParamsA pointer to power state parameters that is given by the NT power manager of the kernel.

Definition at line 419 of file power.c.

421{
422 /* FIXME */
423 ERR("IntHandlePowerState is UNIMPLEMENTED\n");
425}
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:239

Referenced by DriverEntry().

◆ IntInitWin32PowerManagement()

NTSTATUS NTAPI IntInitWin32PowerManagement ( _In_ HANDLE  hPowerRequestEvent)

Initializes the power management side of Win32 kernel-mode subsystem component. This enables communication between the power manager of the NT kernel and Win32k.

Parameters
[in]hPowerRequestEventA handle to the global power request event, provided by the Winsrv module. This allows CSRSS to be notified of power callouts that cannot be handled by Win32k.
Returns
Returns STATUS_INSUFFICIENT_RESOURCES if pool allocation for the power callout lock has failed due to lack of necessary memory. A failure NTSTATUS code is returned if the power request event could not be referenced. Otherwise STATUS_SUCCESS is returned to indicate the power management has initialized successfully.

Definition at line 271 of file power.c.

273{
275
276 /* Allocate memory pool for the power callout mutex */
278 sizeof(FAST_MUTEX),
281 {
282 ERR("Failed to allocate pool of memory for the power callout mutex\n");
284 }
285
286 /* Initialize the mutex and owner thread */
289
290 /* Initialize the global queue list and the power callout (aka request) event object */
292 Status = ObReferenceObjectByHandle(hPowerRequestEvent,
297 NULL);
298 if (!NT_SUCCESS(Status))
299 {
300 ERR("Failed to reference the power callout event handle (Status 0x%08lx)\n", Status);
302 return Status;
303 }
304
305 return STATUS_SUCCESS;
306}
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define EVENT_ALL_ACCESS
Definition: isotest.c:82
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
#define KernelMode
Definition: asm.h:34
POBJECT_TYPE ExEventObjectType
Definition: event.c:18
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
Definition: obref.c:494
LIST_ENTRY gPowerCalloutsQueueList
Definition: power.c:15
PFAST_MUTEX gpPowerCalloutMutexLock
Definition: power.c:16
PKTHREAD gpPowerCalloutMutexOwnerThread
Definition: power.c:18
PKEVENT gpPowerRequestCalloutEvent
Definition: power.c:17
FORCEINLINE VOID ExInitializeFastMutex(_Out_ PFAST_MUTEX FastMutex)
Definition: exfuncs.h:274
FAST_MUTEX
Definition: extypes.h:17

Referenced by NtUserInitialize().

◆ IntIsThreadWin32Thread()

FORCEINLINE BOOL IntIsThreadWin32Thread ( _In_ PETHREAD  Thread)

Definition at line 99 of file power.h.

101{
102 return (Thread->Tcb.Win32Thread != NULL) ? TRUE : FALSE;
103}
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
KTHREAD Tcb
Definition: pstypes.h:1103
PVOID Win32Thread
Definition: ketypes.h:1866

Referenced by IntEnlistPowerCallout().

◆ IntReleasePowerCalloutLock()

FORCEINLINE VOID IntReleasePowerCalloutLock ( VOID  )

Definition at line 87 of file power.h.

88{
92}
#define KeLeaveCriticalRegion()
Definition: ke_x.h:119
VOID FASTCALL ExReleaseFastMutexUnsafe(IN OUT PFAST_MUTEX FastMutex)
Definition: fmutex.c:86

Referenced by IntDeployPowerCallout(), and IntEnlistPowerCallout().

◆ IntWin32PowerManagementCleanup()

NTSTATUS NTAPI IntWin32PowerManagementCleanup ( VOID  )

Cleanup procedure that frees all the allocated resources by the power manager. It is triggered during Win32k subsystem unloading.

Definition at line 315 of file power.c.

316{
317 PWIN32POWERCALLOUT pWin32PwrCallout;
318
319 /* Dereference the power request event */
322
323 /*
324 * Enumerate all pending power callouts and free them. We do not
325 * need to do this with the lock held as the CSR process is tore
326 * apart during Win32k cleanup, so future power callouts would not
327 * be allowed anyway, therefore we are safe.
328 */
329 for (pWin32PwrCallout = IntGetNextPowerCallout(NULL);
330 pWin32PwrCallout != NULL;
331 pWin32PwrCallout = IntGetNextPowerCallout(pWin32PwrCallout))
332 {
333 ExFreePoolWithTag(pWin32PwrCallout, USERTAG_POWER);
334 }
335
336 /* Tear apart the power callout lock mutex */
339 return STATUS_SUCCESS;
340}
static PWIN32POWERCALLOUT IntGetNextPowerCallout(_In_ PWIN32POWERCALLOUT pPowerCallout)
Gets the next pending power callout from the global queue list and returns it to the caller....
Definition: power.c:121
#define ObDereferenceObject
Definition: obfuncs.h:203

Referenced by _Function_class_().

Variable Documentation

◆ gPowerCalloutsQueueList

LIST_ENTRY gPowerCalloutsQueueList
extern

◆ gpPowerCalloutMutexLock

◆ gpPowerCalloutMutexOwnerThread

PKTHREAD gpPowerCalloutMutexOwnerThread
extern

◆ gpPowerRequestCalloutEvent

PKEVENT gpPowerRequestCalloutEvent
extern