Author: ion Date: Mon Jan 22 12:57:10 2007 New Revision: 25593
URL: http://svn.reactos.org/svn/reactos?rev=25593&view=rev Log: - Implement ExEnumHandleTable. Had to add a small hack due to some memory freeing/init problem that requires more investigation. - Implement ObpEnumFindHandleProcedure.
Modified: trunk/reactos/include/ndk/exfuncs.h trunk/reactos/include/ndk/extypes.h trunk/reactos/ntoskrnl/ex/handle.c trunk/reactos/ntoskrnl/ex/sysinfo.c trunk/reactos/ntoskrnl/ob/obhandle.c trunk/reactos/subsystems/win32/win32k/ntuser/desktop.c
Modified: trunk/reactos/include/ndk/exfuncs.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/include/ndk/exfuncs.h?rev=2... ============================================================================== --- trunk/reactos/include/ndk/exfuncs.h (original) +++ trunk/reactos/include/ndk/exfuncs.h Mon Jan 22 12:57:10 2007 @@ -111,8 +111,8 @@ 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 );
Modified: trunk/reactos/include/ndk/extypes.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/include/ndk/extypes.h?rev=2... ============================================================================== --- trunk/reactos/include/ndk/extypes.h (original) +++ trunk/reactos/include/ndk/extypes.h Mon Jan 22 12:57:10 2007 @@ -362,6 +362,17 @@ #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 // typedef struct _ERESOURCE_XP
Modified: trunk/reactos/ntoskrnl/ex/handle.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ex/handle.c?rev=25... ============================================================================== --- trunk/reactos/ntoskrnl/ex/handle.c (original) +++ trunk/reactos/ntoskrnl/ex/handle.c Mon Jan 22 12:57:10 2007 @@ -39,7 +39,7 @@ 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; @@ -1239,3 +1239,61 @@ 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; +}
Modified: trunk/reactos/ntoskrnl/ex/sysinfo.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ex/sysinfo.c?rev=2... ============================================================================== --- trunk/reactos/ntoskrnl/ex/sysinfo.c (original) +++ trunk/reactos/ntoskrnl/ex/sysinfo.c Mon Jan 22 12:57:10 2007 @@ -36,20 +36,6 @@ ExGetPreviousMode (VOID) { return KeGetPreviousMode(); -} - -/* - * @unimplemented - */ -BOOLEAN -NTAPI -ExEnumHandleTable(IN PHANDLE_TABLE HandleTable, - IN PVOID Callback, - IN OUT PVOID Param, - OUT PHANDLE Handle OPTIONAL) -{ - UNIMPLEMENTED; - return FALSE; }
/*
Modified: trunk/reactos/ntoskrnl/ob/obhandle.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ob/obhandle.c?rev=... ============================================================================== --- trunk/reactos/ntoskrnl/ob/obhandle.c (original) +++ trunk/reactos/ntoskrnl/ob/obhandle.c Mon Jan 22 12:57:10 2007 @@ -177,10 +177,46 @@ 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
Modified: trunk/reactos/subsystems/win32/win32k/ntuser/desktop.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/win32k/ntu... ============================================================================== --- trunk/reactos/subsystems/win32/win32k/ntuser/desktop.c (original) +++ trunk/reactos/subsystems/win32/win32k/ntuser/desktop.c Mon Jan 22 12:57:10 2007 @@ -297,6 +297,7 @@
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, @@ -304,6 +305,7 @@ ExWindowStationObjectType, NULL, (PHANDLE)hWinSta)) +#endif { /* we had no luck searching for opened handles, use WinSta0 now */ RtlInitUnicodeString(&WinSta, L"WinSta0"); @@ -312,6 +314,7 @@
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, @@ -319,6 +322,7 @@ ExDesktopObjectType, NULL, (PHANDLE)hDesktop)) +#endif { /* we had no luck searching for opened handles, use Desktop now */ RtlInitUnicodeString(&Desktop, L"Default"); @@ -496,6 +500,10 @@ DPRINT1("Unable to create a desktop handle\n"); return NULL; } + } + else + { + DPRINT1("Got handle: %lx\n", Ret); }
return Ret;