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
);
59 /* not enough memory */
60 Status
= STATUS_INSUFFICIENT_RESOURCES
;
65 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
67 /* Exception, get the error code */
68 Status
= _SEH2_GetExceptionCode();
72 if (!NT_SUCCESS(Status
))
77 /* free resource buffer in case of a failure */
91 IN OUT PULONG BufferLength
,
95 return STATUS_NOT_IMPLEMENTED
;
104 KsGetImageNameAndResourceId(
106 OUT PUNICODE_STRING ImageName
,
107 OUT PULONG_PTR ResourceId
,
108 OUT PULONG ValueType
)
112 WCHAR ImagePath
[] = {L
"\\SystemRoot\\system32\\drivers\\"};
114 /* first clear the provided ImageName */
115 ImageName
->Buffer
= NULL
;
116 ImageName
->Length
= ImageName
->MaximumLength
= 0;
119 /* retrieve length of image name */
120 Status
= KspQueryRegValue(RegKey
, L
"Image", NULL
, &ImageLength
, NULL
);
122 if (Status
!= STATUS_BUFFER_OVERFLOW
)
124 /* key value doesnt exist */
128 /* allocate image name buffer */
129 ImageName
->MaximumLength
= sizeof(ImagePath
) + ImageLength
;
130 ImageName
->Buffer
= AllocateItem(PagedPool
, ImageName
->MaximumLength
);
132 /* check for success */
133 if (!ImageName
->Buffer
)
135 /* insufficient memory */
136 return STATUS_INSUFFICIENT_RESOURCES
;
139 /* copy image name */
140 RtlCopyMemory(ImageName
->Buffer
, ImagePath
, sizeof(ImagePath
));
142 /* retrieve image name */
143 Status
= KspQueryRegValue(RegKey
, L
"Image", &ImageName
->Buffer
[sizeof(ImagePath
) / sizeof(WCHAR
)], &ImageLength
, NULL
);
145 if (!NT_SUCCESS(Status
))
147 /* unexpected error */
148 FreeItem(ImageName
->Buffer
);
152 /* now query for resource id length*/
154 Status
= KspQueryRegValue(RegKey
, L
"ResourceId", NULL
, &ImageLength
, ValueType
);
156 /* allocate resource id buffer*/
157 *ResourceId
= (ULONG_PTR
)AllocateItem(PagedPool
, ImageLength
);
159 /* check for success */
162 /* insufficient memory */
163 FreeItem(ImageName
->Buffer
);
164 return STATUS_INSUFFICIENT_RESOURCES
;
166 /* now query for resource id */
167 Status
= KspQueryRegValue(RegKey
, L
"ResourceId", (PVOID
)*ResourceId
, &ImageLength
, ValueType
);
169 if (!NT_SUCCESS(Status
))
171 /* unexpected error */
172 FreeItem(ImageName
->Buffer
);
173 FreeItem((PVOID
)*ResourceId
);
187 IN PDEVICE_OBJECT PhysicalDeviceObject
,
188 IN PUNICODE_STRING ModuleName
,
189 OUT PUNICODE_STRING ImageName
,
190 OUT PULONG_PTR ResourceId
,
191 OUT PULONG ValueType
)
194 UNICODE_STRING SubKeyName
;
195 UNICODE_STRING Modules
= RTL_CONSTANT_STRING(L
"Modules\\");
196 HANDLE hKey
, hSubKey
;
197 OBJECT_ATTRIBUTES ObjectAttributes
;
199 /* first open device key */
200 Status
= IoOpenDeviceRegistryKey(PhysicalDeviceObject
, PLUGPLAY_REGKEY_DEVICE
, GENERIC_READ
, &hKey
);
202 /* check for success */
203 if (!NT_SUCCESS(Status
))
205 /* invalid parameter */
206 return STATUS_INVALID_PARAMETER
;
209 /* initialize subkey buffer */
210 SubKeyName
.Length
= 0;
211 SubKeyName
.MaximumLength
= Modules
.MaximumLength
+ ModuleName
->MaximumLength
;
212 SubKeyName
.Buffer
= AllocateItem(PagedPool
, SubKeyName
.MaximumLength
);
214 /* check for success */
215 if (!SubKeyName
.Buffer
)
217 /* not enough memory */
219 return STATUS_NO_MEMORY
;
222 /* build subkey string */
223 RtlAppendUnicodeStringToString(&SubKeyName
, &Modules
);
224 RtlAppendUnicodeStringToString(&SubKeyName
, ModuleName
);
226 /* initialize subkey attributes */
227 InitializeObjectAttributes(&ObjectAttributes
, &SubKeyName
, OBJ_CASE_INSENSITIVE
, hKey
, NULL
);
229 /* now open the subkey */
230 Status
= ZwOpenKey(&hSubKey
, GENERIC_READ
, &ObjectAttributes
);
232 /* check for success */
233 if (NT_SUCCESS(Status
))
236 Status
= KsGetImageNameAndResourceId(hSubKey
, ImageName
, ResourceId
, ValueType
);
242 /* free subkey string */
243 FreeItem(SubKeyName
.Buffer
);
245 /* close device key */