ReactOS 0.4.15-dev-7674-gc0b4db1
main.c File Reference
#include "precomp.h"
#include <poclass.h>
#include <debug.h>
Include dependency graph for main.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

NTSTATUS NTAPI DriverEntry (PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
 
NTSTATUS NTAPI Bus_AddDevice (PDRIVER_OBJECT DriverObject, PDEVICE_OBJECT PhysicalDeviceObject)
 
NTSTATUS NTAPI ACPIDispatchCreateClose (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
VOID NTAPI ButtonWaitThread (PVOID Context)
 
NTSTATUS NTAPI ACPIDispatchDeviceControl (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
static NTSTATUS AcpiRegOpenKey (IN HANDLE ParentKeyHandle, IN LPCWSTR KeyName, IN ACCESS_MASK DesiredAccess, OUT HANDLE KeyHandle)
 
static NTSTATUS AcpiRegQueryValue (IN HANDLE KeyHandle, IN LPWSTR ValueName, OUT PULONG Type OPTIONAL, OUT PVOID Data OPTIONAL, IN OUT PULONG DataLength OPTIONAL)
 
static NTSTATUS GetProcessorInformation (VOID)
 

Variables

struct acpi_devicesleep_button
 
struct acpi_devicepower_button
 
UNICODE_STRING ProcessorHardwareIds = {0, 0, NULL}
 
LPWSTR ProcessorIdString = NULL
 
LPWSTR ProcessorNameString = NULL
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 5 of file main.c.

Function Documentation

◆ ACPIDispatchCreateClose()

NTSTATUS NTAPI ACPIDispatchCreateClose ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 179 of file main.c.

182{
183 Irp->IoStatus.Status = STATUS_SUCCESS;
184 Irp->IoStatus.Information = 0;
185
187
188 return STATUS_SUCCESS;
189}
_In_ PIRP Irp
Definition: csq.h:116
#define IoCompleteRequest
Definition: irp.c:1240
#define STATUS_SUCCESS
Definition: shellext.h:65
#define IO_NO_INCREMENT
Definition: iotypes.h:598

Referenced by DriverEntry().

◆ ACPIDispatchDeviceControl()

NTSTATUS NTAPI ACPIDispatchDeviceControl ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 227 of file main.c.

230{
231 PIO_STACK_LOCATION irpStack;
233 PCOMMON_DEVICE_DATA commonData;
234 ULONG Caps = 0;
235 HANDLE ThreadHandle;
236
237 PAGED_CODE ();
238
241
242 commonData = (PCOMMON_DEVICE_DATA) DeviceObject->DeviceExtension;
243
244 Irp->IoStatus.Information = 0;
245
246 if (!commonData->IsFDO)
247 {
248 switch (irpStack->Parameters.DeviceIoControl.IoControlCode)
249 {
252 Irp);
253 break;
254
256 if (irpStack->Parameters.DeviceIoControl.OutputBufferLength < sizeof(ULONG))
257 {
259 break;
260 }
261
262 if (wcsstr(((PPDO_DEVICE_DATA)commonData)->HardwareIDs, L"PNP0C0D"))
263 {
264 DPRINT1("Lid button reported to power manager\n");
265 Caps |= SYS_BUTTON_LID;
266 }
267 else if (((PPDO_DEVICE_DATA)commonData)->AcpiHandle == NULL)
268 {
269 /* We have to return both at the same time because since we
270 * have a NULL handle we are the fixed feature DO and we will
271 * only be called once (not once per device)
272 */
273 if (power_button)
274 {
275 DPRINT("Fixed power button reported to power manager\n");
276 Caps |= SYS_BUTTON_POWER;
277 }
278 if (sleep_button)
279 {
280 DPRINT("Fixed sleep button reported to power manager\n");
281 Caps |= SYS_BUTTON_SLEEP;
282 }
283 }
284 else if (wcsstr(((PPDO_DEVICE_DATA)commonData)->HardwareIDs, L"PNP0C0C"))
285 {
286 DPRINT("Control method power button reported to power manager\n");
287 Caps |= SYS_BUTTON_POWER;
288 }
289 else if (wcsstr(((PPDO_DEVICE_DATA)commonData)->HardwareIDs, L"PNP0C0E"))
290 {
291 DPRINT("Control method sleep reported to power manager\n");
292 Caps |= SYS_BUTTON_SLEEP;
293 }
294 else
295 {
296 DPRINT1("IOCTL_GET_SYS_BUTTON_CAPS sent to a non-button device\n");
298 }
299
300 if (Caps != 0)
301 {
302 RtlCopyMemory(Irp->AssociatedIrp.SystemBuffer, &Caps, sizeof(Caps));
303 Irp->IoStatus.Information = sizeof(Caps);
305 }
306 break;
307
310 ZwClose(ThreadHandle);
311
313 break;
314
316 DPRINT("IOCTL_BATTERY_QUERY_TAG is not supported!\n");
317 break;
318
319 default:
320 DPRINT1("Unsupported IOCTL: %x\n", irpStack->Parameters.DeviceIoControl.IoControlCode);
321 break;
322 }
323 }
324 else
325 DPRINT1("IOCTL sent to the ACPI FDO! Kill the caller!\n");
326
327 if (status != STATUS_PENDING)
328 {
329 Irp->IoStatus.Status = status;
331 }
332 else
334
335 return status;
336}
#define PAGED_CODE()
#define IOCTL_ACPI_EVAL_METHOD
Definition: acpiioct.h:178
struct _COMMON_DEVICE_DATA * PCOMMON_DEVICE_DATA
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
#define IOCTL_BATTERY_QUERY_TAG
Definition: batclass.h:84
#define NULL
Definition: types.h:112
NTSTATUS NTAPI Bus_PDO_EvalMethod(PPDO_DEVICE_DATA DeviceData, PIRP Irp)
Definition: eval.c:85
struct acpi_device * sleep_button
Definition: button.c:56
struct acpi_device * power_button
Definition: button.c:55
VOID NTAPI ButtonWaitThread(PVOID Context)
Definition: main.c:193
_CONST_RETURN wchar_t *__cdecl wcsstr(_In_z_ const wchar_t *_Str, _In_z_ const wchar_t *_SubStr)
IoMarkIrpPending(Irp)
if(dx< 0)
Definition: linetemp.h:194
#define ASSERT(a)
Definition: mode.c:44
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
#define THREAD_ALL_ACCESS
Definition: nt_native.h:1339
NTSTATUS NTAPI PsCreateSystemThread(OUT PHANDLE ThreadHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, IN HANDLE ProcessHandle, IN PCLIENT_ID ClientId, IN PKSTART_ROUTINE StartRoutine, IN PVOID StartContext)
Definition: thread.c:602
#define STATUS_PENDING
Definition: ntstatus.h:82
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:423
#define L(x)
Definition: ntvdm.h:50
#define SYS_BUTTON_SLEEP
Definition: poclass.h:82
#define SYS_BUTTON_POWER
Definition: poclass.h:81
#define IOCTL_GET_SYS_BUTTON_CAPS
Definition: poclass.h:57
#define IOCTL_GET_SYS_BUTTON_EVENT
Definition: poclass.h:60
#define SYS_BUTTON_LID
Definition: poclass.h:83
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
#define DPRINT
Definition: sndvol32.h:71
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3128
Definition: ps.c:97
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2793

Referenced by DriverEntry().

◆ AcpiRegOpenKey()

static NTSTATUS AcpiRegOpenKey ( IN HANDLE  ParentKeyHandle,
IN LPCWSTR  KeyName,
IN ACCESS_MASK  DesiredAccess,
OUT HANDLE  KeyHandle 
)
static

Definition at line 340 of file main.c.

344{
347
349
351 &Name,
353 ParentKeyHandle,
354 NULL);
355
356 return ZwOpenKey(KeyHandle,
359}
struct NameRec_ * Name
Definition: cdprocs.h:460
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4715
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
_Must_inspect_result_ _In_ WDFDEVICE _In_ ULONG _In_ ACCESS_MASK DesiredAccess
Definition: wdfdevice.h:2658
_Must_inspect_result_ _In_ WDFDEVICE _In_ PCUNICODE_STRING KeyName
Definition: wdfdevice.h:2699

Referenced by GetProcessorInformation().

◆ AcpiRegQueryValue()

static NTSTATUS AcpiRegQueryValue ( IN HANDLE  KeyHandle,
IN LPWSTR  ValueName,
OUT PULONG Type  OPTIONAL,
OUT PVOID Data  OPTIONAL,
IN OUT PULONG DataLength  OPTIONAL 
)
static

Definition at line 363 of file main.c.

368{
373
375
376 if (DataLength != NULL)
378
379 /* Check if the caller provided a valid buffer */
380 if ((Data != NULL) && (BufferLength != 0))
381 {
383
384 /* Allocate memory for the value */
385 ValueInfo = ExAllocatePoolWithTag(PagedPool, BufferLength, 'MpcA');
386 if (ValueInfo == NULL)
387 return STATUS_NO_MEMORY;
388 }
389 else
390 {
391 /* Caller didn't provide a valid buffer, assume he wants the size only */
392 ValueInfo = NULL;
393 BufferLength = 0;
394 }
395
396 /* Query the value */
397 Status = ZwQueryValueKey(KeyHandle,
398 &Name,
400 ValueInfo,
402 &BufferLength);
403
404 if (DataLength != NULL)
406
407 /* Check if we have the size only */
408 if (ValueInfo == NULL)
409 {
410 /* Check for unexpected status */
413 {
414 return Status;
415 }
416
417 /* All is well */
419 }
420 /* Otherwise the caller wanted data back, check if we got it */
421 else if (NT_SUCCESS(Status))
422 {
423 if (Type != NULL)
424 *Type = ValueInfo->Type;
425
426 /* Copy it */
427 RtlMoveMemory(Data, ValueInfo->Data, ValueInfo->DataLength);
428
429 /* if the type is REG_SZ and data is not 0-terminated
430 * and there is enough space in the buffer NT appends a \0 */
431 if (((ValueInfo->Type == REG_SZ) ||
432 (ValueInfo->Type == REG_EXPAND_SZ) ||
433 (ValueInfo->Type == REG_MULTI_SZ)) &&
434 (ValueInfo->DataLength <= *DataLength - sizeof(WCHAR)))
435 {
436 WCHAR *ptr = (WCHAR *)((ULONG_PTR)Data + ValueInfo->DataLength);
437 if ((ptr > (WCHAR *)Data) && ptr[-1])
438 *ptr = 0;
439 }
440 }
441
442 /* Free the memory and return status */
443 if (ValueInfo != NULL)
444 {
445 ExFreePoolWithTag(ValueInfo, 'MpcA');
446 }
447
448 return Status;
449}
Type
Definition: Type.h:7
_In_ ULONG _In_opt_ WDFREQUEST _In_opt_ PVOID _In_ size_t _In_ PVOID _In_ size_t _Out_ size_t * DataLength
Definition: cdrom.h:1444
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define PagedPool
Definition: env_spec_w32.h:308
Status
Definition: gdiplustypes.h:25
#define REG_SZ
Definition: layer.c:22
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
static PVOID ptr
Definition: dispmode.c:27
@ KeyValuePartialInformation
Definition: nt_native.h:1182
#define REG_MULTI_SZ
Definition: nt_native.h:1501
#define REG_EXPAND_SZ
Definition: nt_native.h:1494
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:264
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG BufferLength
Definition: wdfdevice.h:3771
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING ValueName
Definition: wdfregistry.h:243
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by GetProcessorInformation().

◆ Bus_AddDevice()

NTSTATUS NTAPI Bus_AddDevice ( PDRIVER_OBJECT  DriverObject,
PDEVICE_OBJECT  PhysicalDeviceObject 
)

Definition at line 31 of file main.c.

36{
39 PFDO_DEVICE_DATA deviceData = NULL;
40#ifndef NDEBUG
41 PWCHAR deviceName = NULL;
42 ULONG nameLength;
43#endif
44
45 PAGED_CODE ();
46
47 DPRINT("Add Device: 0x%p\n", PhysicalDeviceObject);
48
49 DPRINT("#################### Bus_CreateClose Creating FDO Device ####################\n");
51 sizeof(FDO_DEVICE_DATA),
52 NULL,
55 TRUE,
57 if (!NT_SUCCESS(status))
58 {
59 DPRINT1("IoCreateDevice() failed with status 0x%X\n", status);
60 goto End;
61 }
62
63 deviceData = (PFDO_DEVICE_DATA) deviceObject->DeviceExtension;
64 RtlZeroMemory (deviceData, sizeof (FDO_DEVICE_DATA));
65
66 //
67 // Set the initial state of the FDO
68 //
69
70 INITIALIZE_PNP_STATE(deviceData->Common);
71
72 deviceData->Common.IsFDO = TRUE;
73
74 deviceData->Common.Self = deviceObject;
75
76 ExInitializeFastMutex (&deviceData->Mutex);
77
78 InitializeListHead (&deviceData->ListOfPDOs);
79
80 // Set the PDO for use with PlugPlay functions
81
83
84 //
85 // Set the initial powerstate of the FDO
86 //
87
90
92
93 //
94 // Attach our FDO to the device stack.
95 // The return value of IoAttachDeviceToDeviceStack is the top of the
96 // attachment chain. This is where all the IRPs should be routed.
97 //
98
102
103 if (NULL == deviceData->NextLowerDriver) {
104
106 goto End;
107 }
108
109
110#ifndef NDEBUG
111 //
112 // We will demonstrate here the step to retrieve the name of the PDO
113 //
114
117 0,
118 NULL,
119 &nameLength);
120
122 {
123 DPRINT1("AddDevice:IoGDP failed (0x%x)\n", status);
124 goto End;
125 }
126
127 deviceName = ExAllocatePoolWithTag(NonPagedPool, nameLength, 'MpcA');
128
129 if (NULL == deviceName) {
130 DPRINT1("AddDevice: no memory to alloc for deviceName(0x%x)\n", nameLength);
132 goto End;
133 }
134
137 nameLength,
138 deviceName,
139 &nameLength);
140
141 if (!NT_SUCCESS (status)) {
142
143 DPRINT1("AddDevice:IoGDP(2) failed (0x%x)", status);
144 goto End;
145 }
146
147 DPRINT("AddDevice: %p to %p->%p (%ws) \n",
149 deviceData->NextLowerDriver,
151 deviceName);
152
153#endif
154
155 //
156 // We are done with initializing, so let's indicate that and return.
157 // This should be the final step in the AddDevice process.
158 //
159 deviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
160
161End:
162#ifndef NDEBUG
163 if (deviceName){
164 ExFreePoolWithTag(deviceName, 'MpcA');
165 }
166#endif
168 if (deviceData && deviceData->NextLowerDriver){
169 IoDetachDevice (deviceData->NextLowerDriver);
170 }
172 }
173 return status;
174
175}
struct _FDO_DEVICE_DATA * PFDO_DEVICE_DATA
PDEVICE_OBJECT PhysicalDeviceObject
Definition: btrfs_drv.h:1157
#define FILE_DEVICE_SECURE_OPEN
Definition: cdrw_usr.h:46
#define TRUE
Definition: types.h:120
#define NonPagedPool
Definition: env_spec_w32.h:307
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define INITIALIZE_PNP_STATE(_Data_)
Definition: fbtusb.h:107
MxDeviceObject deviceObject
PDEVICE_OBJECT NTAPI IoAttachDeviceToDeviceStack(IN PDEVICE_OBJECT SourceDevice, IN PDEVICE_OBJECT TargetDevice)
Definition: device.c:966
NTSTATUS NTAPI IoCreateDevice(IN PDRIVER_OBJECT DriverObject, IN ULONG DeviceExtensionSize, IN PUNICODE_STRING DeviceName, IN DEVICE_TYPE DeviceType, IN ULONG DeviceCharacteristics, IN BOOLEAN Exclusive, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:1031
VOID NTAPI IoDetachDevice(IN PDEVICE_OBJECT TargetDevice)
Definition: device.c:1296
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
@ PowerSystemWorking
Definition: ntpoapi.h:36
@ PowerDeviceUnspecified
Definition: ntpoapi.h:48
NTSTATUS NTAPI IoGetDeviceProperty(IN PDEVICE_OBJECT DeviceObject, IN DEVICE_REGISTRY_PROPERTY DeviceProperty, IN ULONG BufferLength, OUT PVOID PropertyBuffer, OUT PULONG ResultLength)
Definition: pnpmgr.c:1382
#define FILE_DEVICE_ACPI
Definition: winioctl.h:156
SYSTEM_POWER_STATE SystemPowerState
Definition: acpisys.h:32
DEVICE_POWER_STATE DevicePowerState
Definition: acpisys.h:33
PDEVICE_OBJECT Self
Definition: acpisys.h:28
COMMON_DEVICE_DATA Common
Definition: acpisys.h:58
FAST_MUTEX Mutex
Definition: acpisys.h:72
PDEVICE_OBJECT NextLowerDriver
Definition: acpisys.h:63
LIST_ENTRY ListOfPDOs
Definition: acpisys.h:66
PDEVICE_OBJECT UnderlyingPDO
Definition: acpisys.h:59
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
uint16_t * PWCHAR
Definition: typedefs.h:56
#define STATUS_NO_SUCH_DEVICE
Definition: udferr_usr.h:136
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
FORCEINLINE VOID ExInitializeFastMutex(_Out_ PFAST_MUTEX FastMutex)
Definition: exfuncs.h:274
@ DevicePropertyPhysicalDeviceObjectName
Definition: iotypes.h:1206
#define DO_POWER_PAGABLE

Referenced by DriverEntry().

◆ ButtonWaitThread()

VOID NTAPI ButtonWaitThread ( PVOID  Context)

Definition at line 193 of file main.c.

194{
195 PIRP Irp = Context;
196 int result;
197 struct acpi_bus_event event;
198 ULONG ButtonEvent;
199
202
203 if (!ACPI_SUCCESS(result))
204 {
205 Irp->IoStatus.Status = STATUS_UNSUCCESSFUL;
206 }
207 else
208 {
209 if (strstr(event.bus_id, "PWRF"))
210 ButtonEvent = SYS_BUTTON_POWER;
211 else if (strstr(event.bus_id, "SLPF"))
212 ButtonEvent = SYS_BUTTON_SLEEP;
213 else
214 ButtonEvent = 0;
215
216 RtlCopyMemory(Irp->AssociatedIrp.SystemBuffer, &ButtonEvent, sizeof(ButtonEvent));
217 Irp->IoStatus.Status = STATUS_SUCCESS;
218 Irp->IoStatus.Information = sizeof(ULONG);
219 }
220
222}
char * strstr(char *String1, char *String2)
Definition: utclib.c:653
#define ACPI_SUCCESS(a)
Definition: acexcep.h:94
#define ACPI_BUTTON_NOTIFY_STATUS
Definition: acpi_drivers.h:87
int acpi_bus_receive_event(struct acpi_bus_event *event)
Definition: bus.c:513
struct _cl_event * event
Definition: glext.h:7739
GLuint64EXT * result
Definition: glext.h:11304
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132

Referenced by ACPIDispatchDeviceControl().

◆ DriverEntry()

NTSTATUS NTAPI DriverEntry ( PDRIVER_OBJECT  DriverObject,
PUNICODE_STRING  RegistryPath 
)

Definition at line 687 of file main.c.

691{
693 DPRINT("Driver Entry \n");
694
696 if (!NT_SUCCESS(Status))
697 {
699 return Status;
700 }
701
702 //
703 // Set entry points into the driver
704 //
706 DriverObject->MajorFunction [IRP_MJ_PNP] = Bus_PnP;
707 DriverObject->MajorFunction [IRP_MJ_POWER] = Bus_Power;
710
711 DriverObject->DriverExtension->AddDevice = Bus_AddDevice;
712
713 return STATUS_SUCCESS;
714}
NTSTATUS NTAPI Bus_Power(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: power.c:8
NTSTATUS NTAPI Bus_PnP(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: pnp.c:25
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
#define FALSE
Definition: types.h:117
NTSTATUS NTAPI Bus_AddDevice(PDRIVER_OBJECT DriverObject, PDEVICE_OBJECT PhysicalDeviceObject)
Definition: main.c:31
static NTSTATUS GetProcessorInformation(VOID)
Definition: main.c:453
NTSTATUS NTAPI ACPIDispatchDeviceControl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: main.c:227
NTSTATUS NTAPI ACPIDispatchCreateClose(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: main.c:179
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
#define IRP_MJ_POWER
#define NT_ASSERT
Definition: rtlfuncs.h:3310

◆ GetProcessorInformation()

static NTSTATUS GetProcessorInformation ( VOID  )
static

Definition at line 453 of file main.c.

454{
455 LPWSTR ProcessorIdentifier = NULL;
456 LPWSTR ProcessorVendorIdentifier = NULL;
457 LPWSTR HardwareIdsBuffer = NULL;
458 HANDLE ProcessorHandle = NULL;
459 ULONG Length = 0, Level1Length = 0, Level2Length = 0, Level3Length = 0;
460 SIZE_T HardwareIdsLength = 0;
461 SIZE_T VendorIdentifierLength;
462 ULONG i;
463 PWCHAR Ptr;
465
466 DPRINT("GetProcessorInformation()\n");
467
468 /* Open the key for CPU 0 */
470 L"\\Registry\\Machine\\Hardware\\Description\\System\\CentralProcessor\\0",
471 KEY_READ,
472 &ProcessorHandle);
473 if (!NT_SUCCESS(Status))
474 {
475 DPRINT1("Failed to open CentralProcessor registry key: 0x%lx\n", Status);
476 goto done;
477 }
478
479 /* Query the processor identifier length */
480 Status = AcpiRegQueryValue(ProcessorHandle,
481 L"Identifier",
482 NULL,
483 NULL,
484 &Length);
485 if (!NT_SUCCESS(Status))
486 {
487 DPRINT1("Failed to query Identifier value: 0x%lx\n", Status);
488 goto done;
489 }
490
491 /* Remember the length as fallback for level 1-3 length */
492 Level1Length = Level2Length = Level3Length = Length;
493
494 /* Allocate a buffer large enough to be zero terminated */
495 Length += sizeof(UNICODE_NULL);
496 ProcessorIdentifier = ExAllocatePoolWithTag(PagedPool, Length, 'IpcA');
497 if (ProcessorIdentifier == NULL)
498 {
499 DPRINT1("Failed to allocate 0x%lx bytes\n", Length);
501 goto done;
502 }
503
504 /* Query the processor identifier string */
505 Status = AcpiRegQueryValue(ProcessorHandle,
506 L"Identifier",
507 NULL,
508 ProcessorIdentifier,
509 &Length);
510 if (!NT_SUCCESS(Status))
511 {
512 DPRINT1("Failed to query Identifier value: 0x%lx\n", Status);
513 goto done;
514 }
515
516 /* Query the processor name length */
517 Length = 0;
518 Status = AcpiRegQueryValue(ProcessorHandle,
519 L"ProcessorNameString",
520 NULL,
521 NULL,
522 &Length);
523 if (NT_SUCCESS(Status))
524 {
525 /* Allocate a buffer large enough to be zero terminated */
526 Length += sizeof(UNICODE_NULL);
529 {
530 DPRINT1("Failed to allocate 0x%lx bytes\n", Length);
532 goto done;
533 }
534
535 /* Query the processor name string */
536 Status = AcpiRegQueryValue(ProcessorHandle,
537 L"ProcessorNameString",
538 NULL,
540 &Length);
541 if (!NT_SUCCESS(Status))
542 {
543 DPRINT1("Failed to query ProcessorNameString value: 0x%lx\n", Status);
544 goto done;
545 }
546 }
547
548 /* Query the vendor identifier length */
549 Length = 0;
550 Status = AcpiRegQueryValue(ProcessorHandle,
551 L"VendorIdentifier",
552 NULL,
553 NULL,
554 &Length);
555 if (!NT_SUCCESS(Status) || (Length == 0))
556 {
557 DPRINT1("Failed to query VendorIdentifier value: 0x%lx\n", Status);
558 goto done;
559 }
560
561 /* Allocate a buffer large enough to be zero terminated */
562 Length += sizeof(UNICODE_NULL);
563 ProcessorVendorIdentifier = ExAllocatePoolWithTag(PagedPool, Length, 'IpcA');
564 if (ProcessorVendorIdentifier == NULL)
565 {
566 DPRINT1("Failed to allocate 0x%lx bytes\n", Length);
568 goto done;
569 }
570
571 /* Query the vendor identifier string */
572 Status = AcpiRegQueryValue(ProcessorHandle,
573 L"VendorIdentifier",
574 NULL,
575 ProcessorVendorIdentifier,
576 &Length);
577 if (!NT_SUCCESS(Status))
578 {
579 DPRINT1("Failed to query VendorIdentifier value: 0x%lx\n", Status);
580 goto done;
581 }
582
583 /* Change spaces to underscores */
584 for (i = 0; i < wcslen(ProcessorIdentifier); i++)
585 {
586 if (ProcessorIdentifier[i] == L' ')
587 ProcessorIdentifier[i] = L'_';
588 }
589
590 Ptr = wcsstr(ProcessorIdentifier, L"Stepping");
591 if (Ptr != NULL)
592 {
593 Ptr--;
594 Level1Length = (ULONG)(Ptr - ProcessorIdentifier);
595 }
596
597 Ptr = wcsstr(ProcessorIdentifier, L"Model");
598 if (Ptr != NULL)
599 {
600 Ptr--;
601 Level2Length = (ULONG)(Ptr - ProcessorIdentifier);
602 }
603
604 Ptr = wcsstr(ProcessorIdentifier, L"Family");
605 if (Ptr != NULL)
606 {
607 Ptr--;
608 Level3Length = (ULONG)(Ptr - ProcessorIdentifier);
609 }
610
611 VendorIdentifierLength = (USHORT)wcslen(ProcessorVendorIdentifier);
612
613 /* Calculate the size of the full REG_MULTI_SZ data (see swprintf below) */
614 HardwareIdsLength = (5 + VendorIdentifierLength + 3 + Level1Length + 1 +
615 1 + VendorIdentifierLength + 3 + Level1Length + 1 +
616 5 + VendorIdentifierLength + 3 + Level2Length + 1 +
617 1 + VendorIdentifierLength + 3 + Level2Length + 1 +
618 5 + VendorIdentifierLength + 3 + Level3Length + 1 +
619 1 + VendorIdentifierLength + 3 + Level3Length + 1 +
620 1) * sizeof(WCHAR);
621
622 /* Allocate a buffer to the data */
623 HardwareIdsBuffer = ExAllocatePoolWithTag(PagedPool, HardwareIdsLength, 'IpcA');
624 if (HardwareIdsBuffer == NULL)
625 {
627 goto done;
628 }
629
630 Length = 0;
631 Length += swprintf(&HardwareIdsBuffer[Length], L"ACPI\\%s_-_%.*s", ProcessorVendorIdentifier, Level1Length, ProcessorIdentifier);
632 HardwareIdsBuffer[Length++] = UNICODE_NULL;
633
634 Length += swprintf(&HardwareIdsBuffer[Length], L"*%s_-_%.*s", ProcessorVendorIdentifier, Level1Length, ProcessorIdentifier);
635 HardwareIdsBuffer[Length++] = UNICODE_NULL;
636
637 Length += swprintf(&HardwareIdsBuffer[Length], L"ACPI\\%s_-_%.*s", ProcessorVendorIdentifier, Level2Length, ProcessorIdentifier);
638 HardwareIdsBuffer[Length++] = UNICODE_NULL;
639
640 Length += swprintf(&HardwareIdsBuffer[Length], L"*%s_-_%.*s", ProcessorVendorIdentifier, Level2Length, ProcessorIdentifier);
641 HardwareIdsBuffer[Length++] = UNICODE_NULL;
642
643 Length += swprintf(&HardwareIdsBuffer[Length], L"ACPI\\%s_-_%.*s", ProcessorVendorIdentifier, Level3Length, ProcessorIdentifier);
644 HardwareIdsBuffer[Length++] = UNICODE_NULL;
645
646 Length += swprintf(&HardwareIdsBuffer[Length], L"*%s_-_%.*s", ProcessorVendorIdentifier, Level3Length, ProcessorIdentifier);
647 HardwareIdsBuffer[Length++] = UNICODE_NULL;
648 HardwareIdsBuffer[Length++] = UNICODE_NULL;
649
650 /* Make sure we counted correctly */
651 NT_ASSERT(Length * sizeof(WCHAR) == HardwareIdsLength);
652
653 ProcessorHardwareIds.Length = (SHORT)HardwareIdsLength;
655 ProcessorHardwareIds.Buffer = HardwareIdsBuffer;
656
657 Length = (5 + VendorIdentifierLength + 3 + Level1Length + 1) * sizeof(WCHAR);
659 if (ProcessorIdString != NULL)
660 {
661 Length = swprintf(ProcessorIdString, L"ACPI\\%s_-_%.*s", ProcessorVendorIdentifier, Level1Length, ProcessorIdentifier);
663 DPRINT("ProcessorIdString: %S\n", ProcessorIdString);
664 }
665
666done:
667 if (ProcessorHandle != NULL)
668 ZwClose(ProcessorHandle);
669
670 if (ProcessorIdentifier != NULL)
671 ExFreePoolWithTag(ProcessorIdentifier, 'IpcA');
672
673 if (ProcessorVendorIdentifier != NULL)
674 ExFreePoolWithTag(ProcessorVendorIdentifier, 'IpcA');
675
676 if (!NT_SUCCESS(Status))
677 {
678 if (HardwareIdsBuffer != NULL)
679 ExFreePoolWithTag(HardwareIdsBuffer, 'IpcA');
680 }
681
682 return Status;
683}
#define swprintf
Definition: precomp.h:40
LPWSTR ProcessorIdString
Definition: main.c:25
static NTSTATUS AcpiRegQueryValue(IN HANDLE KeyHandle, IN LPWSTR ValueName, OUT PULONG Type OPTIONAL, OUT PVOID Data OPTIONAL, IN OUT PULONG DataLength OPTIONAL)
Definition: main.c:363
static NTSTATUS AcpiRegOpenKey(IN HANDLE ParentKeyHandle, IN LPCWSTR KeyName, IN ACCESS_MASK DesiredAccess, OUT HANDLE KeyHandle)
Definition: main.c:340
UNICODE_STRING ProcessorHardwareIds
Definition: main.c:24
LPWSTR ProcessorNameString
Definition: main.c:26
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define KEY_READ
Definition: nt_native.h:1023
#define UNICODE_NULL
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
short SHORT
Definition: pedump.c:59
unsigned short USHORT
Definition: pedump.c:61
USHORT MaximumLength
Definition: env_spec_w32.h:370
ULONG_PTR SIZE_T
Definition: typedefs.h:80
WCHAR * LPWSTR
Definition: xmlstorage.h:184

Referenced by DriverEntry().

Variable Documentation

◆ power_button

struct acpi_device* power_button
extern

Definition at line 55 of file button.c.

Referenced by acpi_button_add(), and ACPIDispatchDeviceControl().

◆ ProcessorHardwareIds

UNICODE_STRING ProcessorHardwareIds = {0, 0, NULL}

Definition at line 24 of file main.c.

Referenced by Bus_PDO_QueryDeviceId(), and GetProcessorInformation().

◆ ProcessorIdString

LPWSTR ProcessorIdString = NULL

Definition at line 25 of file main.c.

Referenced by Bus_PDO_QueryDeviceId(), and GetProcessorInformation().

◆ ProcessorNameString

LPWSTR ProcessorNameString = NULL

Definition at line 26 of file main.c.

Referenced by Bus_PDO_QueryDeviceText(), and GetProcessorInformation().

◆ sleep_button

struct acpi_device* sleep_button
extern

Definition at line 56 of file button.c.

Referenced by acpi_button_add(), and ACPIDispatchDeviceControl().