-/* $Id: object.c,v 1.79 2004/07/18 13:03:43 ekohl Exp $
- *
- * COPYRIGHT: See COPYING in the top level directory
- * PROJECT: ReactOS kernel
- * FILE: ntoskrnl/ob/object.c
- * PURPOSE: Implements generic object managment functions
- * PROGRAMMERS David Welch (welch@cwcom.net), Skywing (skywing@valhallalegends.com)
- * UPDATE HISTORY:
- * 10/06/98: Created
- * 09/13/03: Fixed various ObXxx routines to not call retention
- * checks directly at a raised IRQL.
+/* $Id$
+ *
+ * COPYRIGHT: See COPYING in the top level directory
+ * PROJECT: ReactOS kernel
+ * FILE: ntoskrnl/ob/object.c
+ * PURPOSE: Implements generic object managment functions
+ *
+ * PROGRAMMERS: David Welch (welch@cwcom.net)
+ * Skywing (skywing@valhallalegends.com)
*/
/* INCLUDES *****************************************************************/
-#define NTOS_MODE_KERNEL
-#include <ntos.h>
-#include <roscfg.h>
-#include <internal/ob.h>
-#include <internal/ps.h>
-#include <internal/id.h>
-#include <internal/ke.h>
-
+#include <ntoskrnl.h>
#define NDEBUG
#include <internal/debug.h>
POBJECT_HEADER ObjectHeader;
} RETENTION_CHECK_PARAMS, *PRETENTION_CHECK_PARAMS;
-
/* FUNCTIONS ************************************************************/
-PVOID HEADER_TO_BODY(POBJECT_HEADER obj)
+NTSTATUS
+STDCALL
+ObpCaptureObjectName(IN OUT PUNICODE_STRING CapturedName,
+ IN PUNICODE_STRING ObjectName,
+ IN KPROCESSOR_MODE AccessMode)
{
- return(((char*)obj)+sizeof(OBJECT_HEADER)-sizeof(COMMON_BODY_HEADER));
+ NTSTATUS Status = STATUS_SUCCESS;
+ UNICODE_STRING LocalName;
+
+ /* First Probe the String */
+ DPRINT("ObpCaptureObjectName: %wZ\n", ObjectName);
+ if (AccessMode != KernelMode)
+ {
+ DPRINT("Probing Struct\n");
+ _SEH_TRY
+ {
+ /* FIXME: Explorer or win32 broken I think */
+ #if 0
+ ProbeForRead(ObjectName,
+ sizeof(UNICODE_STRING),
+ sizeof(USHORT));
+ #endif
+ LocalName = *ObjectName;
+ }
+ _SEH_HANDLE
+ {
+ Status = _SEH_GetExceptionCode();
+ }
+ _SEH_END;
+
+ if (NT_SUCCESS(Status))
+ {
+ DPRINT("Probing OK\n");
+ _SEH_TRY
+ {
+ #if 0
+ DPRINT("Probing buffer\n");
+ ProbeForRead(LocalName.Buffer,
+ LocalName.Length,
+ sizeof(USHORT));
+ #endif
+ }
+ _SEH_HANDLE
+ {
+ Status = _SEH_GetExceptionCode();
+ }
+ _SEH_END;
+ }
+
+ /* Fail if anything up to here died */
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT1("Probing failed\n");
+ return Status;
+ }
+ }
+ else
+ {
+ LocalName = *ObjectName;
+ }
+
+ /* Make sure there really is a string */
+ DPRINT("Probing OK\n");
+ if (LocalName.Length)
+ {
+ /* Allocate a non-paged buffer for this string */
+ DPRINT("Capturing String\n");
+ CapturedName->Length = LocalName.Length;
+ CapturedName->MaximumLength = LocalName.Length + sizeof(WCHAR);
+ CapturedName->Buffer = ExAllocatePoolWithTag(NonPagedPool,
+ CapturedName->MaximumLength,
+ TAG('O','b','N','m'));
+
+ /* Copy the string and null-terminate it */
+ RtlMoveMemory(CapturedName->Buffer, LocalName.Buffer, LocalName.Length);
+ CapturedName->Buffer[LocalName.Length / sizeof(WCHAR)] = UNICODE_NULL;
+ DPRINT("String Captured: %p, %wZ\n", CapturedName, CapturedName);
+ }
+
+ return Status;
}
+NTSTATUS
+STDCALL
+ObpCaptureObjectAttributes(IN POBJECT_ATTRIBUTES ObjectAttributes,
+ IN KPROCESSOR_MODE AccessMode,
+ IN POBJECT_TYPE ObjectType,
+ IN POBJECT_CREATE_INFORMATION ObjectCreateInfo,
+ OUT PUNICODE_STRING ObjectName)
+{
+ NTSTATUS Status = STATUS_SUCCESS;
+ PSECURITY_DESCRIPTOR SecurityDescriptor;
+ PSECURITY_QUALITY_OF_SERVICE SecurityQos;
+ PUNICODE_STRING LocalObjectName = NULL;
+
+ /* Zero out the Capture Data */
+ DPRINT("ObpCaptureObjectAttributes\n");
+ RtlZeroMemory(ObjectCreateInfo, sizeof(OBJECT_CREATE_INFORMATION));
+
+ /* Check if we got Oba */
+ if (ObjectAttributes)
+ {
+ if (AccessMode != KernelMode)
+ {
+ DPRINT("Probing OBA\n");
+ _SEH_TRY
+ {
+ /* FIXME: SMSS SENDS BULLSHIT. */
+ #if 0
+ ProbeForRead(ObjectAttributes,
+ sizeof(ObjectAttributes),
+ sizeof(ULONG));
+ #endif
+ }
+ _SEH_HANDLE
+ {
+ Status = _SEH_GetExceptionCode();
+ }
+ _SEH_END;
+ }
+
+ /* Validate the Size */
+ DPRINT("Validating OBA\n");
+ if (ObjectAttributes->Length != sizeof(OBJECT_ATTRIBUTES))
+ {
+ Status = STATUS_INVALID_PARAMETER;
+ }
-POBJECT_HEADER BODY_TO_HEADER(PVOID body)
+ /* Fail if SEH or Size Validation failed */
+ if(!NT_SUCCESS(Status))
+ {
+ DPRINT1("ObpCaptureObjectAttributes failed to probe object attributes\n");
+ goto fail;
+ }
+
+ /* Set some Create Info */
+ DPRINT("Creating OBCI\n");
+ ObjectCreateInfo->RootDirectory = ObjectAttributes->RootDirectory;
+ ObjectCreateInfo->Attributes = ObjectAttributes->Attributes;
+ LocalObjectName = ObjectAttributes->ObjectName;
+ SecurityDescriptor = ObjectAttributes->SecurityDescriptor;
+ SecurityQos = ObjectAttributes->SecurityQualityOfService;
+
+ /* Validate the SD */
+ if (SecurityDescriptor)
+ {
+ DPRINT("Probing SD: %x\n", SecurityDescriptor);
+ Status = SeCaptureSecurityDescriptor(SecurityDescriptor,
+ AccessMode,
+ NonPagedPool,
+ TRUE,
+ &ObjectCreateInfo->SecurityDescriptor);
+ if(!NT_SUCCESS(Status))
+ {
+ DPRINT1("Unable to capture the security descriptor!!!\n");
+ ObjectCreateInfo->SecurityDescriptor = NULL;
+ goto fail;
+ }
+
+ DPRINT("Probe done\n");
+ ObjectCreateInfo->SecurityDescriptorCharge = 0; /* FIXME */
+ ObjectCreateInfo->ProbeMode = AccessMode;
+ }
+
+ /* Validate the QoS */
+ if (SecurityQos)
+ {
+ if (AccessMode != KernelMode)
+ {
+ DPRINT("Probing QoS\n");
+ _SEH_TRY
+ {
+ ProbeForRead(SecurityQos,
+ sizeof(SECURITY_QUALITY_OF_SERVICE),
+ sizeof(ULONG));
+ }
+ _SEH_HANDLE
+ {
+ Status = _SEH_GetExceptionCode();
+ }
+ _SEH_END;
+ }
+
+ if(!NT_SUCCESS(Status))
+ {
+ DPRINT1("Unable to capture QoS!!!\n");
+ goto fail;
+ }
+
+ ObjectCreateInfo->SecurityQualityOfService = *SecurityQos;
+ ObjectCreateInfo->SecurityQos = &ObjectCreateInfo->SecurityQualityOfService;
+ }
+ }
+
+ /* Clear Local Object Name */
+ DPRINT("Clearing name\n");
+ RtlZeroMemory(ObjectName, sizeof(UNICODE_STRING));
+
+ /* Now check if the Object Attributes had an Object Name */
+ if (LocalObjectName)
+ {
+ DPRINT("Name Buffer: %x\n", LocalObjectName->Buffer);
+ Status = ObpCaptureObjectName(ObjectName,
+ LocalObjectName,
+ AccessMode);
+ }
+ else
+ {
+ /* He can't have specified a Root Directory */
+ if (ObjectCreateInfo->RootDirectory)
+ {
+ DPRINT1("Invalid name\n");
+ Status = STATUS_OBJECT_NAME_INVALID;
+ }
+ }
+
+fail:
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT1("Failed to capture, cleaning up\n");
+ ObpReleaseCapturedAttributes(ObjectCreateInfo);
+ }
+
+ DPRINT("Return to caller\n");
+ return Status;
+}
+
+
+VOID
+STDCALL
+ObpReleaseCapturedAttributes(IN POBJECT_CREATE_INFORMATION ObjectCreateInfo)
{
- PCOMMON_BODY_HEADER chdr = (PCOMMON_BODY_HEADER)body;
- return(CONTAINING_RECORD((&(chdr->Type)),OBJECT_HEADER,Type));
+ /* Release the SD, it's the only thing we allocated */
+ if (ObjectCreateInfo->SecurityDescriptor)
+ {
+ SeReleaseSecurityDescriptor(ObjectCreateInfo->SecurityDescriptor,
+ ObjectCreateInfo->ProbeMode,
+ TRUE);
+ ObjectCreateInfo->SecurityDescriptor = NULL;
+ }
}
* RETURN VALUE
*/
NTSTATUS
-ObFindObject(POBJECT_ATTRIBUTES ObjectAttributes,
+ObFindObject(POBJECT_CREATE_INFORMATION ObjectCreateInfo,
+ PUNICODE_STRING ObjectName,
PVOID* ReturnedObject,
PUNICODE_STRING RemainingPath,
POBJECT_TYPE ObjectType)
PWSTR current;
UNICODE_STRING PathString;
ULONG Attributes;
- PUNICODE_STRING ObjectName;
- DPRINT("ObFindObject(ObjectAttributes %x, ReturnedObject %x, "
- "RemainingPath %x)\n",ObjectAttributes,ReturnedObject,RemainingPath);
- DPRINT("ObjectAttributes->ObjectName %wZ\n",
- ObjectAttributes->ObjectName);
+ PAGED_CODE();
+
+ DPRINT("ObFindObject(ObjectCreateInfo %x, ReturnedObject %x, "
+ "RemainingPath %x)\n",ObjectCreateInfo,ReturnedObject,RemainingPath);
RtlInitUnicodeString (RemainingPath, NULL);
- if (ObjectAttributes->RootDirectory == NULL)
+ if (ObjectCreateInfo->RootDirectory == NULL)
{
ObReferenceObjectByPointer(NameSpaceRoot,
DIRECTORY_TRAVERSE,
}
else
{
- Status = ObReferenceObjectByHandle(ObjectAttributes->RootDirectory,
- DIRECTORY_TRAVERSE,
+ Status = ObReferenceObjectByHandle(ObjectCreateInfo->RootDirectory,
+ 0,
NULL,
UserMode,
&CurrentObject,
}
}
- ObjectName = ObjectAttributes->ObjectName;
if (ObjectName->Length == 0 ||
ObjectName->Buffer[0] == UNICODE_NULL)
{
return STATUS_SUCCESS;
}
- if (ObjectAttributes->RootDirectory == NULL &&
+ if (ObjectCreateInfo->RootDirectory == NULL &&
ObjectName->Buffer[0] != L'\\')
{
ObDereferenceObject (CurrentObject);
+ DPRINT1("failed\n");
return STATUS_UNSUCCESSFUL;
}
current = PathString.Buffer;
RootObject = CurrentObject;
- Attributes = ObjectAttributes->Attributes;
+ Attributes = ObjectCreateInfo->Attributes;
if (ObjectType == ObSymbolicLinkType)
Attributes |= OBJ_OPENLINK;
CurrentHeader = BODY_TO_HEADER(CurrentObject);
DPRINT("Current ObjectType %wZ\n",
- &CurrentHeader->ObjectType->TypeName);
+ &CurrentHeader->ObjectType->Name);
- if (CurrentHeader->ObjectType->Parse == NULL)
+ if (CurrentHeader->ObjectType->TypeInfo.ParseProcedure == NULL)
{
DPRINT("Current object can't parse\n");
break;
}
- Status = CurrentHeader->ObjectType->Parse(CurrentObject,
+ Status = CurrentHeader->ObjectType->TypeInfo.ParseProcedure(CurrentObject,
&NextObject,
&PathString,
¤t,
/* reparse the object path */
NextObject = NameSpaceRoot;
current = PathString.Buffer;
-
+
ObReferenceObjectByPointer(NextObject,
DIRECTORY_TRAVERSE,
NULL,
}
if (current)
- RtlCreateUnicodeString (RemainingPath, current);
+ {
+ RtlpCreateUnicodeString (RemainingPath, current, NonPagedPool);
+ }
+
RtlFreeUnicodeString (&PathString);
*ReturnedObject = CurrentObject;
ULONG LocalReturnLength;
NTSTATUS Status;
+ PAGED_CODE();
+
*ReturnLength = 0;
if (Length < sizeof(OBJECT_NAME_INFORMATION) + sizeof(WCHAR))
ObjectHeader = BODY_TO_HEADER(Object);
if (ObjectHeader->ObjectType != NULL &&
- ObjectHeader->ObjectType->QueryName != NULL)
+ ObjectHeader->ObjectType->TypeInfo.QueryNameProcedure != NULL)
{
- DPRINT ("Calling %x\n", ObjectHeader->ObjectType->QueryName);
- Status = ObjectHeader->ObjectType->QueryName (Object,
+ DPRINT ("Calling %x\n", ObjectHeader->ObjectType->TypeInfo.QueryNameProcedure);
+ Status = ObjectHeader->ObjectType->TypeInfo.QueryNameProcedure (Object,
ObjectNameInfo,
Length,
ReturnLength);
}
- else if (ObjectHeader->Name.Length > 0 && ObjectHeader->Name.Buffer != NULL)
+ else if (ObjectHeader->NameInfo->Name.Length > 0 && ObjectHeader->NameInfo->Name.Buffer != NULL)
{
DPRINT ("Object does not have a 'QueryName' function\n");
- if (ObjectHeader->Parent == NameSpaceRoot)
+ if (ObjectHeader->NameInfo->Directory == NameSpaceRoot)
{
DPRINT ("Reached the root directory\n");
ObjectNameInfo->Name.Length = 0;
ObjectNameInfo->Name.Buffer[0] = 0;
Status = STATUS_SUCCESS;
}
- else if (ObjectHeader->Parent != NULL)
+ else if (ObjectHeader->NameInfo->Directory != NULL)
{
LocalInfo = ExAllocatePool (NonPagedPool,
sizeof(OBJECT_NAME_INFORMATION) +
if (LocalInfo == NULL)
return STATUS_INSUFFICIENT_RESOURCES;
- Status = ObQueryNameString (ObjectHeader->Parent,
+ Status = ObQueryNameString (ObjectHeader->NameInfo->Directory,
LocalInfo,
MAX_PATH * sizeof(WCHAR),
&LocalReturnLength);
return Status;
}
- DPRINT ("Object path %wZ\n", &ObjectHeader->Name);
+ DPRINT ("Object path %wZ\n", &ObjectHeader->NameInfo->Name);
Status = RtlAppendUnicodeToString (&ObjectNameInfo->Name,
L"\\");
if (!NT_SUCCESS (Status))
return Status;
Status = RtlAppendUnicodeStringToString (&ObjectNameInfo->Name,
- &ObjectHeader->Name);
+ &ObjectHeader->NameInfo->Name);
}
else
{
return Status;
}
+NTSTATUS
+STDCALL
+ObpAllocateObject(POBJECT_CREATE_INFORMATION ObjectCreateInfo,
+ PUNICODE_STRING ObjectName,
+ POBJECT_TYPE ObjectType,
+ ULONG ObjectSize,
+ POBJECT_HEADER *ObjectHeader)
+{
+ POBJECT_HEADER Header;
+ POBJECT_HEADER_NAME_INFO ObjectNameInfo;
+ POOL_TYPE PoolType;
+ ULONG Tag;
+
+ /* If we don't have an Object Type yet, force NonPaged */
+ DPRINT("ObpAllocateObject\n");
+ if (!ObjectType)
+ {
+ PoolType = NonPagedPool;
+ Tag = TAG('O', 'b', 'j', 'T');
+ }
+ else
+ {
+ PoolType = ObjectType->TypeInfo.PoolType;
+ Tag = ObjectType->Key;
+ }
+
+ /* Allocate memory for the Object */
+ Header = ExAllocatePoolWithTag(PoolType, ObjectSize, Tag);
+ if (!Header) {
+ DPRINT1("Not enough memory!\n");
+ return STATUS_INSUFFICIENT_RESOURCES;
+ }
+
+ /* Initialize the object header */
+ RtlZeroMemory(Header, ObjectSize);
+ DPRINT("Initalizing header %p\n", Header);
+ Header->HandleCount = 0;
+ Header->RefCount = 1;
+ Header->ObjectType = ObjectType;
+ if (ObjectCreateInfo && ObjectCreateInfo->Attributes & OBJ_PERMANENT)
+ {
+ Header->Permanent = TRUE;
+ }
+ if (ObjectCreateInfo && ObjectCreateInfo->Attributes & OBJ_INHERIT)
+ {
+ Header->Inherit = TRUE;
+ }
+
+ /* Initialize the Object Name Info [part of header in OB 2.0] */
+ ObjectNameInfo = ExAllocatePool(PoolType, ObjectSize);
+ ObjectNameInfo->Name = *ObjectName;
+ ObjectNameInfo->Directory = NULL;
+
+ /* Link stuff to Object Header */
+ Header->NameInfo = ObjectNameInfo;
+ Header->ObjectCreateInfo = ObjectCreateInfo;
+
+ /* Return Header */
+ *ObjectHeader = Header;
+ return STATUS_SUCCESS;
+}
/**********************************************************************
* NAME EXPORTED
*
* @implemented
*/
-NTSTATUS STDCALL
-ObCreateObject (IN KPROCESSOR_MODE ObjectAttributesAccessMode OPTIONAL,
- IN POBJECT_TYPE Type,
- IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL,
- IN KPROCESSOR_MODE AccessMode,
- IN OUT PVOID ParseContext OPTIONAL,
- IN ULONG ObjectSize,
- IN ULONG PagedPoolCharge OPTIONAL,
- IN ULONG NonPagedPoolCharge OPTIONAL,
- OUT PVOID *Object)
+NTSTATUS
+STDCALL
+ObCreateObject(IN KPROCESSOR_MODE ObjectAttributesAccessMode OPTIONAL,
+ IN POBJECT_TYPE Type,
+ IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL,
+ IN KPROCESSOR_MODE AccessMode,
+ IN OUT PVOID ParseContext OPTIONAL,
+ IN ULONG ObjectSize,
+ IN ULONG PagedPoolCharge OPTIONAL,
+ IN ULONG NonPagedPoolCharge OPTIONAL,
+ OUT PVOID *Object)
{
- PVOID Parent = NULL;
- UNICODE_STRING RemainingPath;
- POBJECT_HEADER Header;
- POBJECT_HEADER ParentHeader = NULL;
- NTSTATUS Status;
- BOOLEAN ObjectAttached = FALSE;
- PWCHAR NamePtr;
- PSECURITY_DESCRIPTOR NewSecurityDescriptor = NULL;
-
- assert_irql(APC_LEVEL);
-
- DPRINT("ObCreateObject(Type %p ObjectAttributes %p, Object %p)\n",
- Type, ObjectAttributes, Object);
-
- if (Type == NULL)
+ NTSTATUS Status;
+ POBJECT_CREATE_INFORMATION ObjectCreateInfo;
+ UNICODE_STRING ObjectName;
+ POBJECT_HEADER Header;
+
+ DPRINT("ObCreateObject(Type %p ObjectAttributes %p, Object %p)\n",
+ Type, ObjectAttributes, Object);
+
+ /* Allocate a Buffer for the Object Create Info */
+ DPRINT("Allocating Create Buffer\n");
+ ObjectCreateInfo = ExAllocatePoolWithTag(NonPagedPool,
+ sizeof(*ObjectCreateInfo),
+ TAG('O','b','C', 'I'));
+
+ /* Capture all the info */
+ DPRINT("Capturing Create Info\n");
+ Status = ObpCaptureObjectAttributes(ObjectAttributes,
+ AccessMode,
+ Type,
+ ObjectCreateInfo,
+ &ObjectName);
+
+ if (NT_SUCCESS(Status))
{
- DPRINT1("Invalid object type!\n");
- return STATUS_INVALID_PARAMETER;
- }
-
- if (ObjectAttributes != NULL &&
- ObjectAttributes->ObjectName != NULL &&
- ObjectAttributes->ObjectName->Buffer != NULL)
- {
- Status = ObFindObject(ObjectAttributes,
- &Parent,
- &RemainingPath,
- NULL);
- if (!NT_SUCCESS(Status))
- {
- DPRINT("ObFindObject() failed! (Status 0x%x)\n", Status);
- return(Status);
- }
- }
- else
- {
- RtlInitUnicodeString(&RemainingPath, NULL);
- }
-
- Header = (POBJECT_HEADER)ExAllocatePoolWithTag(NonPagedPool,
- OBJECT_ALLOC_SIZE(ObjectSize),
- Type->Tag);
- if (Header == NULL)
- return STATUS_INSUFFICIENT_RESOURCES;
- RtlZeroMemory(Header, OBJECT_ALLOC_SIZE(ObjectSize));
-
- /* Initialize the object header */
- Header->HandleCount = 0;
- Header->RefCount = 1;
- Header->ObjectType = Type;
- if (ObjectAttributes != NULL &&
- ObjectAttributes->Attributes & OBJ_PERMANENT)
- {
- Header->Permanent = TRUE;
- }
- else
- {
- Header->Permanent = FALSE;
- }
-
- if (ObjectAttributes != NULL &&
- ObjectAttributes->Attributes & OBJ_INHERIT)
- {
- Header->Inherit = TRUE;
- }
- else
- {
- Header->Inherit = FALSE;
- }
-
- RtlInitUnicodeString(&(Header->Name),NULL);
-
- if (Parent != NULL)
- {
- ParentHeader = BODY_TO_HEADER(Parent);
- }
-
- if (ParentHeader != NULL &&
- ParentHeader->ObjectType == ObDirectoryType &&
- RemainingPath.Buffer != NULL)
- {
- NamePtr = RemainingPath.Buffer;
- if (*NamePtr == L'\\')
- NamePtr++;
-
- ObpAddEntryDirectory(Parent,
- Header,
- NamePtr);
-
- ObjectAttached = TRUE;
- }
-
- if (Header->ObjectType->Create != NULL)
- {
- DPRINT("Calling %x\n", Header->ObjectType->Create);
- Status = Header->ObjectType->Create(HEADER_TO_BODY(Header),
- Parent,
- RemainingPath.Buffer,
- ObjectAttributes);
- if (!NT_SUCCESS(Status))
- {
- if (ObjectAttached == TRUE)
- {
- ObpRemoveEntryDirectory(Header);
- }
- if (Parent)
- {
- ObDereferenceObject(Parent);
- }
- RtlFreeUnicodeString(&Header->Name);
- RtlFreeUnicodeString(&RemainingPath);
- ExFreePool(Header);
- return(Status);
- }
- }
- RtlFreeUnicodeString(&RemainingPath);
-
- /* Build the new security descriptor */
- Status = SeAssignSecurity((ParentHeader != NULL) ? ParentHeader->SecurityDescriptor : NULL,
- (ObjectAttributes != NULL) ? ObjectAttributes->SecurityDescriptor : NULL,
- &NewSecurityDescriptor,
- (Header->ObjectType == ObDirectoryType),
- NULL, //SubjectContext,
- Header->ObjectType->Mapping,
- PagedPool);
- if (NT_SUCCESS(Status))
- {
- DPRINT("NewSecurityDescriptor %p\n", NewSecurityDescriptor);
-
- if (Header->ObjectType->Security != NULL)
- {
- /* FIXME: Call the security method */
- Status = STATUS_SUCCESS;
- }
- else
- {
- /* Assign the security descriptor to the object header */
- Status = ObpAddSecurityDescriptor(NewSecurityDescriptor,
- &Header->SecurityDescriptor);
- DPRINT("Object security descriptor %p\n", Header->SecurityDescriptor);
- }
-
- /* Release the new security descriptor */
- SeDeassignSecurity(&NewSecurityDescriptor);
- }
-
- if (Object != NULL)
- {
- *Object = HEADER_TO_BODY(Header);
+ /* Allocate the Object */
+ DPRINT("Allocating: %wZ\n", &ObjectName);
+ Status = ObpAllocateObject(ObjectCreateInfo,
+ &ObjectName,
+ Type,
+ OBJECT_ALLOC_SIZE(ObjectSize),
+ &Header);
+
+ if (NT_SUCCESS(Status))
+ {
+ /* Return the Object */
+ DPRINT("Returning Object\n");
+ *Object = HEADER_TO_BODY(Header);
+
+ /* Return to caller, leave the Capture Info Alive for ObInsert */
+ return Status;
+ }
+
+ /* Release the Capture Info, we don't need it */
+ DPRINT1("Allocation failed\n");
+ ObpReleaseCapturedAttributes(ObjectCreateInfo);
+ if (ObjectName.Buffer) ExFreePool(ObjectName.Buffer);
}
-
- return(STATUS_SUCCESS);
+
+ /* We failed, so release the Buffer */
+ DPRINT1("Capture failed\n");
+ ExFreePool(ObjectCreateInfo);
+ return Status;
}
-
/*
* FUNCTION: Increments the pointer reference count for a given object
* ARGUMENTS:
{
POBJECT_HEADER Header;
+ /* NOTE: should be possible to reference an object above APC_LEVEL! */
+
DPRINT("ObReferenceObjectByPointer(Object %x, ObjectType %x)\n",
Object,ObjectType);
-
+
Header = BODY_TO_HEADER(Object);
-
+
if (ObjectType != NULL && Header->ObjectType != ObjectType)
{
DPRINT("Failed %x (type was %x %S) should be %x %S\n",
Header->ObjectType,
Header->ObjectType->TypeName.Buffer,
ObjectType,
- ObjectType->TypeName.Buffer);
+ ObjectType->TypeName.Buffer);
return(STATUS_UNSUCCESSFUL);
}
if (Header->ObjectType == PsProcessType)
Object, Header->RefCount, PsThreadType);
DPRINT("eip %x\n", ((PULONG)&Object)[-1]);
}
-
- if (Header->CloseInProcess)
+
+ if (Header->RefCount == 0 && !Header->Permanent)
{
if (Header->ObjectType == PsProcessType)
{
return(STATUS_UNSUCCESSFUL);
}
- InterlockedIncrement(&Header->RefCount);
-
+ if (1 == InterlockedIncrement(&Header->RefCount) && !Header->Permanent)
+ {
+ KEBUGCHECK(0);
+ }
+
return(STATUS_SUCCESS);
}
OUT PHANDLE Handle)
{
NTSTATUS Status;
-
+
+ PAGED_CODE();
+
DPRINT("ObOpenObjectByPointer()\n");
-
+
Status = ObReferenceObjectByPointer(Object,
0,
ObjectType,
{
return Status;
}
-
- Status = ObCreateHandle(PsGetCurrentProcess(),
+
+ Status = ObpCreateHandle(PsGetCurrentProcess(),
Object,
DesiredAccess,
(BOOLEAN)(HandleAttributes & OBJ_INHERIT),
Handle);
-
+
ObDereferenceObject(Object);
-
+
return STATUS_SUCCESS;
}
static NTSTATUS
ObpDeleteObject(POBJECT_HEADER Header)
{
- DPRINT("ObPerformRetentionChecks(Header %p)\n", Header);
+ DPRINT("ObpDeleteObject(Header %p)\n", Header);
if (KeGetCurrentIrql() != PASSIVE_LEVEL)
{
- DPRINT("ObpPerformRetentionChecks called at an unsupported IRQL. Use ObpPerformRetentionChecksDpcLevel instead.\n");
+ DPRINT("ObpDeleteObject called at an unsupported IRQL. Use ObpDeleteObjectDpcLevel instead.\n");
KEBUGCHECK(0);
}
+ if (Header->ObjectType != NULL &&
+ Header->ObjectType->TypeInfo.DeleteProcedure != NULL)
+ {
+ Header->ObjectType->TypeInfo.DeleteProcedure(HEADER_TO_BODY(Header));
+ }
+
if (Header->SecurityDescriptor != NULL)
{
ObpRemoveSecurityDescriptor(Header->SecurityDescriptor);
}
-
- if (Header->ObjectType != NULL &&
- Header->ObjectType->Delete != NULL)
+
+ if (Header->NameInfo)
{
- Header->ObjectType->Delete(HEADER_TO_BODY(Header));
+ if(Header->NameInfo->Name.Buffer)
+ {
+ ExFreePool(Header->NameInfo->Name.Buffer);
+ }
+ ExFreePool(Header->NameInfo);
}
-
- if (Header->Name.Buffer != NULL)
+ if (Header->ObjectCreateInfo)
{
- ObpRemoveEntryDirectory(Header);
- RtlFreeUnicodeString(&Header->Name);
+ ObpReleaseCapturedAttributes(Header->ObjectCreateInfo);
+ ExFreePool(Header->ObjectCreateInfo);
}
DPRINT("ObPerformRetentionChecks() = Freeing object\n");
PRETENTION_CHECK_PARAMS Params = (PRETENTION_CHECK_PARAMS)Parameter;
/* ULONG Tag; */ /* See below */
- assert(Params);
- assert(KeGetCurrentIrql() == PASSIVE_LEVEL); /* We need PAGED_CODE somewhere... */
+ ASSERT(Params);
+ ASSERT(KeGetCurrentIrql() == PASSIVE_LEVEL); /* We need PAGED_CODE somewhere... */
/* Turn this on when we have ExFreePoolWithTag
Tag = Params->ObjectHeader->ObjectType->Tag; */
ObpDeleteObjectDpcLevel(IN POBJECT_HEADER ObjectHeader,
IN LONG OldRefCount)
{
+#if 0
if (ObjectHeader->RefCount < 0)
{
CPRINT("Object %p/%p has invalid reference count (%d)\n",
- ObjectHeader, HEADER_TO_BODY(ObjectHeader),
+ ObjectHeader, HEADER_TO_BODY(ObjectHeader),
ObjectHeader->RefCount);
KEBUGCHECK(0);
}
if (ObjectHeader->HandleCount < 0)
{
CPRINT("Object %p/%p has invalid handle count (%d)\n",
- ObjectHeader, HEADER_TO_BODY(ObjectHeader),
+ ObjectHeader, HEADER_TO_BODY(ObjectHeader),
ObjectHeader->HandleCount);
KEBUGCHECK(0);
}
+#endif
+
- if (ObjectHeader->CloseInProcess)
- {
- KEBUGCHECK(0);
- return STATUS_UNSUCCESSFUL;
- }
- ObjectHeader->CloseInProcess = TRUE;
-
switch (KeGetCurrentIrql ())
{
case PASSIVE_LEVEL:
return ObpDeleteObject (ObjectHeader);
-
+
case APC_LEVEL:
case DISPATCH_LEVEL:
{
PRETENTION_CHECK_PARAMS Params;
-
+
/*
We use must succeed pool here because if the allocation fails
then we leak memory.
Params = (PRETENTION_CHECK_PARAMS)
ExAllocatePoolWithTag(NonPagedPoolMustSucceed,
sizeof(RETENTION_CHECK_PARAMS),
- ObjectHeader->ObjectType->Tag);
+ ObjectHeader->ObjectType->Key);
Params->ObjectHeader = ObjectHeader;
ExInitializeWorkItem(&Params->WorkItem,
ObpDeleteObjectWorkRoutine,
CriticalWorkQueue);
}
return STATUS_PENDING;
-
+
default:
- DPRINT("ObpPerformRetentionChecksDpcLevel called at unsupported "
+ DPRINT("ObpDeleteObjectDpcLevel called at unsupported "
"IRQL %u!\n", KeGetCurrentIrql());
KEBUGCHECK(0);
return STATUS_UNSUCCESSFUL;
{
POBJECT_HEADER Header;
- assert(Object);
+ ASSERT(Object);
Header = BODY_TO_HEADER(Object);
/* No one should be referencing an object once we are deleting it. */
- if (Header->CloseInProcess)
- {
- KEBUGCHECK(0);
- }
+ if (InterlockedIncrement(&Header->RefCount) == 1 && !Header->Permanent)
+ {
+ KEBUGCHECK(0);
+ }
- (VOID)InterlockedIncrement(&Header->RefCount);
}
-
/**********************************************************************
* NAME EXPORTED
* ObfDereferenceObject@4
POBJECT_HEADER Header;
LONG NewRefCount;
BOOL Permanent;
- ULONG HandleCount;
- assert(Object);
+ ASSERT(Object);
/* Extract the object header. */
Header = BODY_TO_HEADER(Object);
Permanent = Header->Permanent;
- HandleCount = Header->HandleCount;
- /*
+ /*
Drop our reference and get the new count so we can tell if this was the
last reference.
*/
NewRefCount = InterlockedDecrement(&Header->RefCount);
- assert(NewRefCount >= 0);
+ DPRINT("ObfDereferenceObject(0x%x)==%d\n", Object, NewRefCount);
+ ASSERT(NewRefCount >= 0);
/* Check whether the object can now be deleted. */
if (NewRefCount == 0 &&
- HandleCount == 0 &&
!Permanent)
{
ObpDeleteObjectDpcLevel(Header, NewRefCount);
}
}
+VOID
+FASTCALL
+ObInitializeFastReference(IN PEX_FAST_REF FastRef,
+ PVOID Object)
+{
+ /* FIXME: Fast Referencing is Unimplemented */
+ FastRef->Object = Object;
+}
+
+
+PVOID
+FASTCALL
+ObFastReferenceObject(IN PEX_FAST_REF FastRef)
+{
+ /* FIXME: Fast Referencing is Unimplemented */
+
+ /* Do a normal Reference */
+ ObReferenceObject(FastRef->Object);
+
+ /* Return the Object */
+ return FastRef->Object;
+}
+
+VOID
+FASTCALL
+ObFastDereferenceObject(IN PEX_FAST_REF FastRef,
+ PVOID Object)
+{
+ /* FIXME: Fast Referencing is Unimplemented */
+
+ /* Do a normal Dereference */
+ ObDereferenceObject(FastRef->Object);
+}
+
+PVOID
+FASTCALL
+ObFastReplaceObject(IN PEX_FAST_REF FastRef,
+ PVOID Object)
+{
+ PVOID OldObject = FastRef->Object;
+
+ /* FIXME: Fast Referencing is Unimplemented */
+ FastRef->Object = Object;
+
+ /* Do a normal Dereference */
+ ObDereferenceObject(OldObject);
+
+ /* Return old Object*/
+ return OldObject;
+}
/**********************************************************************
* NAME EXPORTED
{
POBJECT_HEADER Header;
- assert(Object);
+ PAGED_CODE();
+
+ ASSERT(Object);
Header = BODY_TO_HEADER(Object);
- return(Header->RefCount);
+ return Header->RefCount;
}
{
POBJECT_HEADER Header;
- assert(Object);
+ PAGED_CODE();
+
+ ASSERT(Object);
Header = BODY_TO_HEADER(Object);
- return(Header->HandleCount);
+ return Header->HandleCount;
}