From b440bf6faee4144df8d45538fad6f4848e7293c5 Mon Sep 17 00:00:00 2001 From: Alex Ionescu Date: Mon, 22 Jan 2007 09:57:10 +0000 Subject: [PATCH] - Implement ExEnumHandleTable. Had to add a small hack due to some memory freeing/init problem that requires more investigation. - Implement ObpEnumFindHandleProcedure. svn path=/trunk/; revision=25593 --- reactos/include/ndk/exfuncs.h | 4 +- reactos/include/ndk/extypes.h | 11 ++++ reactos/ntoskrnl/ex/handle.c | 60 ++++++++++++++++++- reactos/ntoskrnl/ex/sysinfo.c | 14 ----- reactos/ntoskrnl/ob/obhandle.c | 44 ++++++++++++-- .../subsystems/win32/win32k/ntuser/desktop.c | 8 +++ 6 files changed, 120 insertions(+), 21 deletions(-) diff --git a/reactos/include/ndk/exfuncs.h b/reactos/include/ndk/exfuncs.h index ba795188133..d987c741a86 100644 --- a/reactos/include/ndk/exfuncs.h +++ b/reactos/include/ndk/exfuncs.h @@ -111,8 +111,8 @@ BOOLEAN 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 ); diff --git a/reactos/include/ndk/extypes.h b/reactos/include/ndk/extypes.h index 01cb60df903..fb221c6eb1d 100644 --- a/reactos/include/ndk/extypes.h +++ b/reactos/include/ndk/extypes.h @@ -361,6 +361,17 @@ NTSTATUS #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 // diff --git a/reactos/ntoskrnl/ex/handle.c b/reactos/ntoskrnl/ex/handle.c index 2e68cbe7c31..e91a7448b29 100644 --- a/reactos/ntoskrnl/ex/handle.c +++ b/reactos/ntoskrnl/ex/handle.c @@ -39,7 +39,7 @@ ExpLookupHandleTableEntry(IN PHANDLE_TABLE HandleTable, 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 @@ ExSweepHandleTable(IN PHANDLE_TABLE HandleTable, 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; +} diff --git a/reactos/ntoskrnl/ex/sysinfo.c b/reactos/ntoskrnl/ex/sysinfo.c index 8f91ef33575..c04659eb8e5 100644 --- a/reactos/ntoskrnl/ex/sysinfo.c +++ b/reactos/ntoskrnl/ex/sysinfo.c @@ -38,20 +38,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; -} - /* * @implemented */ diff --git a/reactos/ntoskrnl/ob/obhandle.c b/reactos/ntoskrnl/ob/obhandle.c index 9383bd8b484..f9b71e24d98 100644 --- a/reactos/ntoskrnl/ob/obhandle.c +++ b/reactos/ntoskrnl/ob/obhandle.c @@ -177,10 +177,46 @@ ObpEnumFindHandleProcedure(IN PHANDLE_TABLE_ENTRY HandleEntry, 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 diff --git a/reactos/subsystems/win32/win32k/ntuser/desktop.c b/reactos/subsystems/win32/win32k/ntuser/desktop.c index ec23d919b0e..51ef6301d25 100644 --- a/reactos/subsystems/win32/win32k/ntuser/desktop.c +++ b/reactos/subsystems/win32/win32k/ntuser/desktop.c @@ -297,6 +297,7 @@ IntParseDesktopPath(PEPROCESS Process, 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 @@ IntParseDesktopPath(PEPROCESS Process, ExWindowStationObjectType, NULL, (PHANDLE)hWinSta)) +#endif { /* we had no luck searching for opened handles, use WinSta0 now */ RtlInitUnicodeString(&WinSta, L"WinSta0"); @@ -312,6 +314,7 @@ IntParseDesktopPath(PEPROCESS Process, 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 @@ IntParseDesktopPath(PEPROCESS Process, ExDesktopObjectType, NULL, (PHANDLE)hDesktop)) +#endif { /* we had no luck searching for opened handles, use Desktop now */ RtlInitUnicodeString(&Desktop, L"Default"); @@ -497,6 +501,10 @@ IntGetDesktopObjectHandle(PDESKTOP_OBJECT DesktopObject) return NULL; } } + else + { + DPRINT1("Got handle: %lx\n", Ret); + } return Ret; }