ReactOS 0.4.15-dev-5672-gf73ac17
eval.c
Go to the documentation of this file.
1#include "precomp.h"
2
3#define NDEBUG
4#include <debug.h>
5
6static
11{
12 ULONG Length, RawLength, TotalLength;
13 UINT32 i;
14
15 TotalLength = 0;
16 for (i = 0; i < Package->Package.Count; i++)
17 {
18 switch (Package->Package.Elements[i].Type)
19 {
22 DPRINT("Integer %lu -> %lu: %lu\n", sizeof(ULONG), Length, Package->Package.Elements[i].Integer.Value);
24 break;
25
27 RawLength = Package->Package.Elements[i].String.Length + 1;
29 if (RawLength > sizeof(ULONG))
30 Length += RawLength - sizeof(ULONG);
31 DPRINT("String %lu -> %lu: '%s'\n", RawLength, Length, Package->Package.Elements[i].String.Pointer);
33 break;
34
35 default:
36 DPRINT1("Unsupported element type %lu\n", Package->Package.Elements[i].Type);
38 }
39 }
40
41 *Count = Package->Package.Count;
43
44 return STATUS_SUCCESS;
45}
46
47
48static
51 ACPI_OBJECT *Package)
52{
54 UINT32 i;
55
56 Ptr = Argument;
57 for (i = 0; i < Package->Package.Count; i++)
58 {
59 switch (Package->Package.Elements[i].Type)
60 {
62 DPRINT("Integer %lu\n", sizeof(ACPI_METHOD_ARGUMENT));
63 ACPI_METHOD_SET_ARGUMENT_INTEGER(Ptr, Package->Package.Elements[i].Integer.Value);
64 break;
65
67 DPRINT("String %lu\n", Package->Package.Elements[i].String.Length);
68 ACPI_METHOD_SET_ARGUMENT_STRING(Ptr, Package->Package.Elements[i].String.Pointer);
69 break;
70
71 default:
72 DPRINT1("Unsupported element type %lu\n", Package->Package.Elements[i].Type);
74 }
75
77 }
78
79 return STATUS_SUCCESS;
80}
81
82
86 PIRP Irp)
87{
90 ACPI_OBJECT_LIST ParamList;
91 PACPI_EVAL_INPUT_BUFFER EvalInputBuff = Irp->AssociatedIrp.SystemBuffer;
97 CHAR MethodName[5];
98
99 if (IrpSp->Parameters.DeviceIoControl.InputBufferLength < sizeof(ULONG))
101
102 Signature = *((PULONG)Irp->AssociatedIrp.SystemBuffer);
103
104 switch (Signature)
105 {
107 if (IrpSp->Parameters.DeviceIoControl.InputBufferLength < sizeof(ACPI_EVAL_INPUT_BUFFER))
109
110 ParamList.Count = 0;
111 break;
112
114 SimpleInt = Irp->AssociatedIrp.SystemBuffer;
115
116 if (IrpSp->Parameters.DeviceIoControl.InputBufferLength < sizeof(ACPI_EVAL_INPUT_BUFFER_SIMPLE_INTEGER))
118
119 ParamList.Count = 1;
120
121 ParamList.Pointer = ExAllocatePoolWithTag(NonPagedPool, sizeof(ACPI_OBJECT), 'OpcA');
122 if (!ParamList.Pointer) return STATUS_INSUFFICIENT_RESOURCES;
123
124 ParamList.Pointer[0].Type = ACPI_TYPE_INTEGER;
125 ParamList.Pointer[0].Integer.Value = SimpleInt->IntegerArgument;
126 break;
127
129 SimpleStr = Irp->AssociatedIrp.SystemBuffer;
130
131 if (IrpSp->Parameters.DeviceIoControl.InputBufferLength < sizeof(ACPI_EVAL_INPUT_BUFFER_SIMPLE_STRING))
133
134 ParamList.Count = 1;
135
136 ParamList.Pointer = ExAllocatePoolWithTag(NonPagedPool, sizeof(ACPI_OBJECT), 'OpcA');
137 if (!ParamList.Pointer) return STATUS_INSUFFICIENT_RESOURCES;
138
139 ParamList.Pointer[0].String.Pointer = (CHAR*)SimpleStr->String;
140 ParamList.Pointer[0].String.Length = SimpleStr->StringLength;
141 break;
142
143 default:
144 DPRINT1("Unsupported input buffer signature: %d\n", Signature);
146 }
147
148 RtlCopyMemory(MethodName,
149 EvalInputBuff->MethodName,
150 sizeof(EvalInputBuff->MethodName));
151 MethodName[4] = ANSI_NULL;
153 MethodName,
154 &ParamList,
155 &RetBuff);
156
157 if (ParamList.Count != 0)
158 ExFreePoolWithTag(ParamList.Pointer, 'OpcA');
159
160 if (ACPI_SUCCESS(Status))
161 {
162 ACPI_OBJECT *Obj = RetBuff.Pointer;
163 ULONG ExtraParamLength = 0;
164 ULONG Count = 1;
165
166 /* If we didn't get anything back then we're done */
167 if (!RetBuff.Pointer || RetBuff.Length == 0)
168 return STATUS_SUCCESS;
169
170 switch (Obj->Type)
171 {
173 ExtraParamLength = sizeof(ACPI_METHOD_ARGUMENT);
174 break;
175
176 case ACPI_TYPE_STRING:
177 ExtraParamLength = sizeof(ACPI_METHOD_ARGUMENT);
178 if (Obj->String.Length + 1 > sizeof(ULONG))
179 ExtraParamLength += Obj->String.Length + 1 - sizeof(ULONG);
180 break;
181
182 case ACPI_TYPE_BUFFER:
183 ExtraParamLength = sizeof(ACPI_METHOD_ARGUMENT);
184 if (Obj->Buffer.Length > sizeof(ULONG))
185 ExtraParamLength += Obj->Buffer.Length + 1 - sizeof(ULONG);
186 break;
187
189 Status = GetPackageSize(Obj, &Count, &ExtraParamLength);
190 if (!NT_SUCCESS(Status))
191 return Status;
192 break;
193
194 default:
195 ASSERT(FALSE);
196 return STATUS_UNSUCCESSFUL;
197 }
198
199 DPRINT("ExtraParamLength %lu\n", ExtraParamLength);
201 sizeof(ACPI_EVAL_OUTPUT_BUFFER) - sizeof(ACPI_METHOD_ARGUMENT) + ExtraParamLength,
202 'BpcA');
203 if (!OutputBuf)
205
206 OutputBuf->Signature = ACPI_EVAL_OUTPUT_BUFFER_SIGNATURE;
207 OutputBuf->Length = ExtraParamLength;
208 OutputBuf->Count = Count;
209
210 switch (Obj->Type)
211 {
213 ACPI_METHOD_SET_ARGUMENT_INTEGER(OutputBuf->Argument, Obj->Integer.Value);
214 break;
215
216 case ACPI_TYPE_STRING:
217 ACPI_METHOD_SET_ARGUMENT_STRING(OutputBuf->Argument, Obj->String.Pointer);
218 break;
219
220 case ACPI_TYPE_BUFFER:
221 ACPI_METHOD_SET_ARGUMENT_BUFFER(OutputBuf->Argument, Obj->Buffer.Pointer, Obj->Buffer.Length);
222 break;
223
225 Status = ConvertPackageArguments(OutputBuf->Argument, Obj);
226 if (!NT_SUCCESS(Status))
227 return Status;
228 break;
229
230 default:
231 ASSERT(FALSE);
232 return STATUS_UNSUCCESSFUL;
233 }
234
235 if (IrpSp->Parameters.DeviceIoControl.OutputBufferLength >= sizeof(ACPI_EVAL_OUTPUT_BUFFER) - sizeof(ACPI_METHOD_ARGUMENT) +
236 ExtraParamLength)
237 {
238 RtlCopyMemory(Irp->AssociatedIrp.SystemBuffer, OutputBuf, sizeof(ACPI_EVAL_OUTPUT_BUFFER) - sizeof(ACPI_METHOD_ARGUMENT) +
239 ExtraParamLength);
240 Irp->IoStatus.Information = sizeof(ACPI_EVAL_OUTPUT_BUFFER) - sizeof(ACPI_METHOD_ARGUMENT) + ExtraParamLength;
241 ExFreePoolWithTag(OutputBuf, 'BpcA');
242 return STATUS_SUCCESS;
243 }
244 else
245 {
246 ExFreePoolWithTag(OutputBuf, 'BpcA');
248 }
249 }
250 else
251 {
252 DPRINT1("Query method %4s failed on %p\n", EvalInputBuff->MethodName, DeviceData->AcpiHandle);
253 return STATUS_UNSUCCESSFUL;
254 }
255}
unsigned int UINT32
#define ACPI_SUCCESS(a)
Definition: acexcep.h:94
struct _ACPI_EVAL_OUTPUT_BUFFER ACPI_EVAL_OUTPUT_BUFFER
#define ACPI_METHOD_NEXT_ARGUMENT(Argument)
Definition: acpiioct.h:150
#define ACPI_EVAL_INPUT_BUFFER_SIMPLE_INTEGER_SIGNATURE
Definition: acpiioct.h:8
#define ACPI_EVAL_INPUT_BUFFER_SIGNATURE
Definition: acpiioct.h:7
#define ACPI_METHOD_SET_ARGUMENT_INTEGER(MethodArgument, IntData)
Definition: acpiioct.h:155
#define ACPI_METHOD_SET_ARGUMENT_STRING(Argument, StrData)
Definition: acpiioct.h:160
#define ACPI_EVAL_INPUT_BUFFER_SIMPLE_STRING_SIGNATURE
Definition: acpiioct.h:9
#define ACPI_EVAL_OUTPUT_BUFFER_SIGNATURE
Definition: acpiioct.h:11
#define ACPI_METHOD_SET_ARGUMENT_BUFFER(Argument, BuffData, BuffLength)
Definition: acpiioct.h:165
struct _ACPI_METHOD_ARGUMENT ACPI_METHOD_ARGUMENT
ACPI_EVAL_OUTPUT_BUFFER UNALIGNED * PACPI_EVAL_OUTPUT_BUFFER
Definition: acpiioct.h:90
#define ACPI_TYPE_STRING
Definition: actypes.h:689
#define ACPI_ALLOCATE_BUFFER
Definition: actypes.h:1046
#define ACPI_TYPE_BUFFER
Definition: actypes.h:690
#define ACPI_TYPE_INTEGER
Definition: actypes.h:688
#define ACPI_TYPE_PACKAGE
Definition: actypes.h:691
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
_In_ PIRP Irp
Definition: csq.h:116
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static const WCHAR Signature[]
Definition: parser.c:141
static NTSTATUS ConvertPackageArguments(ACPI_METHOD_ARGUMENT *Argument, ACPI_OBJECT *Package)
Definition: eval.c:50
NTSTATUS NTAPI Bus_PDO_EvalMethod(PPDO_DEVICE_DATA DeviceData, PIRP Irp)
Definition: eval.c:85
static NTSTATUS GetPackageSize(ACPI_OBJECT *Package, PULONG Count, PULONG Size)
Definition: eval.c:8
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4137
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define NonPagedPool
Definition: env_spec_w32.h:307
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898
Status
Definition: gdiplustypes.h:25
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
#define ASSERT(a)
Definition: mode.c:44
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
int Count
Definition: noreturn.cpp:7
ACPI_STATUS AcpiEvaluateObject(ACPI_HANDLE Handle, ACPI_STRING Pathname, ACPI_OBJECT_LIST *ExternalParams, ACPI_BUFFER *ReturnBuffer)
Definition: nsxfeval.c:217
#define ANSI_NULL
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:239
#define STATUS_SUCCESS
Definition: shellext.h:65
#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
void * Pointer
Definition: actypes.h:1054
ACPI_SIZE Length
Definition: actypes.h:1053
ACPI_OBJECT * Pointer
Definition: actypes.h:1029
uint32_t * PULONG
Definition: typedefs.h:59
#define NTAPI
Definition: typedefs.h:36
#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_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
ACPI_OBJECT_TYPE Type
Definition: actypes.h:970
struct acpi_object::@603 Package
struct acpi_object::@600 Integer
struct acpi_object::@601 String
_In_ ULONG TotalLength
Definition: usbdlib.h:158
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2793
char CHAR
Definition: xmlstorage.h:175