2 * PROJECT: ReactOS Kernel
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: ntoskrnl/ob/oblife.c
5 * PURPOSE: Manages the lifetime of an Object, including its creation,
6 * and deletion, as well as setting or querying any of its
7 * information while it is active. Since Object Types are also
8 * Objects, those are also managed here.
9 * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
11 * Thomas Weidenmueller (w3seek@reactos.org)
14 /* INCLUDES ******************************************************************/
20 extern ULONG NtGlobalFlag
;
22 POBJECT_TYPE ObpTypeObjectType
= NULL
;
23 KEVENT ObpDefaultObject
;
24 KGUARDED_MUTEX ObpDeviceMapLock
;
26 GENERAL_LOOKASIDE ObpNameBufferLookasideList
, ObpCreateInfoLookasideList
;
28 WORK_QUEUE_ITEM ObpReaperWorkItem
;
29 volatile PVOID ObpReaperList
;
31 ULONG ObpObjectsCreated
, ObpObjectsWithName
, ObpObjectsWithPoolQuota
;
32 ULONG ObpObjectsWithHandleDB
, ObpObjectsWithCreatorInfo
;
33 POBJECT_TYPE ObpObjectTypes
[32];
35 /* PRIVATE FUNCTIONS *********************************************************/
39 ObpDeallocateObject(IN PVOID Object
)
42 POBJECT_HEADER Header
;
43 POBJECT_TYPE ObjectType
;
44 POBJECT_HEADER_HANDLE_INFO HandleInfo
;
45 POBJECT_HEADER_NAME_INFO NameInfo
;
46 POBJECT_HEADER_CREATOR_INFO CreatorInfo
;
47 POBJECT_HEADER_QUOTA_INFO QuotaInfo
;
48 ULONG PagedPoolCharge
, NonPagedPoolCharge
;
51 /* Get the header and assume this is what we'll free */
52 Header
= OBJECT_TO_OBJECT_HEADER(Object
);
53 ObjectType
= Header
->Type
;
54 HeaderLocation
= Header
;
56 /* To find the header, walk backwards from how we allocated */
57 if ((CreatorInfo
= OBJECT_HEADER_TO_CREATOR_INFO(Header
)))
59 HeaderLocation
= CreatorInfo
;
61 if ((NameInfo
= OBJECT_HEADER_TO_NAME_INFO(Header
)))
63 HeaderLocation
= NameInfo
;
65 if ((HandleInfo
= OBJECT_HEADER_TO_HANDLE_INFO(Header
)))
67 HeaderLocation
= HandleInfo
;
69 if ((QuotaInfo
= OBJECT_HEADER_TO_QUOTA_INFO(Header
)))
71 HeaderLocation
= QuotaInfo
;
74 /* Decrease the total */
75 InterlockedDecrement((PLONG
)&ObjectType
->TotalNumberOfObjects
);
77 /* Check if we have create info */
78 if (Header
->Flags
& OB_FLAG_CREATE_INFO
)
80 /* Double-check that it exists */
81 if (Header
->ObjectCreateInfo
)
84 ObpFreeObjectCreateInformation(Header
->ObjectCreateInfo
);
85 Header
->ObjectCreateInfo
= NULL
;
90 /* Check if it has a quota block */
91 if (Header
->QuotaBlockCharged
)
93 /* Check if we have quota information */
96 /* Get charges from quota information */
97 PagedPoolCharge
= QuotaInfo
->PagedPoolCharge
+
98 QuotaInfo
->SecurityDescriptorCharge
;
99 NonPagedPoolCharge
= QuotaInfo
->NonPagedPoolCharge
;
103 /* Get charges from object type */
104 PagedPoolCharge
= ObjectType
->TypeInfo
.DefaultPagedPoolCharge
;
105 NonPagedPoolCharge
= ObjectType
->
106 TypeInfo
.DefaultNonPagedPoolCharge
;
108 /* Add the SD charge too */
109 if (Header
->Flags
& OB_FLAG_SECURITY
) PagedPoolCharge
+= 2048;
112 /* Return the quota */
113 DPRINT("FIXME: Should return quotas: %lx %lx\n", PagedPoolCharge
, NonPagedPoolCharge
);
115 PsReturnSharedPoolQuota(ObjectHeader
->QuotaBlockCharged
,
123 /* Check if a handle database was active */
124 if ((HandleInfo
) && !(Header
->Flags
& OB_FLAG_SINGLE_PROCESS
))
127 ExFreePool(HandleInfo
->HandleCountDatabase
);
128 HandleInfo
->HandleCountDatabase
= NULL
;
131 /* Check if we have a name */
132 if ((NameInfo
) && (NameInfo
->Name
.Buffer
))
135 ExFreePool(NameInfo
->Name
.Buffer
);
136 NameInfo
->Name
.Buffer
= NULL
;
139 /* Catch invalid access */
140 Header
->Type
= (POBJECT_TYPE
)0xBAADB0B0;
142 /* Free the object using the same allocation tag */
143 ExFreePoolWithTag(HeaderLocation
, ObjectType
->Key
);
148 ObpDeleteObject(IN PVOID Object
,
149 IN BOOLEAN CalledFromWorkerThread
)
151 POBJECT_HEADER Header
;
152 POBJECT_TYPE ObjectType
;
153 POBJECT_HEADER_NAME_INFO NameInfo
;
154 POBJECT_HEADER_CREATOR_INFO CreatorInfo
;
158 /* Get the header and type */
159 Header
= OBJECT_TO_OBJECT_HEADER(Object
);
160 ObjectType
= Header
->Type
;
162 /* Get creator and name information */
163 NameInfo
= OBJECT_HEADER_TO_NAME_INFO(Header
);
164 CreatorInfo
= OBJECT_HEADER_TO_CREATOR_INFO(Header
);
166 /* Check if the object is on a type list */
167 if ((CreatorInfo
) && !(IsListEmpty(&CreatorInfo
->TypeList
)))
169 /* Lock the object type */
170 ObpEnterObjectTypeMutex(ObjectType
);
172 /* Remove the object from the type list */
173 RemoveEntryList(&CreatorInfo
->TypeList
);
175 /* Release the lock */
176 ObpLeaveObjectTypeMutex(ObjectType
);
179 /* Check if we have a name */
180 if ((NameInfo
) && (NameInfo
->Name
.Buffer
))
183 ExFreePool(NameInfo
->Name
.Buffer
);
184 RtlInitEmptyUnicodeString(&NameInfo
->Name
, NULL
, 0);
187 /* Check if we have a security descriptor */
188 if (Header
->SecurityDescriptor
)
190 /* Call the security procedure to delete it */
191 ObpCalloutStart(&CalloutIrql
);
192 ObjectType
->TypeInfo
.SecurityProcedure(Object
,
193 DeleteSecurityDescriptor
,
197 &Header
->SecurityDescriptor
,
200 ObpCalloutEnd(CalloutIrql
, "Security", ObjectType
, Object
);
203 /* Check if we have a delete procedure */
204 if (ObjectType
->TypeInfo
.DeleteProcedure
)
206 /* Save whether we were deleted from worker thread or not */
207 if (!CalledFromWorkerThread
) Header
->Flags
|= OB_FLAG_DEFER_DELETE
;
210 ObpCalloutStart(&CalloutIrql
);
211 ObjectType
->TypeInfo
.DeleteProcedure(Object
);
212 ObpCalloutEnd(CalloutIrql
, "Delete", ObjectType
, Object
);
215 /* Now de-allocate all object members */
216 ObpDeallocateObject(Object
);
221 ObpReapObject(IN PVOID Parameter
)
223 POBJECT_HEADER ReapObject
, NextObject
;
228 /* Get the reap object */
229 ReapObject
= InterlockedExchangePointer(&ObpReaperList
, (PVOID
)1);
231 /* Start deletion loop */
234 /* Get the next object */
235 NextObject
= ReapObject
->NextToFree
;
237 /* Delete the object */
238 ObpDeleteObject(&ReapObject
->Body
, TRUE
);
240 /* Move to the next one */
241 ReapObject
= NextObject
;
242 } while ((ReapObject
) && (ReapObject
!= (PVOID
)1));
243 } while ((ObpReaperList
!= (PVOID
)1) ||
244 (InterlockedCompareExchange((PLONG
)&ObpReaperList
, 0, 1) != 1));
248 * @name ObpSetPermanentObject
250 * The ObpSetPermanentObject routine makes an sets or clears the permanent
251 * flag of an object, thus making it either permanent or temporary.
254 * Pointer to the object to make permanent or temporary.
257 * Flag specifying which operation to perform.
261 * @remarks If the object is being made temporary, then it will be checked
262 * as a candidate for immediate removal from the namespace.
267 ObpSetPermanentObject(IN PVOID ObjectBody
,
268 IN BOOLEAN Permanent
)
270 POBJECT_HEADER ObjectHeader
;
273 ObjectHeader
= OBJECT_TO_OBJECT_HEADER(ObjectBody
);
275 /* Acquire object lock */
276 ObpAcquireObjectLock(ObjectHeader
);
278 /* Check what we're doing to it */
281 /* Set it to permanent */
282 ObjectHeader
->Flags
|= OB_FLAG_PERMANENT
;
284 /* Release the lock */
285 ObpReleaseObjectLock(ObjectHeader
);
289 /* Remove the flag */
290 ObjectHeader
->Flags
&= ~OB_FLAG_PERMANENT
;
292 /* Release the lock */
293 ObpReleaseObjectLock(ObjectHeader
);
295 /* Check if we should delete the object now */
296 ObpDeleteNameCheck(ObjectBody
);
302 ObpAllocateObjectNameBuffer(IN ULONG Length
,
303 IN BOOLEAN UseLookaside
,
304 IN OUT PUNICODE_STRING ObjectName
)
309 /* Set the maximum length to the length plus the terminator */
310 MaximumLength
= Length
+ sizeof(UNICODE_NULL
);
312 /* Check if we should use the lookaside buffer */
313 if (!(UseLookaside
) || (MaximumLength
> OBP_NAME_LOOKASIDE_MAX_SIZE
))
315 /* Nope, allocate directly from pool */
316 /* Since we later use MaximumLength to detect that we're not allocating
317 * from a list, we need at least MaximumLength + sizeof(UNICODE_NULL)
320 * People do call this with UseLookasideList FALSE so the distinction
323 if (MaximumLength
<= OBP_NAME_LOOKASIDE_MAX_SIZE
)
325 MaximumLength
= OBP_NAME_LOOKASIDE_MAX_SIZE
+ sizeof(UNICODE_NULL
);
327 Buffer
= ExAllocatePoolWithTag(PagedPool
,
333 /* Allocate from the lookaside */
334 MaximumLength
= OBP_NAME_LOOKASIDE_MAX_SIZE
;
335 Buffer
= ObpAllocateObjectCreateInfoBuffer(LookasideNameBufferList
);
338 /* Setup the string */
339 ObjectName
->MaximumLength
= (USHORT
)MaximumLength
;
340 ObjectName
->Length
= (USHORT
)Length
;
341 ObjectName
->Buffer
= Buffer
;
347 ObpFreeObjectNameBuffer(IN PUNICODE_STRING Name
)
349 PVOID Buffer
= Name
->Buffer
;
351 /* We know this is a pool-allocation if the size doesn't match */
352 if (Name
->MaximumLength
!= OBP_NAME_LOOKASIDE_MAX_SIZE
)
355 * Free it from the pool.
357 * We cannot use here ExFreePoolWithTag(..., OB_NAME_TAG); , because
358 * the object name may have been massaged during operation by different
359 * object parse routines. If the latter ones have to resolve a symbolic
360 * link (e.g. as is done by CmpParseKey() and CmpGetSymbolicLink()),
361 * the original object name is freed and re-allocated from the pool,
362 * possibly with a different pool tag. At the end of the day, the new
363 * object name can be reallocated and completely different, but we
364 * should still be able to free it!
370 /* Otherwise, free from the lookaside */
371 ObpFreeCapturedAttributes(Buffer
, LookasideNameBufferList
);
377 ObpCaptureObjectName(IN OUT PUNICODE_STRING CapturedName
,
378 IN PUNICODE_STRING ObjectName
,
379 IN KPROCESSOR_MODE AccessMode
,
380 IN BOOLEAN UseLookaside
)
382 NTSTATUS Status
= STATUS_SUCCESS
;
384 PWCHAR _SEH2_VOLATILE StringBuffer
= NULL
;
385 UNICODE_STRING LocalName
;
388 /* Initialize the Input String */
389 RtlInitEmptyUnicodeString(CapturedName
, NULL
, 0);
391 /* Protect everything */
394 /* Check if we came from user mode */
395 if (AccessMode
!= KernelMode
)
397 /* First Probe the String */
398 LocalName
= ProbeForReadUnicodeString(ObjectName
);
399 ProbeForRead(LocalName
.Buffer
, LocalName
.Length
, sizeof(WCHAR
));
403 /* No probing needed */
404 LocalName
= *ObjectName
;
407 /* Make sure there really is a string */
408 if ((StringLength
= LocalName
.Length
))
410 /* Check that the size is a valid WCHAR multiple */
411 if ((StringLength
& (sizeof(WCHAR
) - 1)) ||
412 /* Check that the NULL-termination below will work */
413 (StringLength
== (MAXUSHORT
- sizeof(UNICODE_NULL
) + 1)))
415 /* PS: Please keep the checks above expanded for clarity */
416 Status
= STATUS_OBJECT_NAME_INVALID
;
420 /* Allocate the string buffer */
421 StringBuffer
= ObpAllocateObjectNameBuffer(StringLength
,
426 /* Set failure code */
427 Status
= STATUS_INSUFFICIENT_RESOURCES
;
432 RtlCopyMemory(StringBuffer
, LocalName
.Buffer
, StringLength
);
433 StringBuffer
[StringLength
/ sizeof(WCHAR
)] = UNICODE_NULL
;
438 _SEH2_EXCEPT(ExSystemExceptionFilter())
440 /* Handle exception and free the string buffer */
441 Status
= _SEH2_GetExceptionCode();
444 ObpFreeObjectNameBuffer(CapturedName
);
455 ObpCaptureObjectCreateInformation(IN POBJECT_ATTRIBUTES ObjectAttributes
,
456 IN KPROCESSOR_MODE AccessMode
,
457 IN KPROCESSOR_MODE CreatorMode
,
458 IN BOOLEAN AllocateFromLookaside
,
459 IN POBJECT_CREATE_INFORMATION ObjectCreateInfo
,
460 OUT PUNICODE_STRING ObjectName
)
462 NTSTATUS Status
= STATUS_SUCCESS
;
463 PSECURITY_DESCRIPTOR SecurityDescriptor
;
464 PSECURITY_QUALITY_OF_SERVICE SecurityQos
;
465 PUNICODE_STRING LocalObjectName
= NULL
;
468 /* Zero out the Capture Data */
469 RtlZeroMemory(ObjectCreateInfo
, sizeof(OBJECT_CREATE_INFORMATION
));
471 /* SEH everything here for protection */
474 /* Check if we got attributes */
475 if (ObjectAttributes
)
477 /* Check if we're in user mode */
478 if (AccessMode
!= KernelMode
)
480 /* Probe the attributes */
481 ProbeForRead(ObjectAttributes
,
482 sizeof(OBJECT_ATTRIBUTES
),
486 /* Validate the Size and Attributes */
487 if ((ObjectAttributes
->Length
!= sizeof(OBJECT_ATTRIBUTES
)) ||
488 (ObjectAttributes
->Attributes
& ~OBJ_VALID_KERNEL_ATTRIBUTES
))
490 /* Invalid combination, fail */
491 _SEH2_YIELD(return STATUS_INVALID_PARAMETER
);
494 /* Set some Create Info and do not allow user-mode kernel handles */
495 ObjectCreateInfo
->RootDirectory
= ObjectAttributes
->RootDirectory
;
496 ObjectCreateInfo
->Attributes
= ObjectAttributes
->Attributes
& OBJ_VALID_KERNEL_ATTRIBUTES
;
497 if (CreatorMode
!= KernelMode
) ObjectCreateInfo
->Attributes
&= ~OBJ_KERNEL_HANDLE
;
498 LocalObjectName
= ObjectAttributes
->ObjectName
;
499 SecurityDescriptor
= ObjectAttributes
->SecurityDescriptor
;
500 SecurityQos
= ObjectAttributes
->SecurityQualityOfService
;
502 /* Check if we have a security descriptor */
503 if (SecurityDescriptor
)
505 /* Capture it. Note: This has an implicit memory barrier due
506 to the function call, so cleanup is safe here.) */
507 Status
= SeCaptureSecurityDescriptor(SecurityDescriptor
,
513 if (!NT_SUCCESS(Status
))
515 /* Capture failed, quit */
516 ObjectCreateInfo
->SecurityDescriptor
= NULL
;
517 _SEH2_YIELD(return Status
);
520 /* Save the probe mode and security descriptor size */
521 ObjectCreateInfo
->SecurityDescriptorCharge
= 2048; /* FIXME */
522 ObjectCreateInfo
->ProbeMode
= AccessMode
;
525 /* Check if we have QoS */
528 /* Check if we came from user mode */
529 if (AccessMode
!= KernelMode
)
531 /* Validate the QoS */
532 ProbeForRead(SecurityQos
,
533 sizeof(SECURITY_QUALITY_OF_SERVICE
),
538 ObjectCreateInfo
->SecurityQualityOfService
= *SecurityQos
;
539 ObjectCreateInfo
->SecurityQos
=
540 &ObjectCreateInfo
->SecurityQualityOfService
;
545 /* We don't have a name */
546 LocalObjectName
= NULL
;
549 _SEH2_EXCEPT(ExSystemExceptionFilter())
551 /* Cleanup and return the exception code */
552 ObpReleaseObjectCreateInformation(ObjectCreateInfo
);
553 _SEH2_YIELD(return _SEH2_GetExceptionCode());
557 /* Now check if the Object Attributes had an Object Name */
560 Status
= ObpCaptureObjectName(ObjectName
,
563 AllocateFromLookaside
);
567 /* Clear the string */
568 RtlInitEmptyUnicodeString(ObjectName
, NULL
, 0);
570 /* It cannot have specified a Root Directory */
571 if (ObjectCreateInfo
->RootDirectory
)
573 Status
= STATUS_OBJECT_NAME_INVALID
;
577 /* Cleanup if we failed */
578 if (!NT_SUCCESS(Status
))
580 ObpReleaseObjectCreateInformation(ObjectCreateInfo
);
583 /* Return status to caller */
589 ObFreeObjectCreateInfoBuffer(IN POBJECT_CREATE_INFORMATION ObjectCreateInfo
)
591 /* Call the macro. We use this function to isolate Ob internals from Io */
592 ObpFreeCapturedAttributes(ObjectCreateInfo
, LookasideCreateInfoList
);
597 ObpAllocateObject(IN POBJECT_CREATE_INFORMATION ObjectCreateInfo
,
598 IN PUNICODE_STRING ObjectName
,
599 IN POBJECT_TYPE ObjectType
,
601 IN KPROCESSOR_MODE PreviousMode
,
602 IN POBJECT_HEADER
*ObjectHeader
)
604 POBJECT_HEADER Header
;
605 ULONG QuotaSize
, HandleSize
, NameSize
, CreatorSize
;
606 POBJECT_HEADER_HANDLE_INFO HandleInfo
;
607 POBJECT_HEADER_NAME_INFO NameInfo
;
608 POBJECT_HEADER_CREATOR_INFO CreatorInfo
;
609 POBJECT_HEADER_QUOTA_INFO QuotaInfo
;
618 /* Check if we don't have an Object Type yet */
621 /* Use default tag and non-paged pool */
622 PoolType
= NonPagedPool
;
627 /* Use the pool and tag given */
628 PoolType
= ObjectType
->TypeInfo
.PoolType
;
629 Tag
= ObjectType
->Key
;
632 /* Check if we have no create information (ie: we're an object type) */
633 if (!ObjectCreateInfo
)
636 QuotaSize
= HandleSize
= 0;
637 NameSize
= sizeof(OBJECT_HEADER_NAME_INFO
);
638 CreatorSize
= sizeof(OBJECT_HEADER_CREATOR_INFO
);
642 /* Check if we have quota */
643 if ((((ObjectCreateInfo
->PagedPoolCharge
!=
644 ObjectType
->TypeInfo
.DefaultPagedPoolCharge
) ||
645 (ObjectCreateInfo
->NonPagedPoolCharge
!=
646 ObjectType
->TypeInfo
.DefaultNonPagedPoolCharge
) ||
647 (ObjectCreateInfo
->SecurityDescriptorCharge
> 2048)) &&
648 (PsGetCurrentProcess() != PsInitialSystemProcess
)) ||
649 (ObjectCreateInfo
->Attributes
& OBJ_EXCLUSIVE
))
652 QuotaSize
= sizeof(OBJECT_HEADER_QUOTA_INFO
);
653 ObpObjectsWithPoolQuota
++;
661 /* Check if we have a handle database */
662 if (ObjectType
->TypeInfo
.MaintainHandleCount
)
664 /* Set handle database size */
665 HandleSize
= sizeof(OBJECT_HEADER_HANDLE_INFO
);
666 ObpObjectsWithHandleDB
++;
674 /* Check if the Object has a name */
675 if (ObjectName
->Buffer
)
678 NameSize
= sizeof(OBJECT_HEADER_NAME_INFO
);
679 ObpObjectsWithName
++;
687 /* Check if the Object maintains type lists */
688 if (ObjectType
->TypeInfo
.MaintainTypeList
)
690 /* Set owner/creator size */
691 CreatorSize
= sizeof(OBJECT_HEADER_CREATOR_INFO
);
692 ObpObjectsWithCreatorInfo
++;
701 /* Set final header size */
702 FinalSize
= QuotaSize
+
706 FIELD_OFFSET(OBJECT_HEADER
, Body
);
708 /* Allocate memory for the Object and Header */
709 Header
= ExAllocatePoolWithTag(PoolType
, FinalSize
+ ObjectSize
, Tag
);
710 if (!Header
) return STATUS_INSUFFICIENT_RESOURCES
;
712 /* Check if we have a quota header */
715 /* Initialize quota info */
716 QuotaInfo
= (POBJECT_HEADER_QUOTA_INFO
)Header
;
717 QuotaInfo
->PagedPoolCharge
= ObjectCreateInfo
->PagedPoolCharge
;
718 QuotaInfo
->NonPagedPoolCharge
= ObjectCreateInfo
->NonPagedPoolCharge
;
719 QuotaInfo
->SecurityDescriptorCharge
= ObjectCreateInfo
->SecurityDescriptorCharge
;
720 QuotaInfo
->ExclusiveProcess
= NULL
;
721 Header
= (POBJECT_HEADER
)(QuotaInfo
+ 1);
724 /* Check if we have a handle database header */
727 /* Initialize Handle Info */
728 HandleInfo
= (POBJECT_HEADER_HANDLE_INFO
)Header
;
729 HandleInfo
->SingleEntry
.HandleCount
= 0;
730 Header
= (POBJECT_HEADER
)(HandleInfo
+ 1);
733 /* Check if we have a name header */
736 /* Initialize the Object Name Info */
737 NameInfo
= (POBJECT_HEADER_NAME_INFO
)Header
;
738 NameInfo
->Name
= *ObjectName
;
739 NameInfo
->Directory
= NULL
;
740 NameInfo
->QueryReferences
= 1;
742 /* Check if this is a call with the special protection flag */
743 if ((PreviousMode
== KernelMode
) &&
744 (ObjectCreateInfo
) &&
745 (ObjectCreateInfo
->Attributes
& OBJ_KERNEL_EXCLUSIVE
))
747 /* Set flag which will make the object protected from user-mode */
748 NameInfo
->QueryReferences
|= OB_FLAG_KERNEL_EXCLUSIVE
;
751 /* Set the header pointer */
752 Header
= (POBJECT_HEADER
)(NameInfo
+ 1);
755 /* Check if we have a creator header */
758 /* Initialize Creator Info */
759 CreatorInfo
= (POBJECT_HEADER_CREATOR_INFO
)Header
;
760 CreatorInfo
->CreatorBackTraceIndex
= 0;
761 CreatorInfo
->CreatorUniqueProcess
= PsGetCurrentProcessId();
762 InitializeListHead(&CreatorInfo
->TypeList
);
763 Header
= (POBJECT_HEADER
)(CreatorInfo
+ 1);
766 /* Check for quota information */
770 Header
->QuotaInfoOffset
= (UCHAR
)(QuotaSize
+
778 Header
->QuotaInfoOffset
= 0;
781 /* Check for handle information */
785 Header
->HandleInfoOffset
= (UCHAR
)(HandleSize
+
792 Header
->HandleInfoOffset
= 0;
795 /* Check for name information */
799 Header
->NameInfoOffset
= (UCHAR
)(NameSize
+ CreatorSize
);
804 Header
->NameInfoOffset
= 0;
807 /* Set the new object flag */
808 Header
->Flags
= OB_FLAG_CREATE_INFO
;
810 /* Remember if we have creator info */
811 if (CreatorSize
) Header
->Flags
|= OB_FLAG_CREATOR_INFO
;
813 /* Remember if we have handle info */
814 if (HandleSize
) Header
->Flags
|= OB_FLAG_SINGLE_PROCESS
;
816 /* Initialize the object header */
817 Header
->PointerCount
= 1;
818 Header
->HandleCount
= 0;
819 Header
->Type
= ObjectType
;
820 Header
->ObjectCreateInfo
= ObjectCreateInfo
;
821 Header
->SecurityDescriptor
= NULL
;
823 /* Check if this is a permanent object */
824 if ((ObjectCreateInfo
) && (ObjectCreateInfo
->Attributes
& OBJ_PERMANENT
))
826 /* Set the needed flag so we can check */
827 Header
->Flags
|= OB_FLAG_PERMANENT
;
830 /* Check if this is an exclusive object */
831 if ((ObjectCreateInfo
) && (ObjectCreateInfo
->Attributes
& OBJ_EXCLUSIVE
))
833 /* Set the needed flag so we can check */
834 Header
->Flags
|= OB_FLAG_EXCLUSIVE
;
837 /* Set kernel-mode flag */
838 if (PreviousMode
== KernelMode
) Header
->Flags
|= OB_FLAG_KERNEL_MODE
;
840 /* Check if we have a type */
843 /* Increase the number of objects of this type */
844 InterlockedIncrement((PLONG
)&ObjectType
->TotalNumberOfObjects
);
846 /* Update the high water */
847 ObjectType
->HighWaterNumberOfObjects
= max(ObjectType
->
848 TotalNumberOfObjects
,
850 HighWaterNumberOfObjects
);
854 *ObjectHeader
= Header
;
855 return STATUS_SUCCESS
;
860 ObQueryTypeInfo(IN POBJECT_TYPE ObjectType
,
861 OUT POBJECT_TYPE_INFORMATION ObjectTypeInfo
,
863 OUT PULONG ReturnLength
)
865 NTSTATUS Status
= STATUS_SUCCESS
;
871 /* Set return length aligned to 4-byte boundary */
872 *ReturnLength
+= sizeof(*ObjectTypeInfo
) +
873 ALIGN_UP(ObjectType
->Name
.MaximumLength
, ULONG
);
875 /* Check if thats too much though. */
876 if (Length
< *ReturnLength
)
878 _SEH2_YIELD(return STATUS_INFO_LENGTH_MISMATCH
);
882 ObjectTypeInfo
->TotalNumberOfHandles
=
883 ObjectType
->TotalNumberOfHandles
;
884 ObjectTypeInfo
->TotalNumberOfObjects
=
885 ObjectType
->TotalNumberOfObjects
;
886 ObjectTypeInfo
->HighWaterNumberOfHandles
=
887 ObjectType
->HighWaterNumberOfHandles
;
888 ObjectTypeInfo
->HighWaterNumberOfObjects
=
889 ObjectType
->HighWaterNumberOfObjects
;
890 ObjectTypeInfo
->PoolType
=
891 ObjectType
->TypeInfo
.PoolType
;
892 ObjectTypeInfo
->DefaultNonPagedPoolCharge
=
893 ObjectType
->TypeInfo
.DefaultNonPagedPoolCharge
;
894 ObjectTypeInfo
->DefaultPagedPoolCharge
=
895 ObjectType
->TypeInfo
.DefaultPagedPoolCharge
;
896 ObjectTypeInfo
->ValidAccessMask
=
897 ObjectType
->TypeInfo
.ValidAccessMask
;
898 ObjectTypeInfo
->SecurityRequired
=
899 ObjectType
->TypeInfo
.SecurityRequired
;
900 ObjectTypeInfo
->InvalidAttributes
=
901 ObjectType
->TypeInfo
.InvalidAttributes
;
902 ObjectTypeInfo
->GenericMapping
=
903 ObjectType
->TypeInfo
.GenericMapping
;
904 ObjectTypeInfo
->MaintainHandleCount
=
905 ObjectType
->TypeInfo
.MaintainHandleCount
;
907 /* Setup the name buffer */
908 InfoBuffer
= (PWSTR
)(ObjectTypeInfo
+ 1);
909 ObjectTypeInfo
->TypeName
.Buffer
= InfoBuffer
;
910 ObjectTypeInfo
->TypeName
.MaximumLength
= ObjectType
->Name
.MaximumLength
;
911 ObjectTypeInfo
->TypeName
.Length
= ObjectType
->Name
.Length
;
914 RtlCopyMemory(InfoBuffer
,
915 ObjectType
->Name
.Buffer
,
916 ObjectType
->Name
.Length
);
918 /* Null-terminate it */
919 (InfoBuffer
)[ObjectType
->Name
.Length
/ sizeof(WCHAR
)] = UNICODE_NULL
;
921 _SEH2_EXCEPT(ExSystemExceptionFilter())
923 /* Otherwise, get the exception code */
924 Status
= _SEH2_GetExceptionCode();
928 /* Return status to caller */
933 /* PUBLIC FUNCTIONS **********************************************************/
937 ObCreateObject(IN KPROCESSOR_MODE ProbeMode OPTIONAL
,
938 IN POBJECT_TYPE Type
,
939 IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL
,
940 IN KPROCESSOR_MODE AccessMode
,
941 IN OUT PVOID ParseContext OPTIONAL
,
943 IN ULONG PagedPoolCharge OPTIONAL
,
944 IN ULONG NonPagedPoolCharge OPTIONAL
,
948 POBJECT_CREATE_INFORMATION ObjectCreateInfo
;
949 UNICODE_STRING ObjectName
;
950 POBJECT_HEADER Header
;
952 /* Allocate a capture buffer */
953 ObjectCreateInfo
= ObpAllocateObjectCreateInfoBuffer(LookasideCreateInfoList
);
954 if (!ObjectCreateInfo
) return STATUS_INSUFFICIENT_RESOURCES
;
956 /* Capture all the info */
957 Status
= ObpCaptureObjectCreateInformation(ObjectAttributes
,
963 if (NT_SUCCESS(Status
))
965 /* Validate attributes */
966 if (Type
->TypeInfo
.InvalidAttributes
& ObjectCreateInfo
->Attributes
)
969 Status
= STATUS_INVALID_PARAMETER
;
973 /* Check if we have a paged charge */
974 if (!PagedPoolCharge
)
977 PagedPoolCharge
= Type
->TypeInfo
.DefaultPagedPoolCharge
;
980 /* Check for nonpaged charge */
981 if (!NonPagedPoolCharge
)
984 NonPagedPoolCharge
= Type
->TypeInfo
.DefaultNonPagedPoolCharge
;
987 /* Write the pool charges */
988 ObjectCreateInfo
->PagedPoolCharge
= PagedPoolCharge
;
989 ObjectCreateInfo
->NonPagedPoolCharge
= NonPagedPoolCharge
;
991 /* Allocate the Object */
992 Status
= ObpAllocateObject(ObjectCreateInfo
,
998 if (NT_SUCCESS(Status
))
1000 /* Return the Object */
1001 *Object
= &Header
->Body
;
1003 /* Check if this is a permanent object */
1004 if (Header
->Flags
& OB_FLAG_PERMANENT
)
1006 /* Do the privilege check */
1007 if (!SeSinglePrivilegeCheck(SeCreatePermanentPrivilege
,
1011 ObpDeallocateObject(*Object
);
1012 Status
= STATUS_PRIVILEGE_NOT_HELD
;
1021 /* Release the Capture Info, we don't need it */
1022 ObpFreeObjectCreateInformation(ObjectCreateInfo
);
1023 if (ObjectName
.Buffer
) ObpFreeObjectNameBuffer(&ObjectName
);
1026 /* We failed, so release the Buffer */
1027 ObpFreeCapturedAttributes(ObjectCreateInfo
, LookasideCreateInfoList
);
1033 ObCreateObjectType(IN PUNICODE_STRING TypeName
,
1034 IN POBJECT_TYPE_INITIALIZER ObjectTypeInitializer
,
1036 OUT POBJECT_TYPE
*ObjectType
)
1038 POBJECT_HEADER Header
;
1039 POBJECT_TYPE LocalObjectType
;
1042 OBP_LOOKUP_CONTEXT Context
;
1045 UNICODE_STRING ObjectName
;
1046 ANSI_STRING AnsiName
;
1047 POBJECT_HEADER_CREATOR_INFO CreatorInfo
;
1049 /* Verify parameters */
1051 !(TypeName
->Length
) ||
1052 (TypeName
->Length
% sizeof(WCHAR
)) ||
1053 !(ObjectTypeInitializer
) ||
1054 (ObjectTypeInitializer
->Length
!= sizeof(*ObjectTypeInitializer
)) ||
1055 (ObjectTypeInitializer
->InvalidAttributes
& ~OBJ_VALID_KERNEL_ATTRIBUTES
) ||
1056 (ObjectTypeInitializer
->MaintainHandleCount
&&
1057 (!(ObjectTypeInitializer
->OpenProcedure
) &&
1058 !ObjectTypeInitializer
->CloseProcedure
)) ||
1059 ((!ObjectTypeInitializer
->UseDefaultObject
) &&
1060 (ObjectTypeInitializer
->PoolType
!= NonPagedPool
)))
1063 return STATUS_INVALID_PARAMETER
;
1066 /* Make sure the name doesn't have a separator */
1067 p
= TypeName
->Buffer
;
1068 i
= TypeName
->Length
/ sizeof(WCHAR
);
1071 /* Check for one and fail */
1072 if (*p
++ == OBJ_NAME_PATH_SEPARATOR
) return STATUS_OBJECT_NAME_INVALID
;
1075 /* Setup a lookup context */
1076 ObpInitializeLookupContext(&Context
);
1078 /* Check if we've already created the directory of types */
1079 if (ObpTypeDirectoryObject
)
1081 /* Acquire the directory lock */
1082 ObpAcquireDirectoryLockExclusive(ObpTypeDirectoryObject
, &Context
);
1085 if (ObpLookupEntryDirectory(ObpTypeDirectoryObject
,
1087 OBJ_CASE_INSENSITIVE
,
1091 /* We have already created it, so fail */
1092 ObpReleaseLookupContext(&Context
);
1093 return STATUS_OBJECT_NAME_COLLISION
;
1097 /* Now make a copy of the object name */
1098 ObjectName
.Buffer
= ExAllocatePoolWithTag(PagedPool
,
1099 TypeName
->MaximumLength
,
1101 if (!ObjectName
.Buffer
)
1103 /* Out of memory, fail */
1104 ObpReleaseLookupContext(&Context
);
1105 return STATUS_INSUFFICIENT_RESOURCES
;
1108 /* Set the length and copy the name */
1109 ObjectName
.MaximumLength
= TypeName
->MaximumLength
;
1110 RtlCopyUnicodeString(&ObjectName
, TypeName
);
1112 /* Allocate the Object */
1113 Status
= ObpAllocateObject(NULL
,
1116 sizeof(OBJECT_TYPE
),
1119 if (!NT_SUCCESS(Status
))
1121 /* Free the name and fail */
1122 ObpReleaseLookupContext(&Context
);
1123 ExFreePool(ObjectName
.Buffer
);
1127 /* Setup the flags and name */
1128 LocalObjectType
= (POBJECT_TYPE
)&Header
->Body
;
1129 LocalObjectType
->Name
= ObjectName
;
1130 Header
->Flags
|= OB_FLAG_KERNEL_MODE
| OB_FLAG_PERMANENT
;
1132 /* Clear accounting data */
1133 LocalObjectType
->TotalNumberOfObjects
=
1134 LocalObjectType
->TotalNumberOfHandles
=
1135 LocalObjectType
->HighWaterNumberOfObjects
=
1136 LocalObjectType
->HighWaterNumberOfHandles
= 0;
1138 /* Check if this is the first Object Type */
1139 if (!ObpTypeObjectType
)
1141 /* It is, so set this as the type object */
1142 ObpTypeObjectType
= LocalObjectType
;
1143 Header
->Type
= ObpTypeObjectType
;
1145 /* Set the hard-coded key and object count */
1146 LocalObjectType
->TotalNumberOfObjects
= 1;
1147 LocalObjectType
->Key
= 'TjbO';
1151 /* Convert the tag to ASCII */
1152 Status
= RtlUnicodeStringToAnsiString(&AnsiName
, TypeName
, TRUE
);
1153 if (NT_SUCCESS(Status
))
1155 /* For every missing character, use a space */
1156 for (i
= 3; i
>= AnsiName
.Length
; i
--) AnsiName
.Buffer
[i
] = ' ';
1158 /* Set the key and free the converted name */
1159 LocalObjectType
->Key
= *(PULONG
)AnsiName
.Buffer
;
1160 RtlFreeAnsiString(&AnsiName
);
1164 /* Just copy the characters */
1165 LocalObjectType
->Key
= *(PULONG
)TypeName
->Buffer
;
1169 /* Set up the type information */
1170 LocalObjectType
->TypeInfo
= *ObjectTypeInitializer
;
1171 LocalObjectType
->TypeInfo
.PoolType
= ObjectTypeInitializer
->PoolType
;
1173 /* Check if we have to maintain a type list */
1174 if (NtGlobalFlag
& FLG_MAINTAIN_OBJECT_TYPELIST
)
1176 /* Enable support */
1177 LocalObjectType
->TypeInfo
.MaintainTypeList
= TRUE
;
1180 /* Calculate how much space our header'll take up */
1181 HeaderSize
= sizeof(OBJECT_HEADER
) +
1182 sizeof(OBJECT_HEADER_NAME_INFO
) +
1183 (ObjectTypeInitializer
->MaintainHandleCount
?
1184 sizeof(OBJECT_HEADER_HANDLE_INFO
) : 0);
1186 /* Check the pool type */
1187 if (ObjectTypeInitializer
->PoolType
== NonPagedPool
)
1189 /* Update the NonPaged Pool charge */
1190 LocalObjectType
->TypeInfo
.DefaultNonPagedPoolCharge
+= HeaderSize
;
1194 /* Update the Paged Pool charge */
1195 LocalObjectType
->TypeInfo
.DefaultPagedPoolCharge
+= HeaderSize
;
1198 /* All objects types need a security procedure */
1199 if (!ObjectTypeInitializer
->SecurityProcedure
)
1201 LocalObjectType
->TypeInfo
.SecurityProcedure
= SeDefaultObjectMethod
;
1204 /* Select the Wait Object */
1205 if (LocalObjectType
->TypeInfo
.UseDefaultObject
)
1207 /* Add the SYNCHRONIZE access mask since it's waitable */
1208 LocalObjectType
->TypeInfo
.ValidAccessMask
|= SYNCHRONIZE
;
1210 /* Use the "Default Object", a simple event */
1211 LocalObjectType
->DefaultObject
= &ObpDefaultObject
;
1213 /* The File Object gets an optimized hack so it can be waited on */
1214 else if ((TypeName
->Length
== 8) && !(wcscmp(TypeName
->Buffer
, L
"File")))
1216 /* Wait on the File Object's event directly */
1217 LocalObjectType
->DefaultObject
= (PVOID
)FIELD_OFFSET(FILE_OBJECT
,
1220 else if ((TypeName
->Length
== 24) && !(wcscmp(TypeName
->Buffer
, L
"WaitablePort")))
1222 /* Wait on the LPC Port's object directly */
1223 LocalObjectType
->DefaultObject
= (PVOID
)FIELD_OFFSET(LPCP_PORT_OBJECT
,
1228 /* No default Object */
1229 LocalObjectType
->DefaultObject
= NULL
;
1232 /* Initialize Object Type components */
1233 ExInitializeResourceLite(&LocalObjectType
->Mutex
);
1234 for (i
= 0; i
< 4; i
++)
1236 /* Initialize the object locks */
1237 ExInitializeResourceLite(&LocalObjectType
->ObjectLocks
[i
]);
1239 InitializeListHead(&LocalObjectType
->TypeList
);
1241 /* Lock the object type */
1242 ObpEnterObjectTypeMutex(ObpTypeObjectType
);
1244 /* Get creator info and insert it into the type list */
1245 CreatorInfo
= OBJECT_HEADER_TO_CREATOR_INFO(Header
);
1248 InsertTailList(&ObpTypeObjectType
->TypeList
,
1249 &CreatorInfo
->TypeList
);
1251 /* CORE-8423: Avoid inserting this a second time if someone creates a
1252 * handle to the object type (bug in Windows 2003) */
1253 Header
->Flags
&= ~OB_FLAG_CREATE_INFO
;
1256 /* Set the index and the entry into the object type array */
1257 LocalObjectType
->Index
= ObpTypeObjectType
->TotalNumberOfObjects
;
1259 ASSERT(LocalObjectType
->Index
!= 0);
1261 if (LocalObjectType
->Index
< RTL_NUMBER_OF(ObpObjectTypes
))
1263 /* It fits, insert it */
1264 ObpObjectTypes
[LocalObjectType
->Index
- 1] = LocalObjectType
;
1267 /* Release the object type */
1268 ObpLeaveObjectTypeMutex(ObpTypeObjectType
);
1270 /* Check if we're actually creating the directory object itself */
1271 if (!(ObpTypeDirectoryObject
) ||
1272 (ObpInsertEntryDirectory(ObpTypeDirectoryObject
, &Context
, Header
)))
1274 /* Check if the type directory exists */
1275 if (ObpTypeDirectoryObject
)
1278 ObReferenceObject(ObpTypeDirectoryObject
);
1281 /* Cleanup the lookup context */
1282 ObpReleaseLookupContext(&Context
);
1284 /* Return the object type and success */
1285 *ObjectType
= LocalObjectType
;
1286 return STATUS_SUCCESS
;
1289 /* If we got here, then we failed */
1290 ObpReleaseLookupContext(&Context
);
1291 return STATUS_INSUFFICIENT_RESOURCES
;
1296 ObDeleteCapturedInsertInfo(IN PVOID Object
)
1298 POBJECT_HEADER ObjectHeader
;
1301 /* Check if there is anything to free */
1302 ObjectHeader
= OBJECT_TO_OBJECT_HEADER(Object
);
1303 if ((ObjectHeader
->Flags
& OB_FLAG_CREATE_INFO
) &&
1304 (ObjectHeader
->ObjectCreateInfo
!= NULL
))
1306 /* Free the create info */
1307 ObpFreeObjectCreateInformation(ObjectHeader
->ObjectCreateInfo
);
1308 ObjectHeader
->ObjectCreateInfo
= NULL
;
1314 ObpDeleteObjectType(IN PVOID Object
)
1317 POBJECT_TYPE ObjectType
= (PVOID
)Object
;
1319 /* Loop our locks */
1320 for (i
= 0; i
< 4; i
++)
1322 /* Delete each one */
1323 ExDeleteResourceLite(&ObjectType
->ObjectLocks
[i
]);
1326 /* Delete our main mutex */
1327 ExDeleteResourceLite(&ObjectType
->Mutex
);
1331 * @name ObMakeTemporaryObject
1334 * The ObMakeTemporaryObject routine <FILLMEIN>
1346 ObMakeTemporaryObject(IN PVOID ObjectBody
)
1350 /* Call the internal API */
1351 ObpSetPermanentObject(ObjectBody
, FALSE
);
1355 * @name NtMakeTemporaryObject
1358 * The NtMakeTemporaryObject routine <FILLMEIN>
1360 * @param ObjectHandle
1363 * @return STATUS_SUCCESS or appropriate error value.
1370 NtMakeTemporaryObject(IN HANDLE ObjectHandle
)
1376 /* Reference the object for DELETE access */
1377 Status
= ObReferenceObjectByHandle(ObjectHandle
,
1380 KeGetPreviousMode(),
1383 if (Status
!= STATUS_SUCCESS
) return Status
;
1385 /* Set it as temporary and dereference it */
1386 ObpSetPermanentObject(ObjectBody
, FALSE
);
1387 ObDereferenceObject(ObjectBody
);
1388 return STATUS_SUCCESS
;
1392 * @name NtMakePermanentObject
1395 * The NtMakePermanentObject routine <FILLMEIN>
1397 * @param ObjectHandle
1400 * @return STATUS_SUCCESS or appropriate error value.
1407 NtMakePermanentObject(IN HANDLE ObjectHandle
)
1411 KPROCESSOR_MODE PreviousMode
= ExGetPreviousMode();
1414 /* Make sure that the caller has SeCreatePermanentPrivilege */
1415 Status
= SeSinglePrivilegeCheck(SeCreatePermanentPrivilege
,
1417 if (!NT_SUCCESS(Status
)) return STATUS_PRIVILEGE_NOT_HELD
;
1419 /* Reference the object */
1420 Status
= ObReferenceObjectByHandle(ObjectHandle
,
1426 if (Status
!= STATUS_SUCCESS
) return Status
;
1428 /* Set it as permanent and dereference it */
1429 ObpSetPermanentObject(ObjectBody
, TRUE
);
1430 ObDereferenceObject(ObjectBody
);
1431 return STATUS_SUCCESS
;
1435 * @name NtQueryObject
1438 * The NtQueryObject routine <FILLMEIN>
1440 * @param ObjectHandle
1443 * @param ObjectInformationClass
1446 * @param ObjectInformation
1452 * @param ResultLength
1455 * @return STATUS_SUCCESS or appropriate error value.
1462 NtQueryObject(IN HANDLE ObjectHandle
,
1463 IN OBJECT_INFORMATION_CLASS ObjectInformationClass
,
1464 OUT PVOID ObjectInformation
,
1466 OUT PULONG ResultLength OPTIONAL
)
1468 OBJECT_HANDLE_INFORMATION HandleInfo
;
1469 POBJECT_HEADER ObjectHeader
= NULL
;
1470 POBJECT_HANDLE_ATTRIBUTE_INFORMATION HandleFlags
;
1471 POBJECT_BASIC_INFORMATION BasicInfo
;
1472 ULONG InfoLength
= 0;
1473 PVOID Object
= NULL
;
1475 KPROCESSOR_MODE PreviousMode
= ExGetPreviousMode();
1478 /* Check if the caller is from user mode */
1479 if (PreviousMode
!= KernelMode
)
1481 /* Protect validation with SEH */
1484 /* Probe the input structure */
1485 ProbeForWrite(ObjectInformation
, Length
, sizeof(UCHAR
));
1487 /* If we have a result length, probe it too */
1488 if (ResultLength
) ProbeForWriteUlong(ResultLength
);
1490 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1492 /* Return the exception code */
1493 _SEH2_YIELD(return _SEH2_GetExceptionCode());
1499 * Make sure this isn't a generic type query, since the caller doesn't
1500 * have to give a handle for it
1502 if (ObjectInformationClass
!= ObjectTypesInformation
)
1504 /* Reference the object */
1505 Status
= ObReferenceObjectByHandle(ObjectHandle
,
1508 KeGetPreviousMode(),
1511 if (!NT_SUCCESS (Status
)) return Status
;
1513 /* Get the object header */
1514 ObjectHeader
= OBJECT_TO_OBJECT_HEADER(Object
);
1519 /* Check the information class */
1520 switch (ObjectInformationClass
)
1523 case ObjectBasicInformation
:
1525 /* Validate length */
1526 InfoLength
= sizeof(OBJECT_BASIC_INFORMATION
);
1527 if (Length
!= sizeof(OBJECT_BASIC_INFORMATION
))
1530 Status
= STATUS_INFO_LENGTH_MISMATCH
;
1534 /* Fill out the basic information */
1535 BasicInfo
= (POBJECT_BASIC_INFORMATION
)ObjectInformation
;
1536 BasicInfo
->Attributes
= HandleInfo
.HandleAttributes
;
1537 BasicInfo
->GrantedAccess
= HandleInfo
.GrantedAccess
;
1538 BasicInfo
->HandleCount
= ObjectHeader
->HandleCount
;
1539 BasicInfo
->PointerCount
= ObjectHeader
->PointerCount
;
1541 /* Permanent/Exclusive Flags are NOT in Handle attributes! */
1542 if (ObjectHeader
->Flags
& OB_FLAG_EXCLUSIVE
)
1545 BasicInfo
->Attributes
|= OBJ_EXCLUSIVE
;
1547 if (ObjectHeader
->Flags
& OB_FLAG_PERMANENT
)
1550 BasicInfo
->Attributes
|= OBJ_PERMANENT
;
1553 /* Copy quota information */
1554 BasicInfo
->PagedPoolCharge
= 0; /* FIXME*/
1555 BasicInfo
->NonPagedPoolCharge
= 0; /* FIXME*/
1557 /* Copy name information */
1558 BasicInfo
->NameInfoSize
= 0; /* FIXME*/
1559 BasicInfo
->TypeInfoSize
= 0; /* FIXME*/
1561 /* Copy security information */
1562 BasicInfo
->SecurityDescriptorSize
= 0; /* FIXME*/
1564 /* Check if this is a symlink */
1565 if (ObjectHeader
->Type
== ObSymbolicLinkType
)
1567 /* Return the creation time */
1568 BasicInfo
->CreationTime
.QuadPart
=
1569 ((POBJECT_SYMBOLIC_LINK
)Object
)->CreationTime
.QuadPart
;
1573 /* Otherwise return 0 */
1574 BasicInfo
->CreationTime
.QuadPart
= (ULONGLONG
)0;
1577 /* Break out with success */
1578 Status
= STATUS_SUCCESS
;
1581 /* Name information */
1582 case ObjectNameInformation
:
1584 /* Call the helper and break out */
1585 Status
= ObQueryNameString(Object
,
1586 (POBJECT_NAME_INFORMATION
)
1592 /* Information about this type */
1593 case ObjectTypeInformation
:
1595 /* Call the helper and break out */
1596 Status
= ObQueryTypeInfo(ObjectHeader
->Type
,
1597 (POBJECT_TYPE_INFORMATION
)
1603 /* Information about all types */
1604 case ObjectTypesInformation
:
1605 DPRINT1("NOT IMPLEMENTED!\n");
1606 InfoLength
= Length
;
1607 Status
= STATUS_NOT_IMPLEMENTED
;
1610 /* Information about the handle flags */
1611 case ObjectHandleFlagInformation
:
1613 /* Validate length */
1614 InfoLength
= sizeof (OBJECT_HANDLE_ATTRIBUTE_INFORMATION
);
1615 if (Length
!= sizeof (OBJECT_HANDLE_ATTRIBUTE_INFORMATION
))
1617 Status
= STATUS_INFO_LENGTH_MISMATCH
;
1621 /* Get the structure */
1622 HandleFlags
= (POBJECT_HANDLE_ATTRIBUTE_INFORMATION
)
1626 HandleFlags
->Inherit
= HandleInfo
.HandleAttributes
& OBJ_INHERIT
;
1627 HandleFlags
->ProtectFromClose
= (HandleInfo
.HandleAttributes
&
1628 OBJ_PROTECT_CLOSE
) != 0;
1630 /* Break out with success */
1631 Status
= STATUS_SUCCESS
;
1638 InfoLength
= Length
;
1639 Status
= STATUS_INVALID_INFO_CLASS
;
1643 /* Check if the caller wanted the return length */
1646 /* Write the length */
1647 *ResultLength
= InfoLength
;
1650 _SEH2_EXCEPT(ExSystemExceptionFilter())
1652 /* Otherwise, get the exception code */
1653 Status
= _SEH2_GetExceptionCode();
1657 /* Dereference the object if we had referenced it */
1658 if (Object
) ObDereferenceObject(Object
);
1665 * @name NtSetInformationObject
1668 * The NtSetInformationObject routine <FILLMEIN>
1670 * @param ObjectHandle
1673 * @param ObjectInformationClass
1676 * @param ObjectInformation
1682 * @return STATUS_SUCCESS or appropriate error value.
1689 NtSetInformationObject(IN HANDLE ObjectHandle
,
1690 IN OBJECT_INFORMATION_CLASS ObjectInformationClass
,
1691 IN PVOID ObjectInformation
,
1695 OBP_SET_HANDLE_ATTRIBUTES_CONTEXT Context
;
1697 KAPC_STATE ApcState
;
1698 POBJECT_DIRECTORY Directory
;
1699 KPROCESSOR_MODE PreviousMode
;
1700 BOOLEAN AttachedToProcess
= FALSE
;
1703 /* Validate the information class */
1704 switch (ObjectInformationClass
)
1706 case ObjectHandleFlagInformation
:
1708 /* Validate the length */
1709 if (Length
!= sizeof(OBJECT_HANDLE_ATTRIBUTE_INFORMATION
))
1711 /* Invalid length */
1712 return STATUS_INFO_LENGTH_MISMATCH
;
1715 /* Save the previous mode */
1716 Context
.PreviousMode
= ExGetPreviousMode();
1718 /* Check if we were called from user mode */
1719 if (Context
.PreviousMode
!= KernelMode
)
1724 /* Probe and capture the attribute buffer */
1725 ProbeForRead(ObjectInformation
,
1726 sizeof(OBJECT_HANDLE_ATTRIBUTE_INFORMATION
),
1728 Context
.Information
= *(POBJECT_HANDLE_ATTRIBUTE_INFORMATION
)
1731 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1733 /* Return the exception code */
1734 _SEH2_YIELD(return _SEH2_GetExceptionCode());
1740 /* Just copy the buffer directly */
1741 Context
.Information
= *(POBJECT_HANDLE_ATTRIBUTE_INFORMATION
)
1745 /* Check if this is a kernel handle */
1746 if (ObpIsKernelHandle(ObjectHandle
, Context
.PreviousMode
))
1748 /* Get the actual handle */
1749 ObjectHandle
= ObKernelHandleToHandle(ObjectHandle
);
1750 ObjectTable
= ObpKernelHandleTable
;
1752 /* Check if we're not in the system process */
1753 if (PsGetCurrentProcess() != PsInitialSystemProcess
)
1756 KeStackAttachProcess(&PsInitialSystemProcess
->Pcb
, &ApcState
);
1757 AttachedToProcess
= TRUE
;
1762 /* Use the current table */
1763 ObjectTable
= PsGetCurrentProcess()->ObjectTable
;
1766 /* Change the handle attributes */
1767 if (!ExChangeHandle(ObjectTable
,
1769 ObpSetHandleAttributes
,
1770 (ULONG_PTR
)&Context
))
1773 Status
= STATUS_ACCESS_DENIED
;
1778 Status
= STATUS_SUCCESS
;
1781 /* De-attach if we were attached, and return status */
1782 if (AttachedToProcess
) KeUnstackDetachProcess(&ApcState
);
1785 case ObjectSessionInformation
:
1787 /* Only a system process can do this */
1788 PreviousMode
= ExGetPreviousMode();
1789 if (!SeSinglePrivilegeCheck(SeTcbPrivilege
, PreviousMode
))
1792 DPRINT1("Privilege not held\n");
1793 Status
= STATUS_PRIVILEGE_NOT_HELD
;
1797 /* Get the object directory */
1798 Status
= ObReferenceObjectByHandle(ObjectHandle
,
1804 if (NT_SUCCESS(Status
))
1806 /* FIXME: Missng locks */
1807 /* Set its session ID */
1808 Directory
->SessionId
= PsGetCurrentProcessSessionId();
1809 ObDereferenceObject(Directory
);
1815 /* Unsupported class */
1816 Status
= STATUS_INVALID_INFO_CLASS
;