3 * Copyright (C) 1998, 1999, 2000, 2001 ReactOS Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * COPYRIGHT: See COPYING in the top level directory
22 * PROJECT: ReactOS kernel
23 * FILE: ntoskrnl/ob/handle.c
24 * PURPOSE: Managing handles
25 * PROGRAMMER: David Welch (welch@cwcom.net)
30 /* INCLUDES ****************************************************************/
34 #include <internal/debug.h>
36 #define EX_OBJ_TO_HDR(eob) ((POBJECT_HEADER)((ULONG_PTR)(eob) & \
37 ~(EX_HANDLE_ENTRY_PROTECTFROMCLOSE | EX_HANDLE_ENTRY_INHERITABLE | \
38 EX_HANDLE_ENTRY_AUDITONCLOSE)))
39 #define EX_HTE_TO_HDR(hte) ((POBJECT_HEADER)((ULONG_PTR)((hte)->u1.Object) & \
40 ~(EX_HANDLE_ENTRY_PROTECTFROMCLOSE | EX_HANDLE_ENTRY_INHERITABLE | \
41 EX_HANDLE_ENTRY_AUDITONCLOSE)))
43 /* FUNCTIONS ***************************************************************/
47 ObpDecrementHandleCount(PVOID ObjectBody
)
49 POBJECT_HEADER ObjectHeader
= BODY_TO_HEADER(ObjectBody
);
50 LONG NewHandleCount
= InterlockedDecrement(&ObjectHeader
->HandleCount
);
52 if ((ObjectHeader
->ObjectType
!= NULL
) &&
53 (ObjectHeader
->ObjectType
->Close
!= NULL
))
55 /* the handle count should be decremented but we pass the previous value
57 ObjectHeader
->ObjectType
->Close(ObjectBody
, NewHandleCount
+ 1);
60 if(NewHandleCount
== 0)
62 ObDereferenceObject(ObjectBody
);
68 ObpQueryHandleAttributes(HANDLE Handle
,
69 POBJECT_HANDLE_ATTRIBUTE_INFORMATION HandleInfo
)
72 PHANDLE_TABLE_ENTRY HandleTableEntry
;
73 LONG ExHandle
= HANDLE_TO_EX_HANDLE(Handle
);
77 DPRINT("ObpQueryHandleAttributes(Handle %x)\n", Handle
);
79 KeEnterCriticalRegion();
81 Process
= PsGetCurrentProcess();
83 HandleTableEntry
= ExMapHandleToPointer(Process
->ObjectTable
,
85 if (HandleTableEntry
== NULL
)
87 KeLeaveCriticalRegion();
88 return STATUS_INVALID_HANDLE
;
91 HandleInfo
->Inherit
= (HandleTableEntry
->u1
.ObAttributes
& EX_HANDLE_ENTRY_INHERITABLE
) != 0;
92 HandleInfo
->ProtectFromClose
= (HandleTableEntry
->u1
.ObAttributes
& EX_HANDLE_ENTRY_PROTECTFROMCLOSE
) != 0;
94 ExUnlockHandleTableEntry(Process
->ObjectTable
,
97 KeLeaveCriticalRegion();
99 return STATUS_SUCCESS
;
104 ObpSetHandleAttributes(HANDLE Handle
,
105 POBJECT_HANDLE_ATTRIBUTE_INFORMATION HandleInfo
)
108 PHANDLE_TABLE_ENTRY HandleTableEntry
;
109 LONG ExHandle
= HANDLE_TO_EX_HANDLE(Handle
);
113 DPRINT("ObpSetHandleAttributes(Handle %x)\n", Handle
);
115 Process
= PsGetCurrentProcess();
117 KeEnterCriticalRegion();
119 HandleTableEntry
= ExMapHandleToPointer(Process
->ObjectTable
,
121 if (HandleTableEntry
== NULL
)
123 KeLeaveCriticalRegion();
124 return STATUS_INVALID_HANDLE
;
127 if (HandleInfo
->Inherit
)
128 HandleTableEntry
->u1
.ObAttributes
|= EX_HANDLE_ENTRY_INHERITABLE
;
130 HandleTableEntry
->u1
.ObAttributes
&= ~EX_HANDLE_ENTRY_INHERITABLE
;
132 if (HandleInfo
->ProtectFromClose
)
133 HandleTableEntry
->u1
.ObAttributes
|= EX_HANDLE_ENTRY_PROTECTFROMCLOSE
;
135 HandleTableEntry
->u1
.ObAttributes
&= ~EX_HANDLE_ENTRY_PROTECTFROMCLOSE
;
137 /* FIXME: Do we need to set anything in the object header??? */
139 ExUnlockHandleTableEntry(Process
->ObjectTable
,
142 KeLeaveCriticalRegion();
144 return STATUS_SUCCESS
;
149 ObDuplicateObject(PEPROCESS SourceProcess
,
150 PEPROCESS TargetProcess
,
152 PHANDLE TargetHandle
,
153 ACCESS_MASK DesiredAccess
,
154 BOOLEAN InheritHandle
,
157 PHANDLE_TABLE_ENTRY SourceHandleEntry
;
158 HANDLE_TABLE_ENTRY NewHandleEntry
;
160 POBJECT_HEADER ObjectHeader
;
162 LONG ExSourceHandle
= HANDLE_TO_EX_HANDLE(SourceHandle
);
166 KeEnterCriticalRegion();
168 SourceHandleEntry
= ExMapHandleToPointer(SourceProcess
->ObjectTable
,
170 if (SourceHandleEntry
== NULL
)
172 return STATUS_INVALID_HANDLE
;
175 ObjectHeader
= EX_HTE_TO_HDR(SourceHandleEntry
);
176 ObjectBody
= HEADER_TO_BODY(ObjectHeader
);
178 NewHandleEntry
.u1
.Object
= SourceHandleEntry
->u1
.Object
;
180 NewHandleEntry
.u1
.ObAttributes
|= EX_HANDLE_ENTRY_INHERITABLE
;
182 NewHandleEntry
.u1
.ObAttributes
&= ~EX_HANDLE_ENTRY_INHERITABLE
;
183 NewHandleEntry
.u2
.GrantedAccess
= ((Options
& DUPLICATE_SAME_ACCESS
) ?
184 SourceHandleEntry
->u2
.GrantedAccess
:
187 /* reference the object so it doesn't get deleted after releasing the lock
188 and before creating a new handle for it */
189 ObReferenceObject(ObjectBody
);
191 /* increment the handle count of the object, it should always be >= 2 because
192 we're holding a handle lock to this object! if the new handle count was
193 1 here, we're in big trouble... it would've been safe to increment and
194 check the handle count without using interlocked functions because the
195 entry is locked, which means the handle count can't change. */
196 InterlockedIncrement(&ObjectHeader
->HandleCount
);
197 ASSERT(ObjectHeader
->HandleCount
>= 2);
199 ExUnlockHandleTableEntry(SourceProcess
->ObjectTable
,
202 KeLeaveCriticalRegion();
204 /* attempt to create the new handle */
205 ExTargetHandle
= ExCreateHandle(TargetProcess
->ObjectTable
,
207 if (ExTargetHandle
!= EX_INVALID_HANDLE
)
209 if (Options
& DUPLICATE_CLOSE_SOURCE
)
211 ObDeleteHandle(SourceProcess
,
215 ObDereferenceObject(ObjectBody
);
217 *TargetHandle
= EX_HANDLE_TO_HANDLE(ExTargetHandle
);
219 return STATUS_SUCCESS
;
223 /* decrement the handle count we previously incremented, but don't call the
224 closing procedure because we're not closing a handle! */
225 if(InterlockedDecrement(&ObjectHeader
->HandleCount
) == 0)
227 ObDereferenceObject(ObjectBody
);
230 ObDereferenceObject(ObjectBody
);
231 return STATUS_UNSUCCESSFUL
;
239 NtDuplicateObject (IN HANDLE SourceProcessHandle
,
240 IN HANDLE SourceHandle
,
241 IN HANDLE TargetProcessHandle
,
242 OUT PHANDLE TargetHandle
,
243 IN ACCESS_MASK DesiredAccess
,
244 IN BOOLEAN InheritHandle
,
247 * FUNCTION: Copies a handle from one process space to another
249 * SourceProcessHandle = The source process owning the handle. The
250 * source process should have opened
251 * the SourceHandle with PROCESS_DUP_HANDLE
253 * SourceHandle = The handle to the object.
254 * TargetProcessHandle = The destination process owning the handle
255 * TargetHandle (OUT) = Caller should supply storage for the
257 * DesiredAccess = The desired access to the handle.
258 * InheritHandle = Indicates wheter the new handle will be inheritable
260 * Options = Specifies special actions upon duplicating the handle.
261 * Can be one of the values DUPLICATE_CLOSE_SOURCE |
262 * DUPLICATE_SAME_ACCESS. DUPLICATE_CLOSE_SOURCE specifies
263 * that the source handle should be closed after duplicating.
264 * DUPLICATE_SAME_ACCESS specifies to ignore the
265 * DesiredAccess paramter and just grant the same access to
268 * REMARKS: This function maps to the win32 DuplicateHandle.
271 PEPROCESS SourceProcess
;
272 PEPROCESS TargetProcess
;
274 KPROCESSOR_MODE PreviousMode
;
275 NTSTATUS Status
= STATUS_SUCCESS
;
279 PreviousMode
= ExGetPreviousMode();
281 if(PreviousMode
!= KernelMode
)
285 ProbeForWrite(TargetHandle
,
291 Status
= _SEH_GetExceptionCode();
295 if(!NT_SUCCESS(Status
))
301 Status
= ObReferenceObjectByHandle(SourceProcessHandle
,
305 (PVOID
*)&SourceProcess
,
307 if (!NT_SUCCESS(Status
))
312 Status
= ObReferenceObjectByHandle(TargetProcessHandle
,
316 (PVOID
*)&TargetProcess
,
318 if (!NT_SUCCESS(Status
))
320 ObDereferenceObject(SourceProcess
);
324 /* Check for magic handle first */
325 if (SourceHandle
== NtCurrentThread())
329 Status
= ObReferenceObjectByHandle(SourceHandle
,
335 if(NT_SUCCESS(Status
))
337 Status
= ObCreateHandle(TargetProcess
,
343 ObDereferenceObject(ObjectBody
);
345 if (Options
& DUPLICATE_CLOSE_SOURCE
)
347 ObDeleteHandle(SourceProcess
,
354 Status
= ObDuplicateObject(SourceProcess
,
363 ObDereferenceObject(TargetProcess
);
364 ObDereferenceObject(SourceProcess
);
366 if(NT_SUCCESS(Status
))
370 *TargetHandle
= hTarget
;
374 Status
= _SEH_GetExceptionCode();
383 DeleteHandleCallback(PHANDLE_TABLE HandleTable
,
388 POBJECT_HEADER ObjectHeader
;
393 ObjectHeader
= EX_OBJ_TO_HDR(Object
);
394 ObjectBody
= HEADER_TO_BODY(ObjectHeader
);
396 ObpDecrementHandleCount(ObjectBody
);
399 VOID
ObDeleteHandleTable(PEPROCESS Process
)
401 * FUNCTION: Deletes the handle table associated with a process
406 ExDestroyHandleTable(Process
->ObjectTable
,
407 DeleteHandleCallback
,
411 static BOOLEAN STDCALL
412 DuplicateHandleCallback(PHANDLE_TABLE HandleTable
,
413 PHANDLE_TABLE_ENTRY HandleTableEntry
,
416 POBJECT_HEADER ObjectHeader
;
421 Ret
= (HandleTableEntry
->u1
.ObAttributes
& EX_HANDLE_ENTRY_INHERITABLE
) != 0;
424 ObjectHeader
= EX_HTE_TO_HDR(HandleTableEntry
);
425 if(InterlockedIncrement(&ObjectHeader
->HandleCount
) == 1)
427 ObReferenceObjectByPointer(HEADER_TO_BODY(ObjectHeader
),
437 VOID
ObCreateHandleTable(PEPROCESS Parent
,
441 * FUNCTION: Creates a handle table for a process
443 * Parent = Parent process (or NULL if this is the first process)
444 * Inherit = True if the process should inherit its parent's handles
445 * Process = Process whose handle table is to be created
450 DPRINT("ObCreateHandleTable(Parent %x, Inherit %d, Process %x)\n",
451 Parent
,Inherit
,Process
);
454 Process
->ObjectTable
= ExDupHandleTable(Process
,
455 DuplicateHandleCallback
,
457 Parent
->ObjectTable
);
461 Process
->ObjectTable
= ExCreateHandleTable(Process
);
467 ObDeleteHandle(PEPROCESS Process
,
470 PHANDLE_TABLE_ENTRY HandleEntry
;
472 POBJECT_HEADER ObjectHeader
;
473 LONG ExHandle
= HANDLE_TO_EX_HANDLE(Handle
);
477 DPRINT("ObDeleteHandle(Handle %x)\n",Handle
);
479 KeEnterCriticalRegion();
481 HandleEntry
= ExMapHandleToPointer(Process
->ObjectTable
,
483 if(HandleEntry
!= NULL
)
485 if(HandleEntry
->u1
.ObAttributes
& EX_HANDLE_ENTRY_PROTECTFROMCLOSE
)
487 ExUnlockHandleTableEntry(Process
->ObjectTable
,
490 KeLeaveCriticalRegion();
492 return STATUS_HANDLE_NOT_CLOSABLE
;
495 ObjectHeader
= EX_HTE_TO_HDR(HandleEntry
);
496 Body
= HEADER_TO_BODY(ObjectHeader
);
498 ObpDecrementHandleCount(Body
);
500 /* destroy and unlock the handle entry */
501 ExDestroyHandleByEntry(Process
->ObjectTable
,
505 KeLeaveCriticalRegion();
507 return STATUS_SUCCESS
;
510 return STATUS_INVALID_HANDLE
;
515 ObCreateHandle(PEPROCESS Process
,
517 ACCESS_MASK GrantedAccess
,
519 PHANDLE HandleReturn
)
521 * FUNCTION: Add a handle referencing an object
523 * obj = Object body that the handle should refer to
524 * RETURNS: The created handle
525 * NOTE: The handle is valid only in the context of the current process
528 HANDLE_TABLE_ENTRY NewEntry
;
529 POBJECT_HEADER ObjectHeader
;
534 DPRINT("ObCreateHandle(Process %x, obj %x)\n",Process
,ObjectBody
);
539 ObjectHeader
= BODY_TO_HEADER(ObjectBody
);
541 ASSERT((ULONG_PTR
)ObjectHeader
& EX_HANDLE_ENTRY_LOCKED
);
543 NewEntry
.u1
.Object
= ObjectHeader
;
545 NewEntry
.u1
.ObAttributes
|= EX_HANDLE_ENTRY_INHERITABLE
;
547 NewEntry
.u1
.ObAttributes
&= ~EX_HANDLE_ENTRY_INHERITABLE
;
548 NewEntry
.u2
.GrantedAccess
= GrantedAccess
;
550 ExHandle
= ExCreateHandle(Process
->ObjectTable
,
552 DPRINT("ObCreateHandle(0x%x)==0x%x [HT:0x%x]\n", ObjectHeader
, *HandleReturn
, Process
->ObjectTable
);
553 if(ExHandle
!= EX_INVALID_HANDLE
)
555 if(InterlockedIncrement(&ObjectHeader
->HandleCount
) == 1)
557 ObReferenceObjectByPointer(ObjectBody
,
563 *HandleReturn
= EX_HANDLE_TO_HANDLE(ExHandle
);
565 return STATUS_SUCCESS
;
568 return STATUS_UNSUCCESSFUL
;
576 ObQueryObjectAuditingByHandle(IN HANDLE Handle
,
577 OUT PBOOLEAN GenerateOnClose
)
579 PHANDLE_TABLE_ENTRY HandleEntry
;
581 LONG ExHandle
= HANDLE_TO_EX_HANDLE(Handle
);
585 DPRINT("ObQueryObjectAuditingByHandle(Handle %x)\n", Handle
);
587 Process
= PsGetCurrentProcess();
589 KeEnterCriticalRegion();
591 HandleEntry
= ExMapHandleToPointer(Process
->ObjectTable
,
593 if(HandleEntry
!= NULL
)
595 *GenerateOnClose
= (HandleEntry
->u1
.ObAttributes
& EX_HANDLE_ENTRY_AUDITONCLOSE
) != 0;
597 ExUnlockHandleTableEntry(Process
->ObjectTable
,
600 KeLeaveCriticalRegion();
602 return STATUS_SUCCESS
;
605 KeLeaveCriticalRegion();
607 return STATUS_INVALID_HANDLE
;
612 * FUNCTION: Increments the reference count for an object and returns a
613 * pointer to its body
615 * Handle = Handle for the object
616 * DesiredAccess = Desired access to the object
619 * Object (OUT) = Points to the object body on return
620 * HandleInformation (OUT) = Contains information about the handle
627 ObReferenceObjectByHandle(HANDLE Handle
,
628 ACCESS_MASK DesiredAccess
,
629 POBJECT_TYPE ObjectType
,
630 KPROCESSOR_MODE AccessMode
,
632 POBJECT_HANDLE_INFORMATION HandleInformation
)
634 PHANDLE_TABLE_ENTRY HandleEntry
;
635 POBJECT_HEADER ObjectHeader
;
637 ACCESS_MASK GrantedAccess
;
638 PGENERIC_MAPPING GenericMapping
;
641 LONG ExHandle
= HANDLE_TO_EX_HANDLE(Handle
);
645 DPRINT("ObReferenceObjectByHandle(Handle %x, DesiredAccess %x, "
646 "ObjectType %x, AccessMode %d, Object %x)\n",Handle
,DesiredAccess
,
647 ObjectType
,AccessMode
,Object
);
650 * Handle special handle names
652 if (Handle
== NtCurrentProcess() &&
653 (ObjectType
== PsProcessType
|| ObjectType
== NULL
))
655 Status
= ObReferenceObjectByPointer(PsGetCurrentProcess(),
659 if (! NT_SUCCESS(Status
))
664 if (HandleInformation
!= NULL
)
666 HandleInformation
->HandleAttributes
= 0;
667 HandleInformation
->GrantedAccess
= PROCESS_ALL_ACCESS
;
670 *Object
= PsGetCurrentProcess();
671 DPRINT("Referencing current process %x\n", PsGetCurrentProcess());
672 return STATUS_SUCCESS
;
674 else if (Handle
== NtCurrentProcess())
677 return(STATUS_OBJECT_TYPE_MISMATCH
);
680 if (Handle
== NtCurrentThread() &&
681 (ObjectType
== PsThreadType
|| ObjectType
== NULL
))
683 Status
= ObReferenceObjectByPointer(PsGetCurrentThread(),
687 if (! NT_SUCCESS(Status
))
692 if (HandleInformation
!= NULL
)
694 HandleInformation
->HandleAttributes
= 0;
695 HandleInformation
->GrantedAccess
= THREAD_ALL_ACCESS
;
698 *Object
= PsGetCurrentThread();
700 return STATUS_SUCCESS
;
702 else if (Handle
== NtCurrentThread())
705 return(STATUS_OBJECT_TYPE_MISMATCH
);
708 KeEnterCriticalRegion();
710 HandleEntry
= ExMapHandleToPointer(PsGetCurrentProcess()->ObjectTable
,
712 if (HandleEntry
== NULL
)
714 KeLeaveCriticalRegion();
715 DPRINT("ExMapHandleToPointer() failed for handle 0x%x\n", Handle
);
716 return(STATUS_INVALID_HANDLE
);
719 ObjectHeader
= EX_HTE_TO_HDR(HandleEntry
);
720 ObjectBody
= HEADER_TO_BODY(ObjectHeader
);
722 DPRINT("locked1: ObjectHeader: 0x%x [HT:0x%x]\n", ObjectHeader
, PsGetCurrentProcess()->ObjectTable
);
724 ObReferenceObjectByPointer(ObjectBody
,
728 Attributes
= HandleEntry
->u1
.ObAttributes
& (EX_HANDLE_ENTRY_PROTECTFROMCLOSE
|
729 EX_HANDLE_ENTRY_INHERITABLE
|
730 EX_HANDLE_ENTRY_AUDITONCLOSE
);
731 GrantedAccess
= HandleEntry
->u2
.GrantedAccess
;
732 GenericMapping
= ObjectHeader
->ObjectType
->Mapping
;
734 if (ObjectType
!= NULL
&& ObjectType
!= ObjectHeader
->ObjectType
)
736 DPRINT("ObjectType mismatch: %wZ vs %wZ (handle 0x%x)\n", &ObjectType
->TypeName
, ObjectHeader
->ObjectType
? &ObjectHeader
->ObjectType
->TypeName
: NULL
, Handle
);
738 ExUnlockHandleTableEntry(PsGetCurrentProcess()->ObjectTable
,
741 KeLeaveCriticalRegion();
743 return(STATUS_OBJECT_TYPE_MISMATCH
);
746 ExUnlockHandleTableEntry(PsGetCurrentProcess()->ObjectTable
,
749 KeLeaveCriticalRegion();
751 if (DesiredAccess
&& AccessMode
!= KernelMode
)
753 RtlMapGenericMask(&DesiredAccess
, GenericMapping
);
755 if (!(GrantedAccess
& DesiredAccess
) &&
756 !((~GrantedAccess
) & DesiredAccess
))
759 return(STATUS_ACCESS_DENIED
);
763 if (HandleInformation
!= NULL
)
765 HandleInformation
->HandleAttributes
= Attributes
;
766 HandleInformation
->GrantedAccess
= GrantedAccess
;
769 *Object
= ObjectBody
;
771 return(STATUS_SUCCESS
);
775 /**********************************************************************
780 * Closes a handle reference to an object.
792 NtClose(IN HANDLE Handle
)
798 Status
= ObDeleteHandle(PsGetCurrentProcess(),
800 if (!NT_SUCCESS(Status
))
802 if(((PEPROCESS
)(KeGetCurrentThread()->ApcState
.Process
))->ExceptionPort
)
803 KeRaiseUserException(Status
);
807 return(STATUS_SUCCESS
);
815 ObInsertObject(IN PVOID Object
,
816 IN PACCESS_STATE PassedAccessState OPTIONAL
,
817 IN ACCESS_MASK DesiredAccess
,
818 IN ULONG AdditionalReferences
,
819 OUT PVOID
* ReferencedObject OPTIONAL
,
822 POBJECT_HEADER ObjectHeader
;
827 Access
= DesiredAccess
;
828 ObjectHeader
= BODY_TO_HEADER(Object
);
830 RtlMapGenericMask(&Access
,
831 ObjectHeader
->ObjectType
->Mapping
);
833 return(ObCreateHandle(PsGetCurrentProcess(),
836 ObjectHeader
->Inherit
,
842 ObpGetHandleCountByHandleTable(PHANDLE_TABLE HandleTable
)
844 return HandleTable
->HandleCount
;
848 * FUNCTION: Searches the handle table of a specified process whether it contains a
849 * valid handle to the Object we're looking for. If not, it'll create one.
852 * The parameters of this function is basically a mixture of some of the parameters
853 * of ObReferenceObjectByHandle() and ObReferenceObjectByPointer(). A little thinking
854 * about what this function does (by it's name) makes clear what parameters it requires.
855 * For example the AccessMode parameter of ObReferenceObjectByHandle/Pointer() is not
856 * required at all as it only has influence on the object security. This function doesn't
857 * want to get access to an object, it just looks for a valid handle and if it can't find
858 * one, it'll just create one. It wouldn't make sense to check for security again as the
859 * caller already has a pointer to the object.
861 * A test on an XP machine shows that this prototype appears to be correct.
864 * Process = This parameter simply describes in which handle table we're looking
865 * for a handle to the object.
866 * Object = The object pointer that we're looking for
867 * ObjectType = Just a sanity check as ObReferenceObjectByHandle() and
868 * ObReferenceObjectByPointer() provides.
869 * HandleInformation = This one has to be the opposite meaning of the usage in
870 * ObReferenceObjectByHandle(). If we actually found a valid
871 * handle in the table, we need to check against the information
872 * provided so we make sure this handle has all access rights
873 * (and attributes?!) we need. If they don't match, we can't
874 * use this handle and keep looking because the caller is likely
875 * to depend on these access rights.
876 * HandleReturn = The last parameter is the same as in ObCreateHandle(). If we could
877 * find a suitable handle in the handle table, return this handle, if
878 * not, we'll just create one using ObCreateHandle() with all access
879 * rights the caller needs.
886 ObFindHandleForObject(IN PEPROCESS Process
,
888 IN POBJECT_TYPE ObjectType
,
889 IN POBJECT_HANDLE_INFORMATION HandleInformation
,
890 OUT PHANDLE HandleReturn
)
893 return STATUS_UNSUCCESSFUL
;
897 ObpGetNextHandleByProcessCount(PSYSTEM_HANDLE_TABLE_ENTRY_INFO pshi
,
904 // pshi->HandleValue;
907 This will never work with ROS! M$, I guess uses 0 -> 65535.
908 Ros uses 0 -> 4294967295!
911 P
= (ULONG
) Process
->UniqueProcessId
;
912 pshi
->UniqueProcessId
= (USHORT
) P
;
914 // KeAcquireSpinLock( &Process->HandleTable.ListLock, &oldIrql );
916 // pshi->GrantedAccess;
918 // pshi->ObjectTypeIndex;
919 // pshi->HandleAttributes;
921 // KeReleaseSpinLock( &Process->HandleTable.ListLock, oldIrql );