- Implement ObpEnumFindHandleProcedure.
svn path=/trunk/; revision=25593
NTAPI
ExEnumHandleTable(
IN PHANDLE_TABLE HandleTable,
- IN PVOID Callback,
- IN OUT PVOID Param,
+ IN PEX_ENUM_HANDLE_CALLBACK EnumHandleProcedure,
+ IN OUT PVOID Context,
OUT PHANDLE Handle OPTIONAL
);
#else
+//
+// Handle Enumeration Callback
+//
+struct _HANDLE_TABLE_ENTRY;
+typedef BOOLEAN
+(NTAPI *PEX_ENUM_HANDLE_CALLBACK)(
+ IN struct _HANDLE_TABLE_ENTRY *HandleTableEntry,
+ IN HANDLE Handle,
+ IN PVOID Context
+);
+
//
// Compatibility with Windows XP Drivers using ERESOURCE
//
ULONG_PTR TableBase;
PHANDLE_TABLE_ENTRY Entry = NULL;
EXHANDLE Handle = LookupHandle;
- PCHAR Level1, Level2, Level3;
+ PUCHAR Level1, Level2, Level3;
/* Clear the tag bits and check what the next handle is */
Handle.TagBits = 0;
Handle.Value += SizeOfHandle(1);
}
}
+
+/*
+ * @implemented
+ */
+BOOLEAN
+NTAPI
+ExEnumHandleTable(IN PHANDLE_TABLE HandleTable,
+ IN PEX_ENUM_HANDLE_CALLBACK EnumHandleProcedure,
+ IN OUT PVOID Context,
+ OUT PHANDLE EnumHandle OPTIONAL)
+{
+ EXHANDLE Handle;
+ PHANDLE_TABLE_ENTRY HandleTableEntry;
+ BOOLEAN Result = FALSE;
+ PAGED_CODE();
+
+ /* Enter a critical region */
+ KeEnterCriticalRegion();
+
+ /* Set the initial value and loop the entries */
+ Handle.Value = 0;
+ while ((HandleTableEntry = ExpLookupHandleTableEntry(HandleTable, Handle)))
+ {
+ /* Validate the entry */
+ if ((HandleTableEntry) &&
+ (HandleTableEntry->Object) &&
+ (HandleTableEntry->NextFreeTableEntry != -2) &&
+ (HandleTableEntry->Object != (PVOID)0xCDCDCDCD)) // HACK OF ETERNAL LAPDANCE
+ {
+ /* Lock the entry */
+ if (ExpLockHandleTableEntry(HandleTable, HandleTableEntry))
+ {
+ /* Notify the callback routine */
+ Result = EnumHandleProcedure(HandleTableEntry,
+ Handle.GenericHandleOverlay,
+ Context);
+
+ /* Unlock it */
+ ExUnlockHandleTableEntry(HandleTable, HandleTableEntry);
+
+ /* Was this the one looked for? */
+ if (Result)
+ {
+ /* If so, return it if requested */
+ if (EnumHandle) *EnumHandle = Handle.GenericHandleOverlay;
+ break;
+ }
+ }
+ }
+
+ /* Go to the next entry */
+ Handle.Value += SizeOfHandle(1);
+ }
+
+ /* Leave the critical region and return callback result */
+ KeLeaveCriticalRegion();
+ return Result;
+}
return KeGetPreviousMode();
}
-/*
- * @unimplemented
- */
-BOOLEAN
-NTAPI
-ExEnumHandleTable(IN PHANDLE_TABLE HandleTable,
- IN PVOID Callback,
- IN OUT PVOID Param,
- OUT PHANDLE Handle OPTIONAL)
-{
- UNIMPLEMENTED;
- return FALSE;
-}
-
/*
* @implemented
*/
IN HANDLE Handle,
IN PVOID Context)
{
- /* FIXME: TODO */
- DPRINT1("Not yet implemented!\n");
- KEBUGCHECK(0);
- return FALSE;
+ POBJECT_HEADER ObjectHeader;
+ ACCESS_MASK GrantedAccess;
+ ULONG HandleAttributes;
+ POBP_FIND_HANDLE_DATA FindData = Context;
+
+ /* Get the object header */
+ ObjectHeader = ObpGetHandleObject(HandleEntry);
+
+ /* Make sure it's valid and matching */
+ if ((FindData->ObjectHeader) && (FindData->ObjectHeader != ObjectHeader))
+ {
+ /* No match, fail */
+ return FALSE;
+ }
+
+ /* Now attempt to match the object type */
+ if ((FindData->ObjectType) && (FindData->ObjectType != ObjectHeader->Type))
+ {
+ /* No match, fail */
+ return FALSE;
+ }
+
+ /* Check if we have extra information */
+ if (FindData->HandleInformation)
+ {
+ /* Get the granted access and attributes */
+ GrantedAccess = HandleEntry->GrantedAccess;
+ HandleAttributes = HandleEntry->ObAttributes & OBJ_HANDLE_ATTRIBUTES;
+
+ /* Attempt to match them */
+ if ((FindData->HandleInformation->HandleAttributes != HandleAttributes) ||
+ (FindData->HandleInformation->GrantedAccess != GrantedAccess))
+ {
+ /* No match, fail */
+ return FALSE;
+ }
+ }
+
+ /* We have a match */
+ return TRUE;
}
POBJECT_HANDLE_COUNT_ENTRY
if(!WinStaPresent)
{
+#if 0
/* search the process handle table for (inherited) window station
handles, use a more appropriate one than WinSta0 if possible. */
if (!ObFindHandleForObject(Process,
ExWindowStationObjectType,
NULL,
(PHANDLE)hWinSta))
+#endif
{
/* we had no luck searching for opened handles, use WinSta0 now */
RtlInitUnicodeString(&WinSta, L"WinSta0");
if(!DesktopPresent && hDesktop != NULL)
{
+#if 0
/* search the process handle table for (inherited) desktop
handles, use a more appropriate one than Default if possible. */
if (!ObFindHandleForObject(Process,
ExDesktopObjectType,
NULL,
(PHANDLE)hDesktop))
+#endif
{
/* we had no luck searching for opened handles, use Desktop now */
RtlInitUnicodeString(&Desktop, L"Default");
return NULL;
}
}
+ else
+ {
+ DPRINT1("Got handle: %lx\n", Ret);
+ }
return Ret;
}