[ACPI] Fix object evaluation (#6302)

CORE-17256

- Implement support for complex input buffers.
  This will enable the IDE driver with some hack
  to execute the _STM (channel timing settings) control method.
- Fix a memory leak.
- Fix returned status code.
- Correctly calculate the output buffer size.
- Improve buffer validation.
- Implement support for async control requests.
- Implement local reference conversion.
- Implement support for subpackage argument conversion.
- Place some code into INIT section.
This commit is contained in:
Dmitry Borisov 2024-04-01 21:21:35 +05:00 committed by GitHub
parent 1538712c0b
commit 5070e8960a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 2217 additions and 226 deletions

File diff suppressed because it is too large Load diff

View file

@ -73,6 +73,13 @@ typedef struct _FDO_DEVICE_DATA
} FDO_DEVICE_DATA, *PFDO_DEVICE_DATA; } FDO_DEVICE_DATA, *PFDO_DEVICE_DATA;
typedef struct _EVAL_WORKITEM_DATA
{
PPDO_DEVICE_DATA DeviceData;
PIRP Irp;
WORK_QUEUE_ITEM WorkQueueItem;
} EVAL_WORKITEM_DATA, *PEVAL_WORKITEM_DATA;
#define FDO_FROM_PDO(pdoData) \ #define FDO_FROM_PDO(pdoData) \
((PFDO_DEVICE_DATA) (pdoData)->ParentFdo->DeviceExtension) ((PFDO_DEVICE_DATA) (pdoData)->ParentFdo->DeviceExtension)
@ -93,10 +100,15 @@ NTSTATUS
ACPIEnumerateDevices( ACPIEnumerateDevices(
PFDO_DEVICE_DATA DeviceExtension); PFDO_DEVICE_DATA DeviceExtension);
CODE_SEG("PAGE")
WORKER_THREAD_ROUTINE Bus_PDO_EvalMethodWorker;
CODE_SEG("PAGE")
NTSTATUS NTSTATUS
NTAPI NTAPI
Bus_PDO_EvalMethod(PPDO_DEVICE_DATA DeviceData, Bus_PDO_EvalMethod(
PIRP Irp); _In_ PPDO_DEVICE_DATA DeviceData,
_Inout_ PIRP Irp);
NTSTATUS NTSTATUS
NTAPI NTAPI
@ -115,13 +127,6 @@ PnPMinorFunctionString (
UCHAR MinorFunction UCHAR MinorFunction
); );
NTSTATUS
NTAPI
Bus_AddDevice(
PDRIVER_OBJECT DriverObject,
PDEVICE_OBJECT PhysicalDeviceObject
);
NTSTATUS NTSTATUS
Bus_SendIrpSynchronously ( Bus_SendIrpSynchronously (
PDEVICE_OBJECT DeviceObject, PDEVICE_OBJECT DeviceObject,

View file

@ -5,18 +5,11 @@
#define NDEBUG #define NDEBUG
#include <debug.h> #include <debug.h>
NTSTATUS CODE_SEG("INIT")
NTAPI DRIVER_INITIALIZE DriverEntry;
DriverEntry (
PDRIVER_OBJECT DriverObject,
PUNICODE_STRING RegistryPath
);
#ifdef ALLOC_PRAGMA CODE_SEG("PAGE")
#pragma alloc_text (INIT, DriverEntry) DRIVER_ADD_DEVICE Bus_AddDevice;
#pragma alloc_text (PAGE, Bus_AddDevice)
#endif
extern struct acpi_device *sleep_button; extern struct acpi_device *sleep_button;
extern struct acpi_device *power_button; extern struct acpi_device *power_button;
@ -26,6 +19,7 @@ LPWSTR ProcessorIdString = NULL;
LPWSTR ProcessorNameString = NULL; LPWSTR ProcessorNameString = NULL;
CODE_SEG("PAGE")
NTSTATUS NTSTATUS
NTAPI NTAPI
Bus_AddDevice( Bus_AddDevice(
@ -234,8 +228,6 @@ ACPIDispatchDeviceControl(
ULONG Caps = 0; ULONG Caps = 0;
HANDLE ThreadHandle; HANDLE ThreadHandle;
PAGED_CODE ();
irpStack = IoGetCurrentIrpStackLocation (Irp); irpStack = IoGetCurrentIrpStackLocation (Irp);
ASSERT (IRP_MJ_DEVICE_CONTROL == irpStack->MajorFunction); ASSERT (IRP_MJ_DEVICE_CONTROL == irpStack->MajorFunction);
@ -247,10 +239,41 @@ ACPIDispatchDeviceControl(
{ {
switch (irpStack->Parameters.DeviceIoControl.IoControlCode) switch (irpStack->Parameters.DeviceIoControl.IoControlCode)
{ {
case IOCTL_ACPI_ASYNC_EVAL_METHOD:
{
ASSERT(KeGetCurrentIrql() <= DISPATCH_LEVEL);
if (KeGetCurrentIrql() == DISPATCH_LEVEL)
{
PEVAL_WORKITEM_DATA workItemData;
workItemData = ExAllocatePoolUninitialized(NonPagedPool,
sizeof(*workItemData),
'ipcA');
if (!workItemData)
{
status = STATUS_INSUFFICIENT_RESOURCES;
break;
}
workItemData->Irp = Irp;
workItemData->DeviceData = (PPDO_DEVICE_DATA)commonData;
ExInitializeWorkItem(&workItemData->WorkQueueItem,
Bus_PDO_EvalMethodWorker,
workItemData);
ExQueueWorkItem(&workItemData->WorkQueueItem, DelayedWorkQueue);
status = STATUS_PENDING;
break;
}
__fallthrough;
}
case IOCTL_ACPI_EVAL_METHOD: case IOCTL_ACPI_EVAL_METHOD:
{
status = Bus_PDO_EvalMethod((PPDO_DEVICE_DATA)commonData, status = Bus_PDO_EvalMethod((PPDO_DEVICE_DATA)commonData,
Irp); Irp);
break; break;
}
case IOCTL_GET_SYS_BUTTON_CAPS: case IOCTL_GET_SYS_BUTTON_CAPS:
if (irpStack->Parameters.DeviceIoControl.OutputBufferLength < sizeof(ULONG)) if (irpStack->Parameters.DeviceIoControl.OutputBufferLength < sizeof(ULONG))
@ -336,6 +359,7 @@ ACPIDispatchDeviceControl(
} }
static static
CODE_SEG("INIT")
NTSTATUS NTSTATUS
AcpiRegOpenKey(IN HANDLE ParentKeyHandle, AcpiRegOpenKey(IN HANDLE ParentKeyHandle,
IN LPCWSTR KeyName, IN LPCWSTR KeyName,
@ -359,6 +383,7 @@ AcpiRegOpenKey(IN HANDLE ParentKeyHandle,
} }
static static
CODE_SEG("INIT")
NTSTATUS NTSTATUS
AcpiRegQueryValue(IN HANDLE KeyHandle, AcpiRegQueryValue(IN HANDLE KeyHandle,
IN LPWSTR ValueName, IN LPWSTR ValueName,
@ -449,6 +474,7 @@ AcpiRegQueryValue(IN HANDLE KeyHandle,
} }
static static
CODE_SEG("INIT")
NTSTATUS NTSTATUS
GetProcessorInformation(VOID) GetProcessorInformation(VOID)
{ {
@ -682,6 +708,7 @@ done:
return Status; return Status;
} }
CODE_SEG("INIT")
NTSTATUS NTSTATUS
NTAPI NTAPI
DriverEntry ( DriverEntry (

View file

@ -15,5 +15,6 @@
#include <glue.h> #include <glue.h>
#include <wdmguid.h> #include <wdmguid.h>
#include <acpiioct.h> #include <acpiioct.h>
#include <ntintsafe.h>
#endif /* _ACPI_PCH_ */ #endif /* _ACPI_PCH_ */

File diff suppressed because it is too large Load diff

View file

@ -2,6 +2,7 @@
include_directories(${REACTOS_SOURCE_DIR}/drivers/bus/acpi/acpica/include) include_directories(${REACTOS_SOURCE_DIR}/drivers/bus/acpi/acpica/include)
list(APPEND SOURCE list(APPEND SOURCE
Bus_PDO_EvalMethod.c
Bus_PDO_QueryResourceRequirements.c Bus_PDO_QueryResourceRequirements.c
testlist.c) testlist.c)

View file

@ -1,10 +1,12 @@
#define STANDALONE #define STANDALONE
#include <apitest.h> #include <apitest.h>
extern void func_Bus_PDO_EvalMethod(void);
extern void func_Bus_PDO_QueryResourceRequirements(void); extern void func_Bus_PDO_QueryResourceRequirements(void);
const struct test winetest_testlist[] = const struct test winetest_testlist[] =
{ {
{ "Bus_PDO_EvalMethod", func_Bus_PDO_EvalMethod },
{ "Bus_PDO_QueryResourceRequirements", func_Bus_PDO_QueryResourceRequirements }, { "Bus_PDO_QueryResourceRequirements", func_Bus_PDO_QueryResourceRequirements },
{ 0, 0 } { 0, 0 }
}; };