ReactOS 0.4.16-dev-106-g10b08aa
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 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)
 
NTSTATUS NTAPI DriverEntry (PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
 

Variables

DRIVER_INITIALIZE DriverEntry
 
DRIVER_ADD_DEVICE Bus_AddDevice
 
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 173 of file main.c.

176{
177 Irp->IoStatus.Status = STATUS_SUCCESS;
178 Irp->IoStatus.Information = 0;
179
181
182 return STATUS_SUCCESS;
183}
_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 221 of file main.c.

224{
225 PIO_STACK_LOCATION irpStack;
227 PCOMMON_DEVICE_DATA commonData;
228 ULONG Caps = 0;
229 HANDLE ThreadHandle;
230
233
234 commonData = (PCOMMON_DEVICE_DATA) DeviceObject->DeviceExtension;
235
236 Irp->IoStatus.Information = 0;
237
238 if (!commonData->IsFDO)
239 {
240 switch (irpStack->Parameters.DeviceIoControl.IoControlCode)
241 {
243 {
245
247 {
248 PEVAL_WORKITEM_DATA workItemData;
249
251 sizeof(*workItemData),
252 'ipcA');
253 if (!workItemData)
254 {
256 break;
257 }
258 workItemData->Irp = Irp;
259 workItemData->DeviceData = (PPDO_DEVICE_DATA)commonData;
260
261 ExInitializeWorkItem(&workItemData->WorkQueueItem,
263 workItemData);
265
267 break;
268 }
270 }
272 {
274 Irp);
275 break;
276 }
277
279 if (irpStack->Parameters.DeviceIoControl.OutputBufferLength < sizeof(ULONG))
280 {
282 break;
283 }
284
285 if (wcsstr(((PPDO_DEVICE_DATA)commonData)->HardwareIDs, L"PNP0C0D"))
286 {
287 DPRINT1("Lid button reported to power manager\n");
288 Caps |= SYS_BUTTON_LID;
289 }
290 else if (((PPDO_DEVICE_DATA)commonData)->AcpiHandle == NULL)
291 {
292 /* We have to return both at the same time because since we
293 * have a NULL handle we are the fixed feature DO and we will
294 * only be called once (not once per device)
295 */
296 if (power_button)
297 {
298 DPRINT("Fixed power button reported to power manager\n");
299 Caps |= SYS_BUTTON_POWER;
300 }
301 if (sleep_button)
302 {
303 DPRINT("Fixed sleep button reported to power manager\n");
304 Caps |= SYS_BUTTON_SLEEP;
305 }
306 }
307 else if (wcsstr(((PPDO_DEVICE_DATA)commonData)->HardwareIDs, L"PNP0C0C"))
308 {
309 DPRINT("Control method power button reported to power manager\n");
310 Caps |= SYS_BUTTON_POWER;
311 }
312 else if (wcsstr(((PPDO_DEVICE_DATA)commonData)->HardwareIDs, L"PNP0C0E"))
313 {
314 DPRINT("Control method sleep reported to power manager\n");
315 Caps |= SYS_BUTTON_SLEEP;
316 }
317 else
318 {
319 DPRINT1("IOCTL_GET_SYS_BUTTON_CAPS sent to a non-button device\n");
321 }
322
323 if (Caps != 0)
324 {
325 RtlCopyMemory(Irp->AssociatedIrp.SystemBuffer, &Caps, sizeof(Caps));
326 Irp->IoStatus.Information = sizeof(Caps);
328 }
329 break;
330
333 ZwClose(ThreadHandle);
334
336 break;
337
339 DPRINT("IOCTL_BATTERY_QUERY_TAG is not supported!\n");
340 break;
341
342 default:
343 DPRINT1("Unsupported IOCTL: %x\n", irpStack->Parameters.DeviceIoControl.IoControlCode);
344 break;
345 }
346 }
347 else
348 DPRINT1("IOCTL sent to the ACPI FDO! Kill the caller!\n");
349
350 if (status != STATUS_PENDING)
351 {
352 Irp->IoStatus.Status = status;
354 }
355 else
357
358 return status;
359}
#define ExAllocatePoolUninitialized
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
#define IOCTL_ACPI_ASYNC_EVAL_METHOD
Definition: acpiioct.h:177
#define IOCTL_ACPI_EVAL_METHOD
Definition: acpiioct.h:178
struct _COMMON_DEVICE_DATA * PCOMMON_DEVICE_DATA
WORKER_THREAD_ROUTINE Bus_PDO_EvalMethodWorker
Definition: acpisys.h:104
struct _PDO_DEVICE_DATA * PPDO_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(_In_ PPDO_DEVICE_DATA DeviceData, _Inout_ PIRP Irp)
Definition: eval.c:796
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:187
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
#define NonPagedPool
Definition: env_spec_w32.h:307
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
_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
#define __fallthrough
Definition: ms_sal.h:2886
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:84
#define SYS_BUTTON_POWER
Definition: poclass.h:83
#define IOCTL_GET_SYS_BUTTON_CAPS
Definition: poclass.h:59
#define IOCTL_GET_SYS_BUTTON_EVENT
Definition: poclass.h:62
#define SYS_BUTTON_LID
Definition: poclass.h:85
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
#define DPRINT
Definition: sndvol32.h:73
WORK_QUEUE_ITEM WorkQueueItem
Definition: acpisys.h:80
PPDO_DEVICE_DATA DeviceData
Definition: acpisys.h:78
struct _IO_STACK_LOCATION::@1575::@1576 DeviceIoControl
union _IO_STACK_LOCATION::@1575 Parameters
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
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
VOID NTAPI ExQueueWorkItem(IN PWORK_QUEUE_ITEM WorkItem, IN WORK_QUEUE_TYPE QueueType)
Definition: work.c:723
#define ExInitializeWorkItem(Item, Routine, Context)
Definition: exfuncs.h:265
@ DelayedWorkQueue
Definition: extypes.h:190

Referenced by DriverEntry().

◆ AcpiRegOpenKey()

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

Definition at line 364 of file main.c.

368{
371
373
375 &Name,
377 ParentKeyHandle,
378 NULL);
379
380 return ZwOpenKey(KeyHandle,
383}
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 388 of file main.c.

393{
398
400
401 if (DataLength != NULL)
403
404 /* Check if the caller provided a valid buffer */
405 if ((Data != NULL) && (BufferLength != 0))
406 {
408
409 /* Allocate memory for the value */
410 ValueInfo = ExAllocatePoolWithTag(PagedPool, BufferLength, 'MpcA');
411 if (ValueInfo == NULL)
412 return STATUS_NO_MEMORY;
413 }
414 else
415 {
416 /* Caller didn't provide a valid buffer, assume he wants the size only */
417 ValueInfo = NULL;
418 BufferLength = 0;
419 }
420
421 /* Query the value */
422 Status = ZwQueryValueKey(KeyHandle,
423 &Name,
425 ValueInfo,
427 &BufferLength);
428
429 if (DataLength != NULL)
431
432 /* Check if we have the size only */
433 if (ValueInfo == NULL)
434 {
435 /* Check for unexpected status */
438 {
439 return Status;
440 }
441
442 /* All is well */
444 }
445 /* Otherwise the caller wanted data back, check if we got it */
446 else if (NT_SUCCESS(Status))
447 {
448 if (Type != NULL)
449 *Type = ValueInfo->Type;
450
451 /* Copy it */
452 RtlMoveMemory(Data, ValueInfo->Data, ValueInfo->DataLength);
453
454 /* if the type is REG_SZ and data is not 0-terminated
455 * and there is enough space in the buffer NT appends a \0 */
456 if (((ValueInfo->Type == REG_SZ) ||
457 (ValueInfo->Type == REG_EXPAND_SZ) ||
458 (ValueInfo->Type == REG_MULTI_SZ)) &&
459 (ValueInfo->DataLength <= *DataLength - sizeof(WCHAR)))
460 {
461 WCHAR *ptr = (WCHAR *)((ULONG_PTR)Data + ValueInfo->DataLength);
462 if ((ptr > (WCHAR *)Data) && ptr[-1])
463 *ptr = 0;
464 }
465 }
466
467 /* Free the memory and return status */
468 if (ValueInfo != NULL)
469 {
470 ExFreePoolWithTag(ValueInfo, 'MpcA');
471 }
472
473 return Status;
474}
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:33
#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 25 of file main.c.

30{
33 PFDO_DEVICE_DATA deviceData = NULL;
34#ifndef NDEBUG
35 PWCHAR deviceName = NULL;
36 ULONG nameLength;
37#endif
38
39 PAGED_CODE ();
40
41 DPRINT("Add Device: 0x%p\n", PhysicalDeviceObject);
42
43 DPRINT("#################### Bus_CreateClose Creating FDO Device ####################\n");
45 sizeof(FDO_DEVICE_DATA),
46 NULL,
49 TRUE,
51 if (!NT_SUCCESS(status))
52 {
53 DPRINT1("IoCreateDevice() failed with status 0x%X\n", status);
54 goto End;
55 }
56
57 deviceData = (PFDO_DEVICE_DATA) deviceObject->DeviceExtension;
58 RtlZeroMemory (deviceData, sizeof (FDO_DEVICE_DATA));
59
60 //
61 // Set the initial state of the FDO
62 //
63
64 INITIALIZE_PNP_STATE(deviceData->Common);
65
66 deviceData->Common.IsFDO = TRUE;
67
68 deviceData->Common.Self = deviceObject;
69
70 ExInitializeFastMutex (&deviceData->Mutex);
71
72 InitializeListHead (&deviceData->ListOfPDOs);
73
74 // Set the PDO for use with PlugPlay functions
75
77
78 //
79 // Set the initial powerstate of the FDO
80 //
81
84
86
87 //
88 // Attach our FDO to the device stack.
89 // The return value of IoAttachDeviceToDeviceStack is the top of the
90 // attachment chain. This is where all the IRPs should be routed.
91 //
92
96
97 if (NULL == deviceData->NextLowerDriver) {
98
100 goto End;
101 }
102
103
104#ifndef NDEBUG
105 //
106 // We will demonstrate here the step to retrieve the name of the PDO
107 //
108
111 0,
112 NULL,
113 &nameLength);
114
116 {
117 DPRINT1("AddDevice:IoGDP failed (0x%x)\n", status);
118 goto End;
119 }
120
121 deviceName = ExAllocatePoolWithTag(NonPagedPool, nameLength, 'MpcA');
122
123 if (NULL == deviceName) {
124 DPRINT1("AddDevice: no memory to alloc for deviceName(0x%x)\n", nameLength);
126 goto End;
127 }
128
131 nameLength,
132 deviceName,
133 &nameLength);
134
135 if (!NT_SUCCESS (status)) {
136
137 DPRINT1("AddDevice:IoGDP(2) failed (0x%x)", status);
138 goto End;
139 }
140
141 DPRINT("AddDevice: %p to %p->%p (%ws) \n",
143 deviceData->NextLowerDriver,
145 deviceName);
146
147#endif
148
149 //
150 // We are done with initializing, so let's indicate that and return.
151 // This should be the final step in the AddDevice process.
152 //
153 deviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
154
155End:
156#ifndef NDEBUG
157 if (deviceName){
158 ExFreePoolWithTag(deviceName, 'MpcA');
159 }
160#endif
162 if (deviceData && deviceData->NextLowerDriver){
163 IoDetachDevice (deviceData->NextLowerDriver);
164 }
166 }
167 return status;
168
169}
#define PAGED_CODE()
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 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:95
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
_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

◆ ButtonWaitThread()

VOID NTAPI ButtonWaitThread ( PVOID  Context)

Definition at line 187 of file main.c.

188{
189 PIRP Irp = Context;
190 int result;
191 struct acpi_bus_event event;
192 ULONG ButtonEvent;
193
196
197 if (!ACPI_SUCCESS(result))
198 {
199 Irp->IoStatus.Status = STATUS_UNSUCCESSFUL;
200 }
201 else
202 {
203 if (strstr(event.bus_id, "PWRF"))
204 ButtonEvent = SYS_BUTTON_POWER;
205 else if (strstr(event.bus_id, "SLPF"))
206 ButtonEvent = SYS_BUTTON_SLEEP;
207 else
208 ButtonEvent = 0;
209
210 RtlCopyMemory(Irp->AssociatedIrp.SystemBuffer, &ButtonEvent, sizeof(ButtonEvent));
211 Irp->IoStatus.Status = STATUS_SUCCESS;
212 Irp->IoStatus.Information = sizeof(ULONG);
213 }
214
216}
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 714 of file main.c.

718{
720 DPRINT("Driver Entry \n");
721
723 if (!NT_SUCCESS(Status))
724 {
726 return Status;
727 }
728
729 //
730 // Set entry points into the driver
731 //
733 DriverObject->MajorFunction [IRP_MJ_PNP] = Bus_PnP;
734 DriverObject->MajorFunction [IRP_MJ_POWER] = Bus_Power;
737
738 DriverObject->DriverExtension->AddDevice = Bus_AddDevice;
739
740 return STATUS_SUCCESS;
741}
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
static NTSTATUS GetProcessorInformation(VOID)
Definition: main.c:479
NTSTATUS NTAPI ACPIDispatchDeviceControl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: main.c:221
DRIVER_ADD_DEVICE Bus_AddDevice
Definition: main.c:12
NTSTATUS NTAPI ACPIDispatchCreateClose(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: main.c:173
#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:3324

◆ GetProcessorInformation()

static NTSTATUS GetProcessorInformation ( VOID  )
static

Definition at line 479 of file main.c.

480{
481 LPWSTR ProcessorIdentifier = NULL;
482 LPWSTR ProcessorVendorIdentifier = NULL;
483 LPWSTR HardwareIdsBuffer = NULL;
484 HANDLE ProcessorHandle = NULL;
485 ULONG Length = 0, Level1Length = 0, Level2Length = 0, Level3Length = 0;
486 SIZE_T HardwareIdsLength = 0;
487 SIZE_T VendorIdentifierLength;
488 ULONG i;
489 PWCHAR Ptr;
491
492 DPRINT("GetProcessorInformation()\n");
493
494 /* Open the key for CPU 0 */
496 L"\\Registry\\Machine\\Hardware\\Description\\System\\CentralProcessor\\0",
497 KEY_READ,
498 &ProcessorHandle);
499 if (!NT_SUCCESS(Status))
500 {
501 DPRINT1("Failed to open CentralProcessor registry key: 0x%lx\n", Status);
502 goto done;
503 }
504
505 /* Query the processor identifier length */
506 Status = AcpiRegQueryValue(ProcessorHandle,
507 L"Identifier",
508 NULL,
509 NULL,
510 &Length);
511 if (!NT_SUCCESS(Status))
512 {
513 DPRINT1("Failed to query Identifier value: 0x%lx\n", Status);
514 goto done;
515 }
516
517 /* Remember the length as fallback for level 1-3 length */
518 Level1Length = Level2Length = Level3Length = Length;
519
520 /* Allocate a buffer large enough to be zero terminated */
521 Length += sizeof(UNICODE_NULL);
522 ProcessorIdentifier = ExAllocatePoolWithTag(PagedPool, Length, 'IpcA');
523 if (ProcessorIdentifier == NULL)
524 {
525 DPRINT1("Failed to allocate 0x%lx bytes\n", Length);
527 goto done;
528 }
529
530 /* Query the processor identifier string */
531 Status = AcpiRegQueryValue(ProcessorHandle,
532 L"Identifier",
533 NULL,
534 ProcessorIdentifier,
535 &Length);
536 if (!NT_SUCCESS(Status))
537 {
538 DPRINT1("Failed to query Identifier value: 0x%lx\n", Status);
539 goto done;
540 }
541
542 /* Query the processor name length */
543 Length = 0;
544 Status = AcpiRegQueryValue(ProcessorHandle,
545 L"ProcessorNameString",
546 NULL,
547 NULL,
548 &Length);
549 if (NT_SUCCESS(Status))
550 {
551 /* Allocate a buffer large enough to be zero terminated */
552 Length += sizeof(UNICODE_NULL);
555 {
556 DPRINT1("Failed to allocate 0x%lx bytes\n", Length);
558 goto done;
559 }
560
561 /* Query the processor name string */
562 Status = AcpiRegQueryValue(ProcessorHandle,
563 L"ProcessorNameString",
564 NULL,
566 &Length);
567 if (!NT_SUCCESS(Status))
568 {
569 DPRINT1("Failed to query ProcessorNameString value: 0x%lx\n", Status);
570 goto done;
571 }
572 }
573
574 /* Query the vendor identifier length */
575 Length = 0;
576 Status = AcpiRegQueryValue(ProcessorHandle,
577 L"VendorIdentifier",
578 NULL,
579 NULL,
580 &Length);
581 if (!NT_SUCCESS(Status) || (Length == 0))
582 {
583 DPRINT1("Failed to query VendorIdentifier value: 0x%lx\n", Status);
584 goto done;
585 }
586
587 /* Allocate a buffer large enough to be zero terminated */
588 Length += sizeof(UNICODE_NULL);
589 ProcessorVendorIdentifier = ExAllocatePoolWithTag(PagedPool, Length, 'IpcA');
590 if (ProcessorVendorIdentifier == NULL)
591 {
592 DPRINT1("Failed to allocate 0x%lx bytes\n", Length);
594 goto done;
595 }
596
597 /* Query the vendor identifier string */
598 Status = AcpiRegQueryValue(ProcessorHandle,
599 L"VendorIdentifier",
600 NULL,
601 ProcessorVendorIdentifier,
602 &Length);
603 if (!NT_SUCCESS(Status))
604 {
605 DPRINT1("Failed to query VendorIdentifier value: 0x%lx\n", Status);
606 goto done;
607 }
608
609 /* Change spaces to underscores */
610 for (i = 0; i < wcslen(ProcessorIdentifier); i++)
611 {
612 if (ProcessorIdentifier[i] == L' ')
613 ProcessorIdentifier[i] = L'_';
614 }
615
616 Ptr = wcsstr(ProcessorIdentifier, L"Stepping");
617 if (Ptr != NULL)
618 {
619 Ptr--;
620 Level1Length = (ULONG)(Ptr - ProcessorIdentifier);
621 }
622
623 Ptr = wcsstr(ProcessorIdentifier, L"Model");
624 if (Ptr != NULL)
625 {
626 Ptr--;
627 Level2Length = (ULONG)(Ptr - ProcessorIdentifier);
628 }
629
630 Ptr = wcsstr(ProcessorIdentifier, L"Family");
631 if (Ptr != NULL)
632 {
633 Ptr--;
634 Level3Length = (ULONG)(Ptr - ProcessorIdentifier);
635 }
636
637 VendorIdentifierLength = (USHORT)wcslen(ProcessorVendorIdentifier);
638
639 /* Calculate the size of the full REG_MULTI_SZ data (see swprintf below) */
640 HardwareIdsLength = (5 + VendorIdentifierLength + 3 + Level1Length + 1 +
641 1 + VendorIdentifierLength + 3 + Level1Length + 1 +
642 5 + VendorIdentifierLength + 3 + Level2Length + 1 +
643 1 + VendorIdentifierLength + 3 + Level2Length + 1 +
644 5 + VendorIdentifierLength + 3 + Level3Length + 1 +
645 1 + VendorIdentifierLength + 3 + Level3Length + 1 +
646 1) * sizeof(WCHAR);
647
648 /* Allocate a buffer to the data */
649 HardwareIdsBuffer = ExAllocatePoolWithTag(PagedPool, HardwareIdsLength, 'IpcA');
650 if (HardwareIdsBuffer == NULL)
651 {
653 goto done;
654 }
655
656 Length = 0;
657 Length += swprintf(&HardwareIdsBuffer[Length], L"ACPI\\%s_-_%.*s", ProcessorVendorIdentifier, Level1Length, ProcessorIdentifier);
658 HardwareIdsBuffer[Length++] = UNICODE_NULL;
659
660 Length += swprintf(&HardwareIdsBuffer[Length], L"*%s_-_%.*s", ProcessorVendorIdentifier, Level1Length, ProcessorIdentifier);
661 HardwareIdsBuffer[Length++] = UNICODE_NULL;
662
663 Length += swprintf(&HardwareIdsBuffer[Length], L"ACPI\\%s_-_%.*s", ProcessorVendorIdentifier, Level2Length, ProcessorIdentifier);
664 HardwareIdsBuffer[Length++] = UNICODE_NULL;
665
666 Length += swprintf(&HardwareIdsBuffer[Length], L"*%s_-_%.*s", ProcessorVendorIdentifier, Level2Length, ProcessorIdentifier);
667 HardwareIdsBuffer[Length++] = UNICODE_NULL;
668
669 Length += swprintf(&HardwareIdsBuffer[Length], L"ACPI\\%s_-_%.*s", ProcessorVendorIdentifier, Level3Length, ProcessorIdentifier);
670 HardwareIdsBuffer[Length++] = UNICODE_NULL;
671
672 Length += swprintf(&HardwareIdsBuffer[Length], L"*%s_-_%.*s", ProcessorVendorIdentifier, Level3Length, ProcessorIdentifier);
673 HardwareIdsBuffer[Length++] = UNICODE_NULL;
674 HardwareIdsBuffer[Length++] = UNICODE_NULL;
675
676 /* Make sure we counted correctly */
677 NT_ASSERT(Length * sizeof(WCHAR) == HardwareIdsLength);
678
679 ProcessorHardwareIds.Length = (SHORT)HardwareIdsLength;
681 ProcessorHardwareIds.Buffer = HardwareIdsBuffer;
682
683 Length = (5 + VendorIdentifierLength + 3 + Level1Length + 1) * sizeof(WCHAR);
685 if (ProcessorIdString != NULL)
686 {
687 Length = swprintf(ProcessorIdString, L"ACPI\\%s_-_%.*s", ProcessorVendorIdentifier, Level1Length, ProcessorIdentifier);
689 DPRINT("ProcessorIdString: %S\n", ProcessorIdString);
690 }
691
692done:
693 if (ProcessorHandle != NULL)
694 ZwClose(ProcessorHandle);
695
696 if (ProcessorIdentifier != NULL)
697 ExFreePoolWithTag(ProcessorIdentifier, 'IpcA');
698
699 if (ProcessorVendorIdentifier != NULL)
700 ExFreePoolWithTag(ProcessorVendorIdentifier, 'IpcA');
701
702 if (!NT_SUCCESS(Status))
703 {
704 if (HardwareIdsBuffer != NULL)
705 ExFreePoolWithTag(HardwareIdsBuffer, 'IpcA');
706 }
707
708 return Status;
709}
#define swprintf
Definition: precomp.h:40
LPWSTR ProcessorIdString
Definition: main.c:18
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:388
static NTSTATUS AcpiRegOpenKey(IN HANDLE ParentKeyHandle, IN LPCWSTR KeyName, IN ACCESS_MASK DesiredAccess, OUT HANDLE KeyHandle)
Definition: main.c:364
UNICODE_STRING ProcessorHardwareIds
Definition: main.c:17
LPWSTR ProcessorNameString
Definition: main.c:19
_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

◆ Bus_AddDevice

DRIVER_ADD_DEVICE Bus_AddDevice

Definition at line 12 of file main.c.

Referenced by DriverEntry().

◆ DriverEntry

DRIVER_INITIALIZE DriverEntry

Definition at line 9 of file main.c.

Referenced by DriverEntry().

◆ 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 17 of file main.c.

Referenced by Bus_PDO_QueryDeviceId(), and GetProcessorInformation().

◆ ProcessorIdString

LPWSTR ProcessorIdString = NULL

Definition at line 18 of file main.c.

Referenced by Bus_PDO_QueryDeviceId(), and GetProcessorInformation().

◆ ProcessorNameString

LPWSTR ProcessorNameString = NULL

Definition at line 19 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().