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
;
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
= 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
, L
"Image", &ImageName
->Buffer
[sizeof(ImagePath
) / sizeof(WCHAR
)], &ImageLength
, NULL
);
150 if (!NT_SUCCESS(Status
))
152 /* unexpected error */
153 FreeItem(ImageName
->Buffer
);
157 /* now query for resource id length*/
159 Status
= KspQueryRegValue(RegKey
, L
"ResourceId", NULL
, &ImageLength
, ValueType
);
161 /* allocate resource id buffer*/
162 *ResourceId
= (ULONG_PTR
)AllocateItem(PagedPool
, ImageLength
);
164 /* check for success */
167 /* insufficient memory */
168 FreeItem(ImageName
->Buffer
);
169 return STATUS_INSUFFICIENT_RESOURCES
;
171 /* now query for resource id */
172 Status
= KspQueryRegValue(RegKey
, L
"ResourceId", (PVOID
)*ResourceId
, &ImageLength
, ValueType
);
174 if (!NT_SUCCESS(Status
))
176 /* unexpected error */
177 FreeItem(ImageName
->Buffer
);
178 FreeItem((PVOID
)*ResourceId
);
192 IN PDEVICE_OBJECT PhysicalDeviceObject
,
193 IN PUNICODE_STRING ModuleName
,
194 OUT PUNICODE_STRING ImageName
,
195 OUT PULONG_PTR ResourceId
,
196 OUT PULONG ValueType
)
199 UNICODE_STRING SubKeyName
;
200 UNICODE_STRING Modules
= RTL_CONSTANT_STRING(L
"Modules\\");
201 HANDLE hKey
, hSubKey
;
202 OBJECT_ATTRIBUTES ObjectAttributes
;
204 /* first open device key */
205 Status
= IoOpenDeviceRegistryKey(PhysicalDeviceObject
, PLUGPLAY_REGKEY_DEVICE
, GENERIC_READ
, &hKey
);
207 /* check for success */
208 if (!NT_SUCCESS(Status
))
210 /* invalid parameter */
211 return STATUS_INVALID_PARAMETER
;
214 /* initialize subkey buffer */
215 SubKeyName
.Length
= 0;
216 SubKeyName
.MaximumLength
= Modules
.MaximumLength
+ ModuleName
->MaximumLength
;
217 SubKeyName
.Buffer
= AllocateItem(PagedPool
, SubKeyName
.MaximumLength
);
219 /* check for success */
220 if (!SubKeyName
.Buffer
)
222 /* not enough memory */
224 return STATUS_NO_MEMORY
;
227 /* build subkey string */
228 RtlAppendUnicodeStringToString(&SubKeyName
, &Modules
);
229 RtlAppendUnicodeStringToString(&SubKeyName
, ModuleName
);
231 /* initialize subkey attributes */
232 InitializeObjectAttributes(&ObjectAttributes
, &SubKeyName
, OBJ_CASE_INSENSITIVE
, hKey
, NULL
);
234 /* now open the subkey */
235 Status
= ZwOpenKey(&hSubKey
, GENERIC_READ
, &ObjectAttributes
);
237 /* check for success */
238 if (NT_SUCCESS(Status
))
241 Status
= KsGetImageNameAndResourceId(hSubKey
, ImageName
, ResourceId
, ValueType
);
247 /* free subkey string */
248 FreeItem(SubKeyName
.Buffer
);
250 /* close device key */