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
)(ULONG_PTR
)0xBAADB0B0BAADB0B0ULL
;
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 StringLength
= LocalName
.Length
;
411 /* Check that the size is a valid WCHAR multiple */
412 if ((StringLength
& (sizeof(WCHAR
) - 1)) ||
413 /* Check that the NULL-termination below will work */
414 (StringLength
== (MAXUSHORT
- sizeof(UNICODE_NULL
) + 1)))
416 /* PS: Please keep the checks above expanded for clarity */
417 Status
= STATUS_OBJECT_NAME_INVALID
;
421 /* Allocate the string buffer */
422 StringBuffer
= ObpAllocateObjectNameBuffer(StringLength
,
427 /* Set failure code */
428 Status
= STATUS_INSUFFICIENT_RESOURCES
;
433 RtlCopyMemory(StringBuffer
, LocalName
.Buffer
, StringLength
);
434 StringBuffer
[StringLength
/ sizeof(WCHAR
)] = UNICODE_NULL
;
439 _SEH2_EXCEPT(ExSystemExceptionFilter())
441 /* Handle exception and free the string buffer */
442 Status
= _SEH2_GetExceptionCode();
445 ObpFreeObjectNameBuffer(CapturedName
);
456 ObpCaptureObjectCreateInformation(IN POBJECT_ATTRIBUTES ObjectAttributes
,
457 IN KPROCESSOR_MODE AccessMode
,
458 IN KPROCESSOR_MODE CreatorMode
,
459 IN BOOLEAN AllocateFromLookaside
,
460 IN POBJECT_CREATE_INFORMATION ObjectCreateInfo
,
461 OUT PUNICODE_STRING ObjectName
)
463 NTSTATUS Status
= STATUS_SUCCESS
;
464 PSECURITY_DESCRIPTOR SecurityDescriptor
;
465 PSECURITY_QUALITY_OF_SERVICE SecurityQos
;
466 PUNICODE_STRING LocalObjectName
= NULL
;
469 /* Zero out the Capture Data */
470 RtlZeroMemory(ObjectCreateInfo
, sizeof(OBJECT_CREATE_INFORMATION
));
472 /* SEH everything here for protection */
475 /* Check if we got attributes */
476 if (ObjectAttributes
)
478 /* Check if we're in user mode */
479 if (AccessMode
!= KernelMode
)
481 /* Probe the attributes */
482 ProbeForRead(ObjectAttributes
,
483 sizeof(OBJECT_ATTRIBUTES
),
487 /* Validate the Size and Attributes */
488 if ((ObjectAttributes
->Length
!= sizeof(OBJECT_ATTRIBUTES
)) ||
489 (ObjectAttributes
->Attributes
& ~OBJ_VALID_KERNEL_ATTRIBUTES
))
491 /* Invalid combination, fail */
492 _SEH2_YIELD(return STATUS_INVALID_PARAMETER
);
495 /* Set some Create Info and do not allow user-mode kernel handles */
496 ObjectCreateInfo
->RootDirectory
= ObjectAttributes
->RootDirectory
;
497 ObjectCreateInfo
->Attributes
= ObjectAttributes
->Attributes
& OBJ_VALID_KERNEL_ATTRIBUTES
;
498 if (CreatorMode
!= KernelMode
) ObjectCreateInfo
->Attributes
&= ~OBJ_KERNEL_HANDLE
;
499 LocalObjectName
= ObjectAttributes
->ObjectName
;
500 SecurityDescriptor
= ObjectAttributes
->SecurityDescriptor
;
501 SecurityQos
= ObjectAttributes
->SecurityQualityOfService
;
503 /* Check if we have a security descriptor */
504 if (SecurityDescriptor
)
506 /* Capture it. Note: This has an implicit memory barrier due
507 to the function call, so cleanup is safe here.) */
508 Status
= SeCaptureSecurityDescriptor(SecurityDescriptor
,
514 if (!NT_SUCCESS(Status
))
516 /* Capture failed, quit */
517 ObjectCreateInfo
->SecurityDescriptor
= NULL
;
518 _SEH2_YIELD(return Status
);
521 /* Save the probe mode and security descriptor size */
522 ObjectCreateInfo
->SecurityDescriptorCharge
= 2048; /* FIXME */
523 ObjectCreateInfo
->ProbeMode
= AccessMode
;
526 /* Check if we have QoS */
529 /* Check if we came from user mode */
530 if (AccessMode
!= KernelMode
)
532 /* Validate the QoS */
533 ProbeForRead(SecurityQos
,
534 sizeof(SECURITY_QUALITY_OF_SERVICE
),
539 ObjectCreateInfo
->SecurityQualityOfService
= *SecurityQos
;
540 ObjectCreateInfo
->SecurityQos
=
541 &ObjectCreateInfo
->SecurityQualityOfService
;
546 /* We don't have a name */
547 LocalObjectName
= NULL
;
550 _SEH2_EXCEPT(ExSystemExceptionFilter())
552 /* Cleanup and return the exception code */
553 ObpReleaseObjectCreateInformation(ObjectCreateInfo
);
554 _SEH2_YIELD(return _SEH2_GetExceptionCode());
558 /* Now check if the Object Attributes had an Object Name */
561 Status
= ObpCaptureObjectName(ObjectName
,
564 AllocateFromLookaside
);
568 /* Clear the string */
569 RtlInitEmptyUnicodeString(ObjectName
, NULL
, 0);
571 /* It cannot have specified a Root Directory */
572 if (ObjectCreateInfo
->RootDirectory
)
574 Status
= STATUS_OBJECT_NAME_INVALID
;
578 /* Cleanup if we failed */
579 if (!NT_SUCCESS(Status
))
581 ObpReleaseObjectCreateInformation(ObjectCreateInfo
);
584 /* Return status to caller */
590 ObFreeObjectCreateInfoBuffer(IN POBJECT_CREATE_INFORMATION ObjectCreateInfo
)
592 /* Call the macro. We use this function to isolate Ob internals from Io */
593 ObpFreeCapturedAttributes(ObjectCreateInfo
, LookasideCreateInfoList
);
598 ObpAllocateObject(IN POBJECT_CREATE_INFORMATION ObjectCreateInfo
,
599 IN PUNICODE_STRING ObjectName
,
600 IN POBJECT_TYPE ObjectType
,
602 IN KPROCESSOR_MODE PreviousMode
,
603 IN POBJECT_HEADER
*ObjectHeader
)
605 POBJECT_HEADER Header
;
606 ULONG QuotaSize
, HandleSize
, NameSize
, CreatorSize
;
607 POBJECT_HEADER_HANDLE_INFO HandleInfo
;
608 POBJECT_HEADER_NAME_INFO NameInfo
;
609 POBJECT_HEADER_CREATOR_INFO CreatorInfo
;
610 POBJECT_HEADER_QUOTA_INFO QuotaInfo
;
619 /* Check if we don't have an Object Type yet */
622 /* Use default tag and non-paged pool */
623 PoolType
= NonPagedPool
;
628 /* Use the pool and tag given */
629 PoolType
= ObjectType
->TypeInfo
.PoolType
;
630 Tag
= ObjectType
->Key
;
633 /* Check if we have no create information (ie: we're an object type) */
634 if (!ObjectCreateInfo
)
637 QuotaSize
= HandleSize
= 0;
638 NameSize
= sizeof(OBJECT_HEADER_NAME_INFO
);
639 CreatorSize
= sizeof(OBJECT_HEADER_CREATOR_INFO
);
643 /* Check if we have quota */
644 if ((((ObjectCreateInfo
->PagedPoolCharge
!=
645 ObjectType
->TypeInfo
.DefaultPagedPoolCharge
) ||
646 (ObjectCreateInfo
->NonPagedPoolCharge
!=
647 ObjectType
->TypeInfo
.DefaultNonPagedPoolCharge
) ||
648 (ObjectCreateInfo
->SecurityDescriptorCharge
> 2048)) &&
649 (PsGetCurrentProcess() != PsInitialSystemProcess
)) ||
650 (ObjectCreateInfo
->Attributes
& OBJ_EXCLUSIVE
))
653 QuotaSize
= sizeof(OBJECT_HEADER_QUOTA_INFO
);
654 ObpObjectsWithPoolQuota
++;
662 /* Check if we have a handle database */
663 if (ObjectType
->TypeInfo
.MaintainHandleCount
)
665 /* Set handle database size */
666 HandleSize
= sizeof(OBJECT_HEADER_HANDLE_INFO
);
667 ObpObjectsWithHandleDB
++;
675 /* Check if the Object has a name */
676 if (ObjectName
->Buffer
)
679 NameSize
= sizeof(OBJECT_HEADER_NAME_INFO
);
680 ObpObjectsWithName
++;
688 /* Check if the Object maintains type lists */
689 if (ObjectType
->TypeInfo
.MaintainTypeList
)
691 /* Set owner/creator size */
692 CreatorSize
= sizeof(OBJECT_HEADER_CREATOR_INFO
);
693 ObpObjectsWithCreatorInfo
++;
702 /* Set final header size */
703 FinalSize
= QuotaSize
+
707 FIELD_OFFSET(OBJECT_HEADER
, Body
);
709 /* Allocate memory for the Object and Header */
710 Header
= ExAllocatePoolWithTag(PoolType
, FinalSize
+ ObjectSize
, Tag
);
711 if (!Header
) return STATUS_INSUFFICIENT_RESOURCES
;
713 /* Check if we have a quota header */
716 /* Initialize quota info */
717 QuotaInfo
= (POBJECT_HEADER_QUOTA_INFO
)Header
;
718 QuotaInfo
->PagedPoolCharge
= ObjectCreateInfo
->PagedPoolCharge
;
719 QuotaInfo
->NonPagedPoolCharge
= ObjectCreateInfo
->NonPagedPoolCharge
;
720 QuotaInfo
->SecurityDescriptorCharge
= ObjectCreateInfo
->SecurityDescriptorCharge
;
721 QuotaInfo
->ExclusiveProcess
= NULL
;
722 Header
= (POBJECT_HEADER
)(QuotaInfo
+ 1);
725 /* Check if we have a handle database header */
728 /* Initialize Handle Info */
729 HandleInfo
= (POBJECT_HEADER_HANDLE_INFO
)Header
;
730 HandleInfo
->SingleEntry
.HandleCount
= 0;
731 Header
= (POBJECT_HEADER
)(HandleInfo
+ 1);
734 /* Check if we have a name header */
737 /* Initialize the Object Name Info */
738 NameInfo
= (POBJECT_HEADER_NAME_INFO
)Header
;
739 NameInfo
->Name
= *ObjectName
;
740 NameInfo
->Directory
= NULL
;
741 NameInfo
->QueryReferences
= 1;
743 /* Check if this is a call with the special protection flag */
744 if ((PreviousMode
== KernelMode
) &&
745 (ObjectCreateInfo
) &&
746 (ObjectCreateInfo
->Attributes
& OBJ_KERNEL_EXCLUSIVE
))
748 /* Set flag which will make the object protected from user-mode */
749 NameInfo
->QueryReferences
|= OB_FLAG_KERNEL_EXCLUSIVE
;
752 /* Set the header pointer */
753 Header
= (POBJECT_HEADER
)(NameInfo
+ 1);
756 /* Check if we have a creator header */
759 /* Initialize Creator Info */
760 CreatorInfo
= (POBJECT_HEADER_CREATOR_INFO
)Header
;
761 CreatorInfo
->CreatorBackTraceIndex
= 0;
762 CreatorInfo
->CreatorUniqueProcess
= PsGetCurrentProcessId();
763 InitializeListHead(&CreatorInfo
->TypeList
);
764 Header
= (POBJECT_HEADER
)(CreatorInfo
+ 1);
767 /* Check for quota information */
771 Header
->QuotaInfoOffset
= (UCHAR
)(QuotaSize
+
779 Header
->QuotaInfoOffset
= 0;
782 /* Check for handle information */
786 Header
->HandleInfoOffset
= (UCHAR
)(HandleSize
+
793 Header
->HandleInfoOffset
= 0;
796 /* Check for name information */
800 Header
->NameInfoOffset
= (UCHAR
)(NameSize
+ CreatorSize
);
805 Header
->NameInfoOffset
= 0;
808 /* Set the new object flag */
809 Header
->Flags
= OB_FLAG_CREATE_INFO
;
811 /* Remember if we have creator info */
812 if (CreatorSize
) Header
->Flags
|= OB_FLAG_CREATOR_INFO
;
814 /* Remember if we have handle info */
815 if (HandleSize
) Header
->Flags
|= OB_FLAG_SINGLE_PROCESS
;
817 /* Initialize the object header */
818 Header
->PointerCount
= 1;
819 Header
->HandleCount
= 0;
820 Header
->Type
= ObjectType
;
821 Header
->ObjectCreateInfo
= ObjectCreateInfo
;
822 Header
->SecurityDescriptor
= NULL
;
824 /* Check if this is a permanent object */
825 if ((ObjectCreateInfo
) && (ObjectCreateInfo
->Attributes
& OBJ_PERMANENT
))
827 /* Set the needed flag so we can check */
828 Header
->Flags
|= OB_FLAG_PERMANENT
;
831 /* Check if this is an exclusive object */
832 if ((ObjectCreateInfo
) && (ObjectCreateInfo
->Attributes
& OBJ_EXCLUSIVE
))
834 /* Set the needed flag so we can check */
835 Header
->Flags
|= OB_FLAG_EXCLUSIVE
;
838 /* Set kernel-mode flag */
839 if (PreviousMode
== KernelMode
) Header
->Flags
|= OB_FLAG_KERNEL_MODE
;
841 /* Check if we have a type */
844 /* Increase the number of objects of this type */
845 InterlockedIncrement((PLONG
)&ObjectType
->TotalNumberOfObjects
);
847 /* Update the high water */
848 ObjectType
->HighWaterNumberOfObjects
= max(ObjectType
->
849 TotalNumberOfObjects
,
851 HighWaterNumberOfObjects
);
855 *ObjectHeader
= Header
;
856 return STATUS_SUCCESS
;
861 ObQueryTypeInfo(IN POBJECT_TYPE ObjectType
,
862 OUT POBJECT_TYPE_INFORMATION ObjectTypeInfo
,
864 OUT PULONG ReturnLength
)
866 NTSTATUS Status
= STATUS_SUCCESS
;
872 /* Set return length aligned to 4-byte boundary */
873 *ReturnLength
+= sizeof(*ObjectTypeInfo
) +
874 ALIGN_UP(ObjectType
->Name
.MaximumLength
, ULONG
);
876 /* Check if thats too much though. */
877 if (Length
< *ReturnLength
)
879 _SEH2_YIELD(return STATUS_INFO_LENGTH_MISMATCH
);
883 ObjectTypeInfo
->TotalNumberOfHandles
=
884 ObjectType
->TotalNumberOfHandles
;
885 ObjectTypeInfo
->TotalNumberOfObjects
=
886 ObjectType
->TotalNumberOfObjects
;
887 ObjectTypeInfo
->HighWaterNumberOfHandles
=
888 ObjectType
->HighWaterNumberOfHandles
;
889 ObjectTypeInfo
->HighWaterNumberOfObjects
=
890 ObjectType
->HighWaterNumberOfObjects
;
891 ObjectTypeInfo
->PoolType
=
892 ObjectType
->TypeInfo
.PoolType
;
893 ObjectTypeInfo
->DefaultNonPagedPoolCharge
=
894 ObjectType
->TypeInfo
.DefaultNonPagedPoolCharge
;
895 ObjectTypeInfo
->DefaultPagedPoolCharge
=
896 ObjectType
->TypeInfo
.DefaultPagedPoolCharge
;
897 ObjectTypeInfo
->ValidAccessMask
=
898 ObjectType
->TypeInfo
.ValidAccessMask
;
899 ObjectTypeInfo
->SecurityRequired
=
900 ObjectType
->TypeInfo
.SecurityRequired
;
901 ObjectTypeInfo
->InvalidAttributes
=
902 ObjectType
->TypeInfo
.InvalidAttributes
;
903 ObjectTypeInfo
->GenericMapping
=
904 ObjectType
->TypeInfo
.GenericMapping
;
905 ObjectTypeInfo
->MaintainHandleCount
=
906 ObjectType
->TypeInfo
.MaintainHandleCount
;
908 /* Setup the name buffer */
909 InfoBuffer
= (PWSTR
)(ObjectTypeInfo
+ 1);
910 ObjectTypeInfo
->TypeName
.Buffer
= InfoBuffer
;
911 ObjectTypeInfo
->TypeName
.MaximumLength
= ObjectType
->Name
.MaximumLength
;
912 ObjectTypeInfo
->TypeName
.Length
= ObjectType
->Name
.Length
;
915 RtlCopyMemory(InfoBuffer
,
916 ObjectType
->Name
.Buffer
,
917 ObjectType
->Name
.Length
);
919 /* Null-terminate it */
920 (InfoBuffer
)[ObjectType
->Name
.Length
/ sizeof(WCHAR
)] = UNICODE_NULL
;
922 _SEH2_EXCEPT(ExSystemExceptionFilter())
924 /* Otherwise, get the exception code */
925 Status
= _SEH2_GetExceptionCode();
929 /* Return status to caller */
934 /* PUBLIC FUNCTIONS **********************************************************/
938 ObCreateObject(IN KPROCESSOR_MODE ProbeMode OPTIONAL
,
939 IN POBJECT_TYPE Type
,
940 IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL
,
941 IN KPROCESSOR_MODE AccessMode
,
942 IN OUT PVOID ParseContext OPTIONAL
,
944 IN ULONG PagedPoolCharge OPTIONAL
,
945 IN ULONG NonPagedPoolCharge OPTIONAL
,
949 POBJECT_CREATE_INFORMATION ObjectCreateInfo
;
950 UNICODE_STRING ObjectName
;
951 POBJECT_HEADER Header
;
953 /* Allocate a capture buffer */
954 ObjectCreateInfo
= ObpAllocateObjectCreateInfoBuffer(LookasideCreateInfoList
);
955 if (!ObjectCreateInfo
) return STATUS_INSUFFICIENT_RESOURCES
;
957 /* Capture all the info */
958 Status
= ObpCaptureObjectCreateInformation(ObjectAttributes
,
964 if (NT_SUCCESS(Status
))
966 /* Validate attributes */
967 if (Type
->TypeInfo
.InvalidAttributes
& ObjectCreateInfo
->Attributes
)
970 Status
= STATUS_INVALID_PARAMETER
;
974 /* Check if we have a paged charge */
975 if (!PagedPoolCharge
)
978 PagedPoolCharge
= Type
->TypeInfo
.DefaultPagedPoolCharge
;
981 /* Check for nonpaged charge */
982 if (!NonPagedPoolCharge
)
985 NonPagedPoolCharge
= Type
->TypeInfo
.DefaultNonPagedPoolCharge
;
988 /* Write the pool charges */
989 ObjectCreateInfo
->PagedPoolCharge
= PagedPoolCharge
;
990 ObjectCreateInfo
->NonPagedPoolCharge
= NonPagedPoolCharge
;
992 /* Allocate the Object */
993 Status
= ObpAllocateObject(ObjectCreateInfo
,
999 if (NT_SUCCESS(Status
))
1001 /* Return the Object */
1002 *Object
= &Header
->Body
;
1004 /* Check if this is a permanent object */
1005 if (Header
->Flags
& OB_FLAG_PERMANENT
)
1007 /* Do the privilege check */
1008 if (!SeSinglePrivilegeCheck(SeCreatePermanentPrivilege
,
1012 ObpDeallocateObject(*Object
);
1013 Status
= STATUS_PRIVILEGE_NOT_HELD
;
1022 /* Release the Capture Info, we don't need it */
1023 ObpFreeObjectCreateInformation(ObjectCreateInfo
);
1024 if (ObjectName
.Buffer
) ObpFreeObjectNameBuffer(&ObjectName
);
1027 /* We failed, so release the Buffer */
1028 ObpFreeCapturedAttributes(ObjectCreateInfo
, LookasideCreateInfoList
);
1034 ObCreateObjectType(IN PUNICODE_STRING TypeName
,
1035 IN POBJECT_TYPE_INITIALIZER ObjectTypeInitializer
,
1037 OUT POBJECT_TYPE
*ObjectType
)
1039 POBJECT_HEADER Header
;
1040 POBJECT_TYPE LocalObjectType
;
1043 OBP_LOOKUP_CONTEXT Context
;
1046 UNICODE_STRING ObjectName
;
1047 ANSI_STRING AnsiName
;
1048 POBJECT_HEADER_CREATOR_INFO CreatorInfo
;
1050 /* Verify parameters */
1052 !(TypeName
->Length
) ||
1053 (TypeName
->Length
% sizeof(WCHAR
)) ||
1054 !(ObjectTypeInitializer
) ||
1055 (ObjectTypeInitializer
->Length
!= sizeof(*ObjectTypeInitializer
)) ||
1056 (ObjectTypeInitializer
->InvalidAttributes
& ~OBJ_VALID_KERNEL_ATTRIBUTES
) ||
1057 (ObjectTypeInitializer
->MaintainHandleCount
&&
1058 (!(ObjectTypeInitializer
->OpenProcedure
) &&
1059 !ObjectTypeInitializer
->CloseProcedure
)) ||
1060 ((!ObjectTypeInitializer
->UseDefaultObject
) &&
1061 (ObjectTypeInitializer
->PoolType
!= NonPagedPool
)))
1064 return STATUS_INVALID_PARAMETER
;
1067 /* Make sure the name doesn't have a separator */
1068 p
= TypeName
->Buffer
;
1069 i
= TypeName
->Length
/ sizeof(WCHAR
);
1072 /* Check for one and fail */
1073 if (*p
++ == OBJ_NAME_PATH_SEPARATOR
) return STATUS_OBJECT_NAME_INVALID
;
1076 /* Setup a lookup context */
1077 ObpInitializeLookupContext(&Context
);
1079 /* Check if we've already created the directory of types */
1080 if (ObpTypeDirectoryObject
)
1082 /* Acquire the directory lock */
1083 ObpAcquireDirectoryLockExclusive(ObpTypeDirectoryObject
, &Context
);
1086 if (ObpLookupEntryDirectory(ObpTypeDirectoryObject
,
1088 OBJ_CASE_INSENSITIVE
,
1092 /* We have already created it, so fail */
1093 ObpReleaseLookupContext(&Context
);
1094 return STATUS_OBJECT_NAME_COLLISION
;
1098 /* Now make a copy of the object name */
1099 ObjectName
.Buffer
= ExAllocatePoolWithTag(PagedPool
,
1100 TypeName
->MaximumLength
,
1102 if (!ObjectName
.Buffer
)
1104 /* Out of memory, fail */
1105 ObpReleaseLookupContext(&Context
);
1106 return STATUS_INSUFFICIENT_RESOURCES
;
1109 /* Set the length and copy the name */
1110 ObjectName
.MaximumLength
= TypeName
->MaximumLength
;
1111 RtlCopyUnicodeString(&ObjectName
, TypeName
);
1113 /* Allocate the Object */
1114 Status
= ObpAllocateObject(NULL
,
1117 sizeof(OBJECT_TYPE
),
1120 if (!NT_SUCCESS(Status
))
1122 /* Free the name and fail */
1123 ObpReleaseLookupContext(&Context
);
1124 ExFreePool(ObjectName
.Buffer
);
1128 /* Setup the flags and name */
1129 LocalObjectType
= (POBJECT_TYPE
)&Header
->Body
;
1130 LocalObjectType
->Name
= ObjectName
;
1131 Header
->Flags
|= OB_FLAG_KERNEL_MODE
| OB_FLAG_PERMANENT
;
1133 /* Clear accounting data */
1134 LocalObjectType
->TotalNumberOfObjects
=
1135 LocalObjectType
->TotalNumberOfHandles
=
1136 LocalObjectType
->HighWaterNumberOfObjects
=
1137 LocalObjectType
->HighWaterNumberOfHandles
= 0;
1139 /* Check if this is the first Object Type */
1140 if (!ObpTypeObjectType
)
1142 /* It is, so set this as the type object */
1143 ObpTypeObjectType
= LocalObjectType
;
1144 Header
->Type
= ObpTypeObjectType
;
1146 /* Set the hard-coded key and object count */
1147 LocalObjectType
->TotalNumberOfObjects
= 1;
1148 LocalObjectType
->Key
= 'TjbO';
1152 /* Convert the tag to ASCII */
1153 Status
= RtlUnicodeStringToAnsiString(&AnsiName
, TypeName
, TRUE
);
1154 if (NT_SUCCESS(Status
))
1156 /* For every missing character, use a space */
1157 for (i
= 3; i
>= AnsiName
.Length
; i
--) AnsiName
.Buffer
[i
] = ' ';
1159 /* Set the key and free the converted name */
1160 LocalObjectType
->Key
= *(PULONG
)AnsiName
.Buffer
;
1161 RtlFreeAnsiString(&AnsiName
);
1165 /* Just copy the characters */
1166 LocalObjectType
->Key
= *(PULONG
)TypeName
->Buffer
;
1170 /* Set up the type information */
1171 LocalObjectType
->TypeInfo
= *ObjectTypeInitializer
;
1172 LocalObjectType
->TypeInfo
.PoolType
= ObjectTypeInitializer
->PoolType
;
1174 /* Check if we have to maintain a type list */
1175 if (NtGlobalFlag
& FLG_MAINTAIN_OBJECT_TYPELIST
)
1177 /* Enable support */
1178 LocalObjectType
->TypeInfo
.MaintainTypeList
= TRUE
;
1181 /* Calculate how much space our header'll take up */
1182 HeaderSize
= sizeof(OBJECT_HEADER
) +
1183 sizeof(OBJECT_HEADER_NAME_INFO
) +
1184 (ObjectTypeInitializer
->MaintainHandleCount
?
1185 sizeof(OBJECT_HEADER_HANDLE_INFO
) : 0);
1187 /* Check the pool type */
1188 if (ObjectTypeInitializer
->PoolType
== NonPagedPool
)
1190 /* Update the NonPaged Pool charge */
1191 LocalObjectType
->TypeInfo
.DefaultNonPagedPoolCharge
+= HeaderSize
;
1195 /* Update the Paged Pool charge */
1196 LocalObjectType
->TypeInfo
.DefaultPagedPoolCharge
+= HeaderSize
;
1199 /* All objects types need a security procedure */
1200 if (!ObjectTypeInitializer
->SecurityProcedure
)
1202 LocalObjectType
->TypeInfo
.SecurityProcedure
= SeDefaultObjectMethod
;
1205 /* Select the Wait Object */
1206 if (LocalObjectType
->TypeInfo
.UseDefaultObject
)
1208 /* Add the SYNCHRONIZE access mask since it's waitable */
1209 LocalObjectType
->TypeInfo
.ValidAccessMask
|= SYNCHRONIZE
;
1211 /* Use the "Default Object", a simple event */
1212 LocalObjectType
->DefaultObject
= &ObpDefaultObject
;
1214 /* The File Object gets an optimized hack so it can be waited on */
1215 else if ((TypeName
->Length
== 8) && !(wcscmp(TypeName
->Buffer
, L
"File")))
1217 /* Wait on the File Object's event directly */
1218 LocalObjectType
->DefaultObject
= UlongToPtr(FIELD_OFFSET(FILE_OBJECT
,
1221 else if ((TypeName
->Length
== 24) && !(wcscmp(TypeName
->Buffer
, L
"WaitablePort")))
1223 /* Wait on the LPC Port's object directly */
1224 LocalObjectType
->DefaultObject
= UlongToPtr(FIELD_OFFSET(LPCP_PORT_OBJECT
,
1229 /* No default Object */
1230 LocalObjectType
->DefaultObject
= NULL
;
1233 /* Initialize Object Type components */
1234 ExInitializeResourceLite(&LocalObjectType
->Mutex
);
1235 for (i
= 0; i
< 4; i
++)
1237 /* Initialize the object locks */
1238 ExInitializeResourceLite(&LocalObjectType
->ObjectLocks
[i
]);
1240 InitializeListHead(&LocalObjectType
->TypeList
);
1242 /* Lock the object type */
1243 ObpEnterObjectTypeMutex(ObpTypeObjectType
);
1245 /* Get creator info and insert it into the type list */
1246 CreatorInfo
= OBJECT_HEADER_TO_CREATOR_INFO(Header
);
1249 InsertTailList(&ObpTypeObjectType
->TypeList
,
1250 &CreatorInfo
->TypeList
);
1252 /* CORE-8423: Avoid inserting this a second time if someone creates a
1253 * handle to the object type (bug in Windows 2003) */
1254 Header
->Flags
&= ~OB_FLAG_CREATE_INFO
;
1257 /* Set the index and the entry into the object type array */
1258 LocalObjectType
->Index
= ObpTypeObjectType
->TotalNumberOfObjects
;
1260 ASSERT(LocalObjectType
->Index
!= 0);
1262 if (LocalObjectType
->Index
< RTL_NUMBER_OF(ObpObjectTypes
))
1264 /* It fits, insert it */
1265 ObpObjectTypes
[LocalObjectType
->Index
- 1] = LocalObjectType
;
1268 /* Release the object type */
1269 ObpLeaveObjectTypeMutex(ObpTypeObjectType
);
1271 /* Check if we're actually creating the directory object itself */
1272 if (!(ObpTypeDirectoryObject
) ||
1273 (ObpInsertEntryDirectory(ObpTypeDirectoryObject
, &Context
, Header
)))
1275 /* Check if the type directory exists */
1276 if (ObpTypeDirectoryObject
)
1279 ObReferenceObject(ObpTypeDirectoryObject
);
1282 /* Cleanup the lookup context */
1283 ObpReleaseLookupContext(&Context
);
1285 /* Return the object type and success */
1286 *ObjectType
= LocalObjectType
;
1287 return STATUS_SUCCESS
;
1290 /* If we got here, then we failed */
1291 ObpReleaseLookupContext(&Context
);
1292 return STATUS_INSUFFICIENT_RESOURCES
;
1297 ObDeleteCapturedInsertInfo(IN PVOID Object
)
1299 POBJECT_HEADER ObjectHeader
;
1302 /* Check if there is anything to free */
1303 ObjectHeader
= OBJECT_TO_OBJECT_HEADER(Object
);
1304 if ((ObjectHeader
->Flags
& OB_FLAG_CREATE_INFO
) &&
1305 (ObjectHeader
->ObjectCreateInfo
!= NULL
))
1307 /* Free the create info */
1308 ObpFreeObjectCreateInformation(ObjectHeader
->ObjectCreateInfo
);
1309 ObjectHeader
->ObjectCreateInfo
= NULL
;
1315 ObpDeleteObjectType(IN PVOID Object
)
1318 POBJECT_TYPE ObjectType
= (PVOID
)Object
;
1320 /* Loop our locks */
1321 for (i
= 0; i
< 4; i
++)
1323 /* Delete each one */
1324 ExDeleteResourceLite(&ObjectType
->ObjectLocks
[i
]);
1327 /* Delete our main mutex */
1328 ExDeleteResourceLite(&ObjectType
->Mutex
);
1332 * @name ObMakeTemporaryObject
1335 * The ObMakeTemporaryObject routine <FILLMEIN>
1347 ObMakeTemporaryObject(IN PVOID ObjectBody
)
1351 /* Call the internal API */
1352 ObpSetPermanentObject(ObjectBody
, FALSE
);
1356 * @name NtMakeTemporaryObject
1359 * The NtMakeTemporaryObject routine <FILLMEIN>
1361 * @param ObjectHandle
1364 * @return STATUS_SUCCESS or appropriate error value.
1371 NtMakeTemporaryObject(IN HANDLE ObjectHandle
)
1377 /* Reference the object for DELETE access */
1378 Status
= ObReferenceObjectByHandle(ObjectHandle
,
1381 KeGetPreviousMode(),
1384 if (Status
!= STATUS_SUCCESS
) return Status
;
1386 /* Set it as temporary and dereference it */
1387 ObpSetPermanentObject(ObjectBody
, FALSE
);
1388 ObDereferenceObject(ObjectBody
);
1389 return STATUS_SUCCESS
;
1393 * @name NtMakePermanentObject
1396 * The NtMakePermanentObject routine <FILLMEIN>
1398 * @param ObjectHandle
1401 * @return STATUS_SUCCESS or appropriate error value.
1408 NtMakePermanentObject(IN HANDLE ObjectHandle
)
1412 KPROCESSOR_MODE PreviousMode
= ExGetPreviousMode();
1415 /* Make sure that the caller has SeCreatePermanentPrivilege */
1416 Status
= SeSinglePrivilegeCheck(SeCreatePermanentPrivilege
,
1418 if (!NT_SUCCESS(Status
)) return STATUS_PRIVILEGE_NOT_HELD
;
1420 /* Reference the object */
1421 Status
= ObReferenceObjectByHandle(ObjectHandle
,
1427 if (Status
!= STATUS_SUCCESS
) return Status
;
1429 /* Set it as permanent and dereference it */
1430 ObpSetPermanentObject(ObjectBody
, TRUE
);
1431 ObDereferenceObject(ObjectBody
);
1432 return STATUS_SUCCESS
;
1436 * @name NtQueryObject
1439 * The NtQueryObject routine <FILLMEIN>
1441 * @param ObjectHandle
1444 * @param ObjectInformationClass
1447 * @param ObjectInformation
1453 * @param ResultLength
1456 * @return STATUS_SUCCESS or appropriate error value.
1463 NtQueryObject(IN HANDLE ObjectHandle
,
1464 IN OBJECT_INFORMATION_CLASS ObjectInformationClass
,
1465 OUT PVOID ObjectInformation
,
1467 OUT PULONG ResultLength OPTIONAL
)
1469 OBJECT_HANDLE_INFORMATION HandleInfo
;
1470 POBJECT_HEADER ObjectHeader
= NULL
;
1471 POBJECT_HANDLE_ATTRIBUTE_INFORMATION HandleFlags
;
1472 POBJECT_BASIC_INFORMATION BasicInfo
;
1473 ULONG InfoLength
= 0;
1474 PVOID Object
= NULL
;
1476 KPROCESSOR_MODE PreviousMode
= ExGetPreviousMode();
1479 /* Check if the caller is from user mode */
1480 if (PreviousMode
!= KernelMode
)
1482 /* Protect validation with SEH */
1485 /* Probe the input structure */
1486 ProbeForWrite(ObjectInformation
, Length
, sizeof(UCHAR
));
1488 /* If we have a result length, probe it too */
1489 if (ResultLength
) ProbeForWriteUlong(ResultLength
);
1491 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1493 /* Return the exception code */
1494 _SEH2_YIELD(return _SEH2_GetExceptionCode());
1500 * Make sure this isn't a generic type query, since the caller doesn't
1501 * have to give a handle for it
1503 if (ObjectInformationClass
!= ObjectTypesInformation
)
1505 /* Reference the object */
1506 Status
= ObReferenceObjectByHandle(ObjectHandle
,
1509 KeGetPreviousMode(),
1512 if (!NT_SUCCESS (Status
)) return Status
;
1514 /* Get the object header */
1515 ObjectHeader
= OBJECT_TO_OBJECT_HEADER(Object
);
1520 /* Check the information class */
1521 switch (ObjectInformationClass
)
1524 case ObjectBasicInformation
:
1526 /* Validate length */
1527 InfoLength
= sizeof(OBJECT_BASIC_INFORMATION
);
1528 if (Length
!= sizeof(OBJECT_BASIC_INFORMATION
))
1531 Status
= STATUS_INFO_LENGTH_MISMATCH
;
1535 /* Fill out the basic information */
1536 BasicInfo
= (POBJECT_BASIC_INFORMATION
)ObjectInformation
;
1537 BasicInfo
->Attributes
= HandleInfo
.HandleAttributes
;
1538 BasicInfo
->GrantedAccess
= HandleInfo
.GrantedAccess
;
1539 BasicInfo
->HandleCount
= ObjectHeader
->HandleCount
;
1540 BasicInfo
->PointerCount
= ObjectHeader
->PointerCount
;
1542 /* Permanent/Exclusive Flags are NOT in Handle attributes! */
1543 if (ObjectHeader
->Flags
& OB_FLAG_EXCLUSIVE
)
1546 BasicInfo
->Attributes
|= OBJ_EXCLUSIVE
;
1548 if (ObjectHeader
->Flags
& OB_FLAG_PERMANENT
)
1551 BasicInfo
->Attributes
|= OBJ_PERMANENT
;
1554 /* Copy quota information */
1555 BasicInfo
->PagedPoolCharge
= 0; /* FIXME*/
1556 BasicInfo
->NonPagedPoolCharge
= 0; /* FIXME*/
1558 /* Copy name information */
1559 BasicInfo
->NameInfoSize
= 0; /* FIXME*/
1560 BasicInfo
->TypeInfoSize
= 0; /* FIXME*/
1562 /* Copy security information */
1563 BasicInfo
->SecurityDescriptorSize
= 0; /* FIXME*/
1565 /* Check if this is a symlink */
1566 if (ObjectHeader
->Type
== ObpSymbolicLinkObjectType
)
1568 /* Return the creation time */
1569 BasicInfo
->CreationTime
.QuadPart
=
1570 ((POBJECT_SYMBOLIC_LINK
)Object
)->CreationTime
.QuadPart
;
1574 /* Otherwise return 0 */
1575 BasicInfo
->CreationTime
.QuadPart
= (ULONGLONG
)0;
1578 /* Break out with success */
1579 Status
= STATUS_SUCCESS
;
1582 /* Name information */
1583 case ObjectNameInformation
:
1585 /* Call the helper and break out */
1586 Status
= ObQueryNameString(Object
,
1587 (POBJECT_NAME_INFORMATION
)
1593 /* Information about this type */
1594 case ObjectTypeInformation
:
1596 /* Call the helper and break out */
1597 Status
= ObQueryTypeInfo(ObjectHeader
->Type
,
1598 (POBJECT_TYPE_INFORMATION
)
1604 /* Information about all types */
1605 case ObjectTypesInformation
:
1606 DPRINT1("NOT IMPLEMENTED!\n");
1607 InfoLength
= Length
;
1608 Status
= STATUS_NOT_IMPLEMENTED
;
1611 /* Information about the handle flags */
1612 case ObjectHandleFlagInformation
:
1614 /* Validate length */
1615 InfoLength
= sizeof (OBJECT_HANDLE_ATTRIBUTE_INFORMATION
);
1616 if (Length
!= sizeof (OBJECT_HANDLE_ATTRIBUTE_INFORMATION
))
1618 Status
= STATUS_INFO_LENGTH_MISMATCH
;
1622 /* Get the structure */
1623 HandleFlags
= (POBJECT_HANDLE_ATTRIBUTE_INFORMATION
)
1627 HandleFlags
->Inherit
= HandleInfo
.HandleAttributes
& OBJ_INHERIT
;
1628 HandleFlags
->ProtectFromClose
= (HandleInfo
.HandleAttributes
&
1629 OBJ_PROTECT_CLOSE
) != 0;
1631 /* Break out with success */
1632 Status
= STATUS_SUCCESS
;
1639 InfoLength
= Length
;
1640 Status
= STATUS_INVALID_INFO_CLASS
;
1644 /* Check if the caller wanted the return length */
1647 /* Write the length */
1648 *ResultLength
= InfoLength
;
1651 _SEH2_EXCEPT(ExSystemExceptionFilter())
1653 /* Otherwise, get the exception code */
1654 Status
= _SEH2_GetExceptionCode();
1658 /* Dereference the object if we had referenced it */
1659 if (Object
) ObDereferenceObject(Object
);
1666 * @name NtSetInformationObject
1669 * The NtSetInformationObject routine <FILLMEIN>
1671 * @param ObjectHandle
1674 * @param ObjectInformationClass
1677 * @param ObjectInformation
1683 * @return STATUS_SUCCESS or appropriate error value.
1690 NtSetInformationObject(IN HANDLE ObjectHandle
,
1691 IN OBJECT_INFORMATION_CLASS ObjectInformationClass
,
1692 IN PVOID ObjectInformation
,
1696 OBP_SET_HANDLE_ATTRIBUTES_CONTEXT Context
;
1698 KAPC_STATE ApcState
;
1699 POBJECT_DIRECTORY Directory
;
1700 KPROCESSOR_MODE PreviousMode
;
1701 BOOLEAN AttachedToProcess
= FALSE
;
1704 /* Validate the information class */
1705 switch (ObjectInformationClass
)
1707 case ObjectHandleFlagInformation
:
1709 /* Validate the length */
1710 if (Length
!= sizeof(OBJECT_HANDLE_ATTRIBUTE_INFORMATION
))
1712 /* Invalid length */
1713 return STATUS_INFO_LENGTH_MISMATCH
;
1716 /* Save the previous mode */
1717 Context
.PreviousMode
= ExGetPreviousMode();
1719 /* Check if we were called from user mode */
1720 if (Context
.PreviousMode
!= KernelMode
)
1725 /* Probe and capture the attribute buffer */
1726 ProbeForRead(ObjectInformation
,
1727 sizeof(OBJECT_HANDLE_ATTRIBUTE_INFORMATION
),
1729 Context
.Information
= *(POBJECT_HANDLE_ATTRIBUTE_INFORMATION
)
1732 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1734 /* Return the exception code */
1735 _SEH2_YIELD(return _SEH2_GetExceptionCode());
1741 /* Just copy the buffer directly */
1742 Context
.Information
= *(POBJECT_HANDLE_ATTRIBUTE_INFORMATION
)
1746 /* Check if this is a kernel handle */
1747 if (ObpIsKernelHandle(ObjectHandle
, Context
.PreviousMode
))
1749 /* Get the actual handle */
1750 ObjectHandle
= ObKernelHandleToHandle(ObjectHandle
);
1751 ObjectTable
= ObpKernelHandleTable
;
1753 /* Check if we're not in the system process */
1754 if (PsGetCurrentProcess() != PsInitialSystemProcess
)
1757 KeStackAttachProcess(&PsInitialSystemProcess
->Pcb
, &ApcState
);
1758 AttachedToProcess
= TRUE
;
1763 /* Use the current table */
1764 ObjectTable
= PsGetCurrentProcess()->ObjectTable
;
1767 /* Change the handle attributes */
1768 if (!ExChangeHandle(ObjectTable
,
1770 ObpSetHandleAttributes
,
1771 (ULONG_PTR
)&Context
))
1774 Status
= STATUS_ACCESS_DENIED
;
1779 Status
= STATUS_SUCCESS
;
1782 /* De-attach if we were attached, and return status */
1783 if (AttachedToProcess
) KeUnstackDetachProcess(&ApcState
);
1786 case ObjectSessionInformation
:
1788 /* Only a system process can do this */
1789 PreviousMode
= ExGetPreviousMode();
1790 if (!SeSinglePrivilegeCheck(SeTcbPrivilege
, PreviousMode
))
1793 DPRINT1("Privilege not held\n");
1794 Status
= STATUS_PRIVILEGE_NOT_HELD
;
1798 /* Get the object directory */
1799 Status
= ObReferenceObjectByHandle(ObjectHandle
,
1801 ObpDirectoryObjectType
,
1805 if (NT_SUCCESS(Status
))
1807 /* FIXME: Missng locks */
1808 /* Set its session ID */
1809 Directory
->SessionId
= PsGetCurrentProcessSessionId();
1810 ObDereferenceObject(Directory
);
1816 /* Unsupported class */
1817 Status
= STATUS_INVALID_INFO_CLASS
;