mirror of
https://github.com/reactos/reactos.git
synced 2025-08-05 09:03:25 +00:00
- Add some trace macros to monitor handle/pointer counts for fixing regressions/bugs later.
- Change ObpCreateHandle to use an ACCESS_STATE structure instead of DesiredAccess. This is to help moving to an updated model where creating and incrementing a handle are 2 operations, so that code can be refactored (similarly to how we now have Delete/Decrement as 2 operations). - Fix functions that were not creating an ACCESS_STATE Structure to create one locally now, or use the one passed as a parameter, if available. svn path=/trunk/; revision=22265
This commit is contained in:
parent
d2e5bfabe5
commit
f36b5d1f3b
1 changed files with 103 additions and 5 deletions
|
@ -19,6 +19,12 @@
|
||||||
|
|
||||||
PHANDLE_TABLE ObpKernelHandleTable = NULL;
|
PHANDLE_TABLE ObpKernelHandleTable = NULL;
|
||||||
|
|
||||||
|
#ifdef _OBDEBUG_
|
||||||
|
#define OBTRACE DPRINT1
|
||||||
|
#else
|
||||||
|
#define OBTRACE DPRINT
|
||||||
|
#endif
|
||||||
|
|
||||||
/* UGLY FUNCTIONS ************************************************************/
|
/* UGLY FUNCTIONS ************************************************************/
|
||||||
|
|
||||||
ULONG
|
ULONG
|
||||||
|
@ -215,6 +221,11 @@ ObpDecrementHandleCount(IN PVOID ObjectBody,
|
||||||
/* Get the object type and header */
|
/* Get the object type and header */
|
||||||
ObjectHeader = OBJECT_TO_OBJECT_HEADER(ObjectBody);
|
ObjectHeader = OBJECT_TO_OBJECT_HEADER(ObjectBody);
|
||||||
ObjectType = ObjectHeader->Type;
|
ObjectType = ObjectHeader->Type;
|
||||||
|
OBTRACE("OBTRACE - %s - Decrementing count for: %p. HC LC %lx %lx\n",
|
||||||
|
__FUNCTION__,
|
||||||
|
ObjectBody,
|
||||||
|
ObjectHeader->HandleCount,
|
||||||
|
ObjectHeader->PointerCount);
|
||||||
|
|
||||||
/* FIXME: The process handle count should be in the Handle DB. Investigate */
|
/* FIXME: The process handle count should be in the Handle DB. Investigate */
|
||||||
SystemHandleCount = ObjectHeader->HandleCount;
|
SystemHandleCount = ObjectHeader->HandleCount;
|
||||||
|
@ -239,6 +250,11 @@ ObpDecrementHandleCount(IN PVOID ObjectBody,
|
||||||
|
|
||||||
/* Decrease the total number of handles for this type */
|
/* Decrease the total number of handles for this type */
|
||||||
ObjectType->TotalNumberOfHandles--;
|
ObjectType->TotalNumberOfHandles--;
|
||||||
|
OBTRACE("OBTRACE - %s - Decremented count for: %p. HC LC %lx %lx\n",
|
||||||
|
__FUNCTION__,
|
||||||
|
ObjectBody,
|
||||||
|
ObjectHeader->HandleCount,
|
||||||
|
ObjectHeader->PointerCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*++
|
/*++
|
||||||
|
@ -285,6 +301,12 @@ ObpDeleteHandle(HANDLE Handle)
|
||||||
ObjectType = ObjectHeader->Type;
|
ObjectType = ObjectHeader->Type;
|
||||||
Body = &ObjectHeader->Body;
|
Body = &ObjectHeader->Body;
|
||||||
GrantedAccess = HandleEntry->GrantedAccess;
|
GrantedAccess = HandleEntry->GrantedAccess;
|
||||||
|
OBTRACE("OBTRACE - %s - Deleting handle: %lx for %p. HC LC %lx %lx\n",
|
||||||
|
__FUNCTION__,
|
||||||
|
Handle,
|
||||||
|
Body,
|
||||||
|
ObjectHeader->HandleCount,
|
||||||
|
ObjectHeader->PointerCount);
|
||||||
|
|
||||||
/* Check if the object has an Okay To Close procedure */
|
/* Check if the object has an Okay To Close procedure */
|
||||||
if (ObjectType->TypeInfo.OkayToCloseProcedure)
|
if (ObjectType->TypeInfo.OkayToCloseProcedure)
|
||||||
|
@ -316,6 +338,12 @@ ObpDeleteHandle(HANDLE Handle)
|
||||||
/* Now decrement the handle count */
|
/* Now decrement the handle count */
|
||||||
ObpDecrementHandleCount(Body, PsGetCurrentProcess(), GrantedAccess);
|
ObpDecrementHandleCount(Body, PsGetCurrentProcess(), GrantedAccess);
|
||||||
Status = STATUS_SUCCESS;
|
Status = STATUS_SUCCESS;
|
||||||
|
OBTRACE("OBTRACE - %s - Deleted handle: %lx for %p. HC LC %lx %lx\n",
|
||||||
|
__FUNCTION__,
|
||||||
|
Handle,
|
||||||
|
Body,
|
||||||
|
ObjectHeader->HandleCount,
|
||||||
|
ObjectHeader->PointerCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Leave the critical region and return the status */
|
/* Leave the critical region and return the status */
|
||||||
|
@ -326,7 +354,7 @@ ObpDeleteHandle(HANDLE Handle)
|
||||||
NTSTATUS
|
NTSTATUS
|
||||||
NTAPI
|
NTAPI
|
||||||
ObpCreateHandle(PVOID ObjectBody,
|
ObpCreateHandle(PVOID ObjectBody,
|
||||||
ACCESS_MASK GrantedAccess,
|
PACCESS_STATE AccessState,
|
||||||
ULONG HandleAttributes,
|
ULONG HandleAttributes,
|
||||||
PHANDLE HandleReturn)
|
PHANDLE HandleReturn)
|
||||||
/*
|
/*
|
||||||
|
@ -343,6 +371,7 @@ ObpCreateHandle(PVOID ObjectBody,
|
||||||
HANDLE Handle;
|
HANDLE Handle;
|
||||||
KAPC_STATE ApcState;
|
KAPC_STATE ApcState;
|
||||||
BOOLEAN AttachedToProcess = FALSE;
|
BOOLEAN AttachedToProcess = FALSE;
|
||||||
|
ACCESS_MASK GrantedAccess;
|
||||||
|
|
||||||
PAGED_CODE();
|
PAGED_CODE();
|
||||||
|
|
||||||
|
@ -357,6 +386,8 @@ ObpCreateHandle(PVOID ObjectBody,
|
||||||
/* check that this is a valid kernel pointer */
|
/* check that this is a valid kernel pointer */
|
||||||
ASSERT((ULONG_PTR)ObjectHeader & EX_HANDLE_ENTRY_LOCKED);
|
ASSERT((ULONG_PTR)ObjectHeader & EX_HANDLE_ENTRY_LOCKED);
|
||||||
|
|
||||||
|
GrantedAccess = AccessState->RemainingDesiredAccess |
|
||||||
|
AccessState->PreviouslyGrantedAccess;
|
||||||
if (GrantedAccess & MAXIMUM_ALLOWED)
|
if (GrantedAccess & MAXIMUM_ALLOWED)
|
||||||
{
|
{
|
||||||
GrantedAccess &= ~MAXIMUM_ALLOWED;
|
GrantedAccess &= ~MAXIMUM_ALLOWED;
|
||||||
|
@ -512,12 +543,16 @@ ObpDuplicateHandleCallback(IN PHANDLE_TABLE HandleTable,
|
||||||
{
|
{
|
||||||
POBJECT_HEADER ObjectHeader;
|
POBJECT_HEADER ObjectHeader;
|
||||||
BOOLEAN Ret = FALSE;
|
BOOLEAN Ret = FALSE;
|
||||||
|
ACCESS_STATE AccessState;
|
||||||
PAGED_CODE();
|
PAGED_CODE();
|
||||||
|
|
||||||
/* Make sure that the handle is inheritable */
|
/* Make sure that the handle is inheritable */
|
||||||
Ret = (HandleTableEntry->ObAttributes & EX_HANDLE_ENTRY_INHERITABLE) != 0;
|
Ret = (HandleTableEntry->ObAttributes & EX_HANDLE_ENTRY_INHERITABLE) != 0;
|
||||||
if(Ret)
|
if(Ret)
|
||||||
{
|
{
|
||||||
|
/* Setup the access state */
|
||||||
|
AccessState.PreviouslyGrantedAccess = HandleTableEntry->GrantedAccess;
|
||||||
|
|
||||||
/* Get the object header and increment the handle and pointer counts */
|
/* Get the object header and increment the handle and pointer counts */
|
||||||
ObjectHeader = EX_HTE_TO_HDR(HandleTableEntry);
|
ObjectHeader = EX_HTE_TO_HDR(HandleTableEntry);
|
||||||
InterlockedIncrement(&ObjectHeader->HandleCount);
|
InterlockedIncrement(&ObjectHeader->HandleCount);
|
||||||
|
@ -807,7 +842,7 @@ ObOpenObjectByName(IN POBJECT_ATTRIBUTES ObjectAttributes,
|
||||||
|
|
||||||
/* Create the actual handle now */
|
/* Create the actual handle now */
|
||||||
Status = ObpCreateHandle(Object,
|
Status = ObpCreateHandle(Object,
|
||||||
DesiredAccess,
|
PassedAccessState,
|
||||||
ObjectCreateInfo.Attributes,
|
ObjectCreateInfo.Attributes,
|
||||||
Handle);
|
Handle);
|
||||||
|
|
||||||
|
@ -825,6 +860,10 @@ Cleanup:
|
||||||
Quickie:
|
Quickie:
|
||||||
ObpReleaseCapturedAttributes(&ObjectCreateInfo);
|
ObpReleaseCapturedAttributes(&ObjectCreateInfo);
|
||||||
if (ObjectName.Buffer) ObpReleaseCapturedName(&ObjectName);
|
if (ObjectName.Buffer) ObpReleaseCapturedName(&ObjectName);
|
||||||
|
OBTRACE("OBTRACE: %s returning Object with PC S: %lx %lx\n",
|
||||||
|
__FUNCTION__,
|
||||||
|
OBJECT_TO_OBJECT_HEADER(Object)->PointerCount,
|
||||||
|
Status);
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -842,6 +881,8 @@ ObOpenObjectByPointer(IN PVOID Object,
|
||||||
OUT PHANDLE Handle)
|
OUT PHANDLE Handle)
|
||||||
{
|
{
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
|
ACCESS_STATE AccessState;
|
||||||
|
AUX_DATA AuxData;
|
||||||
PAGED_CODE();
|
PAGED_CODE();
|
||||||
|
|
||||||
/* Reference the object */
|
/* Reference the object */
|
||||||
|
@ -851,14 +892,42 @@ ObOpenObjectByPointer(IN PVOID Object,
|
||||||
AccessMode);
|
AccessMode);
|
||||||
if (!NT_SUCCESS(Status)) return Status;
|
if (!NT_SUCCESS(Status)) return Status;
|
||||||
|
|
||||||
|
/* Check if we didn't get an access state */
|
||||||
|
if (!PassedAccessState)
|
||||||
|
{
|
||||||
|
/* Use our built-in access state */
|
||||||
|
PassedAccessState = &AccessState;
|
||||||
|
Status = SeCreateAccessState(&AccessState,
|
||||||
|
&AuxData,
|
||||||
|
DesiredAccess,
|
||||||
|
&ObjectType->TypeInfo.GenericMapping);
|
||||||
|
if (!NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
/* Fail */
|
||||||
|
ObDereferenceObject(Object);
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Create the handle */
|
/* Create the handle */
|
||||||
Status = ObpCreateHandle(Object,
|
Status = ObpCreateHandle(Object,
|
||||||
DesiredAccess,
|
PassedAccessState,
|
||||||
HandleAttributes,
|
HandleAttributes,
|
||||||
Handle);
|
Handle);
|
||||||
|
|
||||||
|
/* Delete the access state */
|
||||||
|
if (PassedAccessState == &AccessState)
|
||||||
|
{
|
||||||
|
SeDeleteAccessState(PassedAccessState);
|
||||||
|
}
|
||||||
|
|
||||||
/* ROS Hack: Dereference the object and return */
|
/* ROS Hack: Dereference the object and return */
|
||||||
ObDereferenceObject(Object);
|
ObDereferenceObject(Object);
|
||||||
|
|
||||||
|
OBTRACE("OBTRACE: %s returning Object with PC S: %lx %lx\n",
|
||||||
|
__FUNCTION__,
|
||||||
|
OBJECT_TO_OBJECT_HEADER(Object)->PointerCount,
|
||||||
|
Status);
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -915,6 +984,8 @@ ObInsertObject(IN PVOID Object,
|
||||||
SECURITY_SUBJECT_CONTEXT SubjectContext;
|
SECURITY_SUBJECT_CONTEXT SubjectContext;
|
||||||
OBP_LOOKUP_CONTEXT Context;
|
OBP_LOOKUP_CONTEXT Context;
|
||||||
POBJECT_HEADER_NAME_INFO ObjectNameInfo;
|
POBJECT_HEADER_NAME_INFO ObjectNameInfo;
|
||||||
|
ACCESS_STATE AccessState;
|
||||||
|
AUX_DATA AuxData;
|
||||||
PAGED_CODE();
|
PAGED_CODE();
|
||||||
|
|
||||||
/* Get the Header and Create Info */
|
/* Get the Header and Create Info */
|
||||||
|
@ -1030,6 +1101,23 @@ ObInsertObject(IN PVOID Object,
|
||||||
DPRINT("Security Complete\n");
|
DPRINT("Security Complete\n");
|
||||||
SeReleaseSubjectContext(&SubjectContext);
|
SeReleaseSubjectContext(&SubjectContext);
|
||||||
|
|
||||||
|
/* Check if we didn't get an access state */
|
||||||
|
if (!PassedAccessState)
|
||||||
|
{
|
||||||
|
/* Use our built-in access state */
|
||||||
|
PassedAccessState = &AccessState;
|
||||||
|
Status = SeCreateAccessState(&AccessState,
|
||||||
|
&AuxData,
|
||||||
|
DesiredAccess,
|
||||||
|
&Header->Type->TypeInfo.GenericMapping);
|
||||||
|
if (!NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
/* Fail */
|
||||||
|
ObDereferenceObject(Object);
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Create the Handle */
|
/* Create the Handle */
|
||||||
/* HACKHACK: Because of ROS's incorrect startup, this can be called
|
/* HACKHACK: Because of ROS's incorrect startup, this can be called
|
||||||
* without a valid Process until I finalize the startup patch,
|
* without a valid Process until I finalize the startup patch,
|
||||||
|
@ -1041,7 +1129,7 @@ ObInsertObject(IN PVOID Object,
|
||||||
if (Handle != NULL)
|
if (Handle != NULL)
|
||||||
{
|
{
|
||||||
Status = ObpCreateHandle(&Header->Body,
|
Status = ObpCreateHandle(&Header->Body,
|
||||||
DesiredAccess,
|
PassedAccessState,
|
||||||
ObjectCreateInfo->Attributes,
|
ObjectCreateInfo->Attributes,
|
||||||
Handle);
|
Handle);
|
||||||
DPRINT("handle Created: %d. refcount. handlecount %d %d\n",
|
DPRINT("handle Created: %d. refcount. handlecount %d %d\n",
|
||||||
|
@ -1076,6 +1164,9 @@ NtDuplicateObject (IN HANDLE SourceProcessHandle,
|
||||||
KPROCESSOR_MODE PreviousMode;
|
KPROCESSOR_MODE PreviousMode;
|
||||||
KAPC_STATE ApcState;
|
KAPC_STATE ApcState;
|
||||||
NTSTATUS Status = STATUS_SUCCESS;
|
NTSTATUS Status = STATUS_SUCCESS;
|
||||||
|
ACCESS_STATE AccessState;
|
||||||
|
AUX_DATA AuxData;
|
||||||
|
PACCESS_STATE PassedAccessState = NULL;
|
||||||
|
|
||||||
PAGED_CODE();
|
PAGED_CODE();
|
||||||
|
|
||||||
|
@ -1162,8 +1253,15 @@ NtDuplicateObject (IN HANDLE SourceProcessHandle,
|
||||||
AttachedToProcess = TRUE;
|
AttachedToProcess = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
Status = ObpCreateHandle(ObjectBody,
|
/* Use our built-in access state */
|
||||||
|
PassedAccessState = &AccessState;
|
||||||
|
Status = SeCreateAccessState(&AccessState,
|
||||||
|
&AuxData,
|
||||||
DesiredAccess,
|
DesiredAccess,
|
||||||
|
&ObjectType->TypeInfo.GenericMapping);
|
||||||
|
|
||||||
|
Status = ObpCreateHandle(ObjectBody,
|
||||||
|
PassedAccessState,
|
||||||
HandleAttributes,
|
HandleAttributes,
|
||||||
&hTarget);
|
&hTarget);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue