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 ObKillProcess(PEPROCESS Process
)
49 ObDeleteHandleTable(Process
);
53 ObpDecrementHandleCount(PVOID ObjectBody
)
55 POBJECT_HEADER ObjectHeader
= BODY_TO_HEADER(ObjectBody
);
56 LONG NewHandleCount
= InterlockedDecrement(&ObjectHeader
->HandleCount
);
58 if ((ObjectHeader
->ObjectType
!= NULL
) &&
59 (ObjectHeader
->ObjectType
->Close
!= NULL
))
61 /* the handle count should be decremented but we pass the previous value
63 ObjectHeader
->ObjectType
->Close(ObjectBody
, NewHandleCount
+ 1);
66 if(NewHandleCount
== 0)
68 ObDereferenceObject(ObjectBody
);
74 ObpQueryHandleAttributes(HANDLE Handle
,
75 POBJECT_HANDLE_ATTRIBUTE_INFORMATION HandleInfo
)
78 PHANDLE_TABLE_ENTRY HandleTableEntry
;
79 LONG ExHandle
= HANDLE_TO_EX_HANDLE(Handle
);
83 DPRINT("ObpQueryHandleAttributes(Handle %x)\n", Handle
);
85 KeEnterCriticalRegion();
87 Process
= PsGetCurrentProcess();
89 HandleTableEntry
= ExMapHandleToPointer(Process
->ObjectTable
,
91 if (HandleTableEntry
== NULL
)
93 KeLeaveCriticalRegion();
94 return STATUS_INVALID_HANDLE
;
97 HandleInfo
->Inherit
= (HandleTableEntry
->u1
.ObAttributes
& EX_HANDLE_ENTRY_INHERITABLE
) != 0;
98 HandleInfo
->ProtectFromClose
= (HandleTableEntry
->u1
.ObAttributes
& EX_HANDLE_ENTRY_PROTECTFROMCLOSE
) != 0;
100 ExUnlockHandleTableEntry(Process
->ObjectTable
,
103 KeLeaveCriticalRegion();
105 return STATUS_SUCCESS
;
110 ObpSetHandleAttributes(HANDLE Handle
,
111 POBJECT_HANDLE_ATTRIBUTE_INFORMATION HandleInfo
)
114 PHANDLE_TABLE_ENTRY HandleTableEntry
;
115 LONG ExHandle
= HANDLE_TO_EX_HANDLE(Handle
);
119 DPRINT("ObpSetHandleAttributes(Handle %x)\n", Handle
);
121 Process
= PsGetCurrentProcess();
123 KeEnterCriticalRegion();
125 HandleTableEntry
= ExMapHandleToPointer(Process
->ObjectTable
,
127 if (HandleTableEntry
== NULL
)
129 KeLeaveCriticalRegion();
130 return STATUS_INVALID_HANDLE
;
133 if (HandleInfo
->Inherit
)
134 HandleTableEntry
->u1
.ObAttributes
|= EX_HANDLE_ENTRY_INHERITABLE
;
136 HandleTableEntry
->u1
.ObAttributes
&= ~EX_HANDLE_ENTRY_INHERITABLE
;
138 if (HandleInfo
->ProtectFromClose
)
139 HandleTableEntry
->u1
.ObAttributes
|= EX_HANDLE_ENTRY_PROTECTFROMCLOSE
;
141 HandleTableEntry
->u1
.ObAttributes
&= ~EX_HANDLE_ENTRY_PROTECTFROMCLOSE
;
143 /* FIXME: Do we need to set anything in the object header??? */
145 ExUnlockHandleTableEntry(Process
->ObjectTable
,
148 KeLeaveCriticalRegion();
150 return STATUS_SUCCESS
;
155 ObDuplicateObject(PEPROCESS SourceProcess
,
156 PEPROCESS TargetProcess
,
158 PHANDLE TargetHandle
,
159 ACCESS_MASK DesiredAccess
,
160 BOOLEAN InheritHandle
,
163 PHANDLE_TABLE_ENTRY SourceHandleEntry
;
164 HANDLE_TABLE_ENTRY NewHandleEntry
;
166 POBJECT_HEADER ObjectHeader
;
168 LONG ExSourceHandle
= HANDLE_TO_EX_HANDLE(SourceHandle
);
169 ULONG NewHandleCount
;
173 KeEnterCriticalRegion();
175 SourceHandleEntry
= ExMapHandleToPointer(SourceProcess
->ObjectTable
,
177 if (SourceHandleEntry
== NULL
)
179 KeLeaveCriticalRegion();
180 return STATUS_INVALID_HANDLE
;
183 ObjectHeader
= EX_HTE_TO_HDR(SourceHandleEntry
);
184 ObjectBody
= HEADER_TO_BODY(ObjectHeader
);
186 NewHandleEntry
.u1
.Object
= SourceHandleEntry
->u1
.Object
;
188 NewHandleEntry
.u1
.ObAttributes
|= EX_HANDLE_ENTRY_INHERITABLE
;
190 NewHandleEntry
.u1
.ObAttributes
&= ~EX_HANDLE_ENTRY_INHERITABLE
;
191 NewHandleEntry
.u2
.GrantedAccess
= ((Options
& DUPLICATE_SAME_ACCESS
) ?
192 SourceHandleEntry
->u2
.GrantedAccess
:
195 /* reference the object so it doesn't get deleted after releasing the lock
196 and before creating a new handle for it */
197 ObReferenceObject(ObjectBody
);
199 /* increment the handle count of the object, it should always be >= 2 because
200 we're holding a handle lock to this object! if the new handle count was
201 1 here, we're in big trouble... it would've been safe to increment and
202 check the handle count without using interlocked functions because the
203 entry is locked, which means the handle count can't change. */
204 NewHandleCount
= InterlockedIncrement(&ObjectHeader
->HandleCount
);
205 ASSERT(NewHandleCount
>= 2);
207 ExUnlockHandleTableEntry(SourceProcess
->ObjectTable
,
210 KeLeaveCriticalRegion();
212 /* attempt to create the new handle */
213 ExTargetHandle
= ExCreateHandle(TargetProcess
->ObjectTable
,
215 if (ExTargetHandle
!= EX_INVALID_HANDLE
)
217 if (Options
& DUPLICATE_CLOSE_SOURCE
)
219 ObDeleteHandle(SourceProcess
,
223 ObDereferenceObject(ObjectBody
);
225 *TargetHandle
= EX_HANDLE_TO_HANDLE(ExTargetHandle
);
227 return STATUS_SUCCESS
;
231 /* decrement the handle count we previously incremented, but don't call the
232 closing procedure because we're not closing a handle! */
233 if(InterlockedDecrement(&ObjectHeader
->HandleCount
) == 0)
235 ObDereferenceObject(ObjectBody
);
238 ObDereferenceObject(ObjectBody
);
239 return STATUS_UNSUCCESSFUL
;
247 NtDuplicateObject (IN HANDLE SourceProcessHandle
,
248 IN HANDLE SourceHandle
,
249 IN HANDLE TargetProcessHandle
,
250 OUT PHANDLE TargetHandle
,
251 IN ACCESS_MASK DesiredAccess
,
252 IN BOOLEAN InheritHandle
,
255 * FUNCTION: Copies a handle from one process space to another
257 * SourceProcessHandle = The source process owning the handle. The
258 * source process should have opened
259 * the SourceHandle with PROCESS_DUP_HANDLE
261 * SourceHandle = The handle to the object.
262 * TargetProcessHandle = The destination process owning the handle
263 * TargetHandle (OUT) = Caller should supply storage for the
265 * DesiredAccess = The desired access to the handle.
266 * InheritHandle = Indicates wheter the new handle will be inheritable
268 * Options = Specifies special actions upon duplicating the handle.
269 * Can be one of the values DUPLICATE_CLOSE_SOURCE |
270 * DUPLICATE_SAME_ACCESS. DUPLICATE_CLOSE_SOURCE specifies
271 * that the source handle should be closed after duplicating.
272 * DUPLICATE_SAME_ACCESS specifies to ignore the
273 * DesiredAccess paramter and just grant the same access to
276 * REMARKS: This function maps to the win32 DuplicateHandle.
279 PEPROCESS SourceProcess
;
280 PEPROCESS TargetProcess
;
282 KPROCESSOR_MODE PreviousMode
;
283 NTSTATUS Status
= STATUS_SUCCESS
;
287 PreviousMode
= ExGetPreviousMode();
289 if(PreviousMode
!= KernelMode
)
293 ProbeForWrite(TargetHandle
,
299 Status
= _SEH_GetExceptionCode();
303 if(!NT_SUCCESS(Status
))
309 Status
= ObReferenceObjectByHandle(SourceProcessHandle
,
313 (PVOID
*)&SourceProcess
,
315 if (!NT_SUCCESS(Status
))
320 Status
= ObReferenceObjectByHandle(TargetProcessHandle
,
324 (PVOID
*)&TargetProcess
,
326 if (!NT_SUCCESS(Status
))
328 ObDereferenceObject(SourceProcess
);
332 /* Check for magic handle first */
333 if (SourceHandle
== NtCurrentThread() ||
334 SourceHandle
== NtCurrentProcess())
338 Status
= ObReferenceObjectByHandle(SourceHandle
,
344 if(NT_SUCCESS(Status
))
346 Status
= ObCreateHandle(TargetProcess
,
352 ObDereferenceObject(ObjectBody
);
354 if (Options
& DUPLICATE_CLOSE_SOURCE
)
356 ObDeleteHandle(SourceProcess
,
363 Status
= ObDuplicateObject(SourceProcess
,
372 ObDereferenceObject(TargetProcess
);
373 ObDereferenceObject(SourceProcess
);
375 if(NT_SUCCESS(Status
))
379 *TargetHandle
= hTarget
;
383 Status
= _SEH_GetExceptionCode();
392 DeleteHandleCallback(PHANDLE_TABLE HandleTable
,
397 POBJECT_HEADER ObjectHeader
;
402 ObjectHeader
= EX_OBJ_TO_HDR(Object
);
403 ObjectBody
= HEADER_TO_BODY(ObjectHeader
);
405 ObpDecrementHandleCount(ObjectBody
);
408 VOID
ObDeleteHandleTable(PEPROCESS Process
)
410 * FUNCTION: Deletes the handle table associated with a process
415 ExDestroyHandleTable(Process
->ObjectTable
,
416 DeleteHandleCallback
,
420 static BOOLEAN STDCALL
421 DuplicateHandleCallback(PHANDLE_TABLE HandleTable
,
422 PHANDLE_TABLE_ENTRY HandleTableEntry
,
425 POBJECT_HEADER ObjectHeader
;
430 Ret
= (HandleTableEntry
->u1
.ObAttributes
& EX_HANDLE_ENTRY_INHERITABLE
) != 0;
433 ObjectHeader
= EX_HTE_TO_HDR(HandleTableEntry
);
434 if(InterlockedIncrement(&ObjectHeader
->HandleCount
) == 1)
436 ObReferenceObjectByPointer(HEADER_TO_BODY(ObjectHeader
),
446 VOID
ObCreateHandleTable(PEPROCESS Parent
,
450 * FUNCTION: Creates a handle table for a process
452 * Parent = Parent process (or NULL if this is the first process)
453 * Inherit = True if the process should inherit its parent's handles
454 * Process = Process whose handle table is to be created
459 DPRINT("ObCreateHandleTable(Parent %x, Inherit %d, Process %x)\n",
460 Parent
,Inherit
,Process
);
463 Process
->ObjectTable
= ExDupHandleTable(Process
,
464 DuplicateHandleCallback
,
466 Parent
->ObjectTable
);
470 Process
->ObjectTable
= ExCreateHandleTable(Process
);
476 ObDeleteHandle(PEPROCESS Process
,
479 PHANDLE_TABLE_ENTRY HandleEntry
;
481 POBJECT_HEADER ObjectHeader
;
482 LONG ExHandle
= HANDLE_TO_EX_HANDLE(Handle
);
486 DPRINT("ObDeleteHandle(Handle %x)\n",Handle
);
488 KeEnterCriticalRegion();
490 HandleEntry
= ExMapHandleToPointer(Process
->ObjectTable
,
492 if(HandleEntry
!= NULL
)
494 if(HandleEntry
->u1
.ObAttributes
& EX_HANDLE_ENTRY_PROTECTFROMCLOSE
)
496 ExUnlockHandleTableEntry(Process
->ObjectTable
,
499 KeLeaveCriticalRegion();
501 return STATUS_HANDLE_NOT_CLOSABLE
;
504 ObjectHeader
= EX_HTE_TO_HDR(HandleEntry
);
505 Body
= HEADER_TO_BODY(ObjectHeader
);
507 ObpDecrementHandleCount(Body
);
509 /* destroy and unlock the handle entry */
510 ExDestroyHandleByEntry(Process
->ObjectTable
,
514 KeLeaveCriticalRegion();
516 return STATUS_SUCCESS
;
518 KeLeaveCriticalRegion();
519 return STATUS_INVALID_HANDLE
;
524 ObCreateHandle(PEPROCESS Process
,
526 ACCESS_MASK GrantedAccess
,
528 PHANDLE HandleReturn
)
530 * FUNCTION: Add a handle referencing an object
532 * obj = Object body that the handle should refer to
533 * RETURNS: The created handle
534 * NOTE: The handle is valid only in the context of the current process
537 HANDLE_TABLE_ENTRY NewEntry
;
538 POBJECT_HEADER ObjectHeader
;
543 DPRINT("ObCreateHandle(Process %x, obj %x)\n",Process
,ObjectBody
);
548 ObjectHeader
= BODY_TO_HEADER(ObjectBody
);
550 ASSERT((ULONG_PTR
)ObjectHeader
& EX_HANDLE_ENTRY_LOCKED
);
552 NewEntry
.u1
.Object
= ObjectHeader
;
554 NewEntry
.u1
.ObAttributes
|= EX_HANDLE_ENTRY_INHERITABLE
;
556 NewEntry
.u1
.ObAttributes
&= ~EX_HANDLE_ENTRY_INHERITABLE
;
557 NewEntry
.u2
.GrantedAccess
= GrantedAccess
;
559 ExHandle
= ExCreateHandle(Process
->ObjectTable
,
561 DPRINT("ObCreateHandle(0x%x)==0x%x [HT:0x%x]\n", ObjectHeader
, *HandleReturn
, Process
->ObjectTable
);
562 if(ExHandle
!= EX_INVALID_HANDLE
)
564 if(InterlockedIncrement(&ObjectHeader
->HandleCount
) == 1)
566 ObReferenceObjectByPointer(ObjectBody
,
572 *HandleReturn
= EX_HANDLE_TO_HANDLE(ExHandle
);
574 return STATUS_SUCCESS
;
577 return STATUS_UNSUCCESSFUL
;
585 ObQueryObjectAuditingByHandle(IN HANDLE Handle
,
586 OUT PBOOLEAN GenerateOnClose
)
588 PHANDLE_TABLE_ENTRY HandleEntry
;
590 LONG ExHandle
= HANDLE_TO_EX_HANDLE(Handle
);
594 DPRINT("ObQueryObjectAuditingByHandle(Handle %x)\n", Handle
);
596 Process
= PsGetCurrentProcess();
598 KeEnterCriticalRegion();
600 HandleEntry
= ExMapHandleToPointer(Process
->ObjectTable
,
602 if(HandleEntry
!= NULL
)
604 *GenerateOnClose
= (HandleEntry
->u1
.ObAttributes
& EX_HANDLE_ENTRY_AUDITONCLOSE
) != 0;
606 ExUnlockHandleTableEntry(Process
->ObjectTable
,
609 KeLeaveCriticalRegion();
611 return STATUS_SUCCESS
;
614 KeLeaveCriticalRegion();
616 return STATUS_INVALID_HANDLE
;
621 * FUNCTION: Increments the reference count for an object and returns a
622 * pointer to its body
624 * Handle = Handle for the object
625 * DesiredAccess = Desired access to the object
628 * Object (OUT) = Points to the object body on return
629 * HandleInformation (OUT) = Contains information about the handle
636 ObReferenceObjectByHandle(HANDLE Handle
,
637 ACCESS_MASK DesiredAccess
,
638 POBJECT_TYPE ObjectType
,
639 KPROCESSOR_MODE AccessMode
,
641 POBJECT_HANDLE_INFORMATION HandleInformation
)
643 PHANDLE_TABLE_ENTRY HandleEntry
;
644 POBJECT_HEADER ObjectHeader
;
646 ACCESS_MASK GrantedAccess
;
647 PGENERIC_MAPPING GenericMapping
;
650 LONG ExHandle
= HANDLE_TO_EX_HANDLE(Handle
);
654 DPRINT("ObReferenceObjectByHandle(Handle %x, DesiredAccess %x, "
655 "ObjectType %x, AccessMode %d, Object %x)\n",Handle
,DesiredAccess
,
656 ObjectType
,AccessMode
,Object
);
659 * Handle special handle names
661 if (Handle
== NtCurrentProcess() &&
662 (ObjectType
== PsProcessType
|| ObjectType
== NULL
))
664 Status
= ObReferenceObjectByPointer(PsGetCurrentProcess(),
668 if (! NT_SUCCESS(Status
))
673 if (HandleInformation
!= NULL
)
675 HandleInformation
->HandleAttributes
= 0;
676 HandleInformation
->GrantedAccess
= PROCESS_ALL_ACCESS
;
679 *Object
= PsGetCurrentProcess();
680 DPRINT("Referencing current process %x\n", PsGetCurrentProcess());
681 return STATUS_SUCCESS
;
683 else if (Handle
== NtCurrentProcess())
686 return(STATUS_OBJECT_TYPE_MISMATCH
);
689 if (Handle
== NtCurrentThread() &&
690 (ObjectType
== PsThreadType
|| ObjectType
== NULL
))
692 Status
= ObReferenceObjectByPointer(PsGetCurrentThread(),
696 if (! NT_SUCCESS(Status
))
701 if (HandleInformation
!= NULL
)
703 HandleInformation
->HandleAttributes
= 0;
704 HandleInformation
->GrantedAccess
= THREAD_ALL_ACCESS
;
707 *Object
= PsGetCurrentThread();
709 return STATUS_SUCCESS
;
711 else if (Handle
== NtCurrentThread())
714 return(STATUS_OBJECT_TYPE_MISMATCH
);
717 KeEnterCriticalRegion();
719 HandleEntry
= ExMapHandleToPointer(PsGetCurrentProcess()->ObjectTable
,
721 if (HandleEntry
== NULL
)
723 KeLeaveCriticalRegion();
724 DPRINT("ExMapHandleToPointer() failed for handle 0x%x\n", Handle
);
725 return(STATUS_INVALID_HANDLE
);
728 ObjectHeader
= EX_HTE_TO_HDR(HandleEntry
);
729 ObjectBody
= HEADER_TO_BODY(ObjectHeader
);
731 DPRINT("locked1: ObjectHeader: 0x%x [HT:0x%x]\n", ObjectHeader
, PsGetCurrentProcess()->ObjectTable
);
733 ObReferenceObjectByPointer(ObjectBody
,
737 Attributes
= HandleEntry
->u1
.ObAttributes
& (EX_HANDLE_ENTRY_PROTECTFROMCLOSE
|
738 EX_HANDLE_ENTRY_INHERITABLE
|
739 EX_HANDLE_ENTRY_AUDITONCLOSE
);
740 GrantedAccess
= HandleEntry
->u2
.GrantedAccess
;
741 GenericMapping
= ObjectHeader
->ObjectType
->Mapping
;
743 if (ObjectType
!= NULL
&& ObjectType
!= ObjectHeader
->ObjectType
)
745 DPRINT("ObjectType mismatch: %wZ vs %wZ (handle 0x%x)\n", &ObjectType
->TypeName
, ObjectHeader
->ObjectType
? &ObjectHeader
->ObjectType
->TypeName
: NULL
, Handle
);
747 ExUnlockHandleTableEntry(PsGetCurrentProcess()->ObjectTable
,
750 KeLeaveCriticalRegion();
751 ObDereferenceObject(ObjectBody
);
753 return(STATUS_OBJECT_TYPE_MISMATCH
);
756 ExUnlockHandleTableEntry(PsGetCurrentProcess()->ObjectTable
,
759 KeLeaveCriticalRegion();
761 if (DesiredAccess
&& AccessMode
!= KernelMode
)
763 RtlMapGenericMask(&DesiredAccess
, GenericMapping
);
765 if (!(GrantedAccess
& DesiredAccess
) &&
766 !((~GrantedAccess
) & DesiredAccess
))
768 ObDereferenceObject(ObjectBody
);
770 return(STATUS_ACCESS_DENIED
);
774 if (HandleInformation
!= NULL
)
776 HandleInformation
->HandleAttributes
= Attributes
;
777 HandleInformation
->GrantedAccess
= GrantedAccess
;
780 *Object
= ObjectBody
;
782 return(STATUS_SUCCESS
);
786 /**********************************************************************
791 * Closes a handle reference to an object.
803 NtClose(IN HANDLE Handle
)
809 Status
= ObDeleteHandle(PsGetCurrentProcess(),
811 if (!NT_SUCCESS(Status
))
813 if(((PEPROCESS
)(KeGetCurrentThread()->ApcState
.Process
))->ExceptionPort
)
814 KeRaiseUserException(Status
);
818 return(STATUS_SUCCESS
);
826 ObInsertObject(IN PVOID Object
,
827 IN PACCESS_STATE PassedAccessState OPTIONAL
,
828 IN ACCESS_MASK DesiredAccess
,
829 IN ULONG AdditionalReferences
,
830 OUT PVOID
* ReferencedObject OPTIONAL
,
833 POBJECT_HEADER ObjectHeader
;
838 Access
= DesiredAccess
;
839 ObjectHeader
= BODY_TO_HEADER(Object
);
841 RtlMapGenericMask(&Access
,
842 ObjectHeader
->ObjectType
->Mapping
);
844 return(ObCreateHandle(PsGetCurrentProcess(),
847 ObjectHeader
->Inherit
,
853 ObpGetHandleCountByHandleTable(PHANDLE_TABLE HandleTable
)
855 return HandleTable
->HandleCount
;
859 * FUNCTION: Searches the handle table of a specified process whether it contains a
860 * valid handle to the Object we're looking for. If not, it'll create one.
863 * The parameters of this function is basically a mixture of some of the parameters
864 * of ObReferenceObjectByHandle() and ObReferenceObjectByPointer(). A little thinking
865 * about what this function does (by it's name) makes clear what parameters it requires.
866 * For example the AccessMode parameter of ObReferenceObjectByHandle/Pointer() is not
867 * required at all as it only has influence on the object security. This function doesn't
868 * want to get access to an object, it just looks for a valid handle and if it can't find
869 * one, it'll just create one. It wouldn't make sense to check for security again as the
870 * caller already has a pointer to the object.
872 * A test on an XP machine shows that this prototype appears to be correct.
875 * Process = This parameter simply describes in which handle table we're looking
876 * for a handle to the object.
877 * Object = The object pointer that we're looking for
878 * ObjectType = Just a sanity check as ObReferenceObjectByHandle() and
879 * ObReferenceObjectByPointer() provides.
880 * HandleInformation = This one has to be the opposite meaning of the usage in
881 * ObReferenceObjectByHandle(). If we actually found a valid
882 * handle in the table, we need to check against the information
883 * provided so we make sure this handle has all access rights
884 * (and attributes?!) we need. If they don't match, we can't
885 * use this handle and keep looking because the caller is likely
886 * to depend on these access rights.
887 * HandleReturn = The last parameter is the same as in ObCreateHandle(). If we could
888 * find a suitable handle in the handle table, return this handle, if
889 * not, we'll just create one using ObCreateHandle() with all access
890 * rights the caller needs.
897 ObFindHandleForObject(IN PEPROCESS Process
,
899 IN POBJECT_TYPE ObjectType
,
900 IN POBJECT_HANDLE_INFORMATION HandleInformation
,
901 OUT PHANDLE HandleReturn
)
904 return STATUS_UNSUCCESSFUL
;
908 ObpGetNextHandleByProcessCount(PSYSTEM_HANDLE_TABLE_ENTRY_INFO pshi
,
915 // pshi->HandleValue;
918 This will never work with ROS! M$, I guess uses 0 -> 65535.
919 Ros uses 0 -> 4294967295!
922 P
= (ULONG
) Process
->UniqueProcessId
;
923 pshi
->UniqueProcessId
= (USHORT
) P
;
925 // KeAcquireSpinLock( &Process->HandleTable.ListLock, &oldIrql );
927 // pshi->GrantedAccess;
929 // pshi->ObjectTypeIndex;
930 // pshi->HandleAttributes;
932 // KeReleaseSpinLock( &Process->HandleTable.ListLock, oldIrql );