BOOLEAN AttachedToProcess = FALSE;
PVOID HandleTable;
NTSTATUS Status;
+ ULONG i;
PAGED_CODE();
/* Get the object header and type */
/* Save the access mask */
NewEntry.GrantedAccess = DesiredAccess;
+ /* Handle extra references */
+ if (AdditionalReferences)
+ {
+ /* Make a copy in case we fail later below */
+ i = AdditionalReferences;
+ while (i--)
+ {
+ /* Increment the count */
+ InterlockedIncrement(&ObjectHeader->PointerCount);
+ }
+ }
+
/*
* Create the actual handle. We'll need to do this *after* calling
* ObpIncrementHandleCount to make sure that Object Security is valid
/* Make sure we got a handle */
if (Handle)
{
- /* Handle extra references */
- while (AdditionalReferences--)
- {
- /* Increment the count */
- InterlockedIncrement(&ObjectHeader->PointerCount);
- }
-
/* Check if this was a kernel handle */
if (HandleAttributes & OBJ_KERNEL_HANDLE)
{
*ReturnedHandle = Handle;
if (ReturnedObject) *ReturnedObject = Object;
OBTRACE(OB_HANDLE_DEBUG,
- "%s %s - Returning Handle: %lx HC LC %lx %lx\n",
+ "%s - Returning Handle: %lx HC LC %lx %lx\n",
__FUNCTION__,
Handle,
ObjectHeader->HandleCount,
return STATUS_SUCCESS;
}
+ /* Handle extra references */
+ while (AdditionalReferences--)
+ {
+ /* Decrement the count */
+ InterlockedDecrement(&ObjectHeader->PointerCount);
+ }
+
/* Decrement the handle count and detach */
ObpDecrementHandleCount(&ObjectHeader->Body,
PsGetCurrentProcess(),
POBJECT_TYPE ObjectType;
PVOID HandleTable;
NTSTATUS Status;
+ ULONG i;
PAGED_CODE();
/* Get the object header and type */
NewEntry.GrantedAccess = AccessState->RemainingDesiredAccess |
AccessState->PreviouslyGrantedAccess;
+ /* Handle extra references */
+ if (AdditionalReferences)
+ {
+ /* Make a copy in case we fail later below */
+ i = AdditionalReferences;
+ while (i--)
+ {
+ /* Increment the count */
+ InterlockedIncrement(&ObjectHeader->PointerCount);
+ }
+ }
+
/*
* Create the actual handle. We'll need to do this *after* calling
* ObpIncrementHandleCount to make sure that Object Security is valid
/* Make sure we got a handle */
if (Handle)
{
- /* Handle extra references */
- while (AdditionalReferences--)
- {
- /* Increment the count */
- InterlockedIncrement(&ObjectHeader->PointerCount);
- }
-
/* Check if this was a kernel handle */
if (HandleAttributes & OBJ_KERNEL_HANDLE)
{
return STATUS_SUCCESS;
}
+ /* Handle extra references */
+ while (AdditionalReferences--)
+ {
+ /* Increment the count */
+ InterlockedDecrement(&ObjectHeader->PointerCount);
+ }
+
/* Decrement the handle count and detach */
ObpDecrementHandleCount(&ObjectHeader->Body,
PsGetCurrentProcess(),
/* Make sure that the handle is inheritable */
Ret = (HandleTableEntry->ObAttributes & EX_HANDLE_ENTRY_INHERITABLE) != 0;
- if(Ret)
+ if (Ret)
{
/* Get the object header */
ObjectHeader = EX_HTE_TO_HDR(HandleTableEntry);
ObpReleaseCapturedAttributes(&ObjectCreateInfo);
if (ObjectName.Buffer) ObpReleaseCapturedName(&ObjectName);
OBTRACE(OB_HANDLE_DEBUG,
- "%s returning Object with PC S: %lx %lx\n",
+ "%s - returning Object %p with PC S: %lx %lx\n",
__FUNCTION__,
- OBJECT_TO_OBJECT_HEADER(Object)->PointerCount,
+ Object,
+ Object ? OBJECT_TO_OBJECT_HEADER(Object)->PointerCount : -1,
Status);
return Status;
}
Header->ObjectCreateInfo = NULL;
/* Remove the extra keep-alive reference */
- //ObDereferenceObject(Object); FIXME: Will require massive changes
+ //ObDereferenceObject(Object); // FIXME: Needs sync changes
/* Return */
return Status;
if (!NT_SUCCESS(Status))
{
/* We failed, dereference the object and delete the access state */
+ KEBUGCHECK(0);
ObDereferenceObject(Object);
if (PassedAccessState == &AccessState)
{
{
/* Create the handle */
Status = ObpCreateHandle(OpenReason,
- &Header->Body,
+ FoundObject,
NULL,
PassedAccessState,
AdditionalReferences + 1,
ObjectCreateInfo->Attributes,
ExGetPreviousMode(),
- NULL,
+ ReferencedObject,
Handle);
}
}
/* Remove the extra keep-alive reference */
- //ObDereferenceObject(Object); FIXME: Will require massive changes
+ //ObDereferenceObject(Object);
/* Check if we created our own access state */
if (PassedAccessState == &AccessState)