2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Kernel Streaming
4 * FILE: drivers/ksfilter/ks/allocators.c
5 * PURPOSE: KS Allocator functions
6 * PROGRAMMER: Johannes Anderwald
19 IN POOL_TYPE PoolType
,
20 IN ULONG_PTR ResourceName
,
21 IN ULONG ResourceType
,
23 OUT PULONG ResourceSize
)
26 LDR_RESOURCE_INFO ResourceInfo
;
27 PIMAGE_RESOURCE_DATA_ENTRY ResourceDataEntry
;
30 PVOID _SEH2_VOLATILE Result
= NULL
;
32 /* set up resource info */
33 ResourceInfo
.Type
= ResourceType
;
34 ResourceInfo
.Name
= ResourceName
;
35 ResourceInfo
.Language
= 0;
39 /* find the resource */
40 Status
= LdrFindResource_U(ImageBase
, &ResourceInfo
, RESOURCE_DATA_LEVEL
, &ResourceDataEntry
);
41 if (NT_SUCCESS(Status
))
43 /* try accessing it */
44 Status
= LdrAccessResource(ImageBase
, ResourceDataEntry
, &Data
, &Size
);
45 if (NT_SUCCESS(Status
))
47 /* allocate resource buffer */
48 Result
= AllocateItem(PoolType
, Size
);
52 RtlMoveMemory(Result
, Data
, Size
);
58 /* resource size is optional */
64 /* not enough memory */
65 Status
= STATUS_INSUFFICIENT_RESOURCES
;
70 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
72 /* Exception, get the error code */
73 Status
= _SEH2_GetExceptionCode();
77 if (!NT_SUCCESS(Status
))
82 /* free resource buffer in case of a failure */
96 IN OUT PULONG BufferLength
,
100 return STATUS_NOT_IMPLEMENTED
;
109 KsGetImageNameAndResourceId(
111 OUT PUNICODE_STRING ImageName
,
112 OUT PULONG_PTR ResourceId
,
113 OUT PULONG ValueType
)
117 WCHAR ImagePath
[] = {L
"\\SystemRoot\\system32\\drivers\\"};
119 /* first clear the provided ImageName */
120 ImageName
->Buffer
= NULL
;
121 ImageName
->Length
= ImageName
->MaximumLength
= 0;
124 /* retrieve length of image name */
125 Status
= KspQueryRegValue(RegKey
, L
"Image", NULL
, &ImageLength
, NULL
);
127 if (Status
!= STATUS_BUFFER_OVERFLOW
)
129 /* key value doesnt exist */
133 /* allocate image name buffer */
134 ImageName
->MaximumLength
= (USHORT
)(sizeof(ImagePath
) + ImageLength
);
135 ImageName
->Buffer
= AllocateItem(PagedPool
, ImageName
->MaximumLength
);
137 /* check for success */
138 if (!ImageName
->Buffer
)
140 /* insufficient memory */
141 return STATUS_INSUFFICIENT_RESOURCES
;
144 /* copy image name */
145 RtlCopyMemory(ImageName
->Buffer
, ImagePath
, sizeof(ImagePath
));
147 /* retrieve image name */
148 Status
= KspQueryRegValue(RegKey
,
150 &ImageName
->Buffer
[sizeof(ImagePath
) / sizeof(WCHAR
)],
154 if (!NT_SUCCESS(Status
))
156 /* unexpected error */
157 FreeItem(ImageName
->Buffer
);
161 /* now query for resource id length*/
163 Status
= KspQueryRegValue(RegKey
, L
"ResourceId", NULL
, &ImageLength
, ValueType
);
165 /* allocate resource id buffer*/
166 *ResourceId
= (ULONG_PTR
)AllocateItem(PagedPool
, ImageLength
);
168 /* check for success */
171 /* insufficient memory */
172 FreeItem(ImageName
->Buffer
);
173 return STATUS_INSUFFICIENT_RESOURCES
;
175 /* now query for resource id */
176 Status
= KspQueryRegValue(RegKey
, L
"ResourceId", (PVOID
)*ResourceId
, &ImageLength
, ValueType
);
178 if (!NT_SUCCESS(Status
))
180 /* unexpected error */
181 FreeItem(ImageName
->Buffer
);
182 FreeItem((PVOID
)*ResourceId
);
196 IN PDEVICE_OBJECT PhysicalDeviceObject
,
197 IN PUNICODE_STRING ModuleName
,
198 OUT PUNICODE_STRING ImageName
,
199 OUT PULONG_PTR ResourceId
,
200 OUT PULONG ValueType
)
203 UNICODE_STRING SubKeyName
;
204 UNICODE_STRING Modules
= RTL_CONSTANT_STRING(L
"Modules\\");
205 HANDLE hKey
, hSubKey
;
206 OBJECT_ATTRIBUTES ObjectAttributes
;
208 /* first open device key */
209 Status
= IoOpenDeviceRegistryKey(PhysicalDeviceObject
, PLUGPLAY_REGKEY_DEVICE
, GENERIC_READ
, &hKey
);
211 /* check for success */
212 if (!NT_SUCCESS(Status
))
214 /* invalid parameter */
215 return STATUS_INVALID_PARAMETER
;
218 /* initialize subkey buffer */
219 SubKeyName
.Length
= 0;
220 SubKeyName
.MaximumLength
= Modules
.MaximumLength
+ ModuleName
->MaximumLength
;
221 SubKeyName
.Buffer
= AllocateItem(PagedPool
, SubKeyName
.MaximumLength
);
223 /* check for success */
224 if (!SubKeyName
.Buffer
)
226 /* not enough memory */
228 return STATUS_NO_MEMORY
;
231 /* build subkey string */
232 RtlAppendUnicodeStringToString(&SubKeyName
, &Modules
);
233 RtlAppendUnicodeStringToString(&SubKeyName
, ModuleName
);
235 /* initialize subkey attributes */
236 InitializeObjectAttributes(&ObjectAttributes
, &SubKeyName
, OBJ_CASE_INSENSITIVE
, hKey
, NULL
);
238 /* now open the subkey */
239 Status
= ZwOpenKey(&hSubKey
, GENERIC_READ
, &ObjectAttributes
);
241 /* check for success */
242 if (NT_SUCCESS(Status
))
245 Status
= KsGetImageNameAndResourceId(hSubKey
, ImageName
, ResourceId
, ValueType
);
251 /* free subkey string */
252 FreeItem(SubKeyName
.Buffer
);
254 /* close device key */