Implement duplication of NtCurrentThread() pseudo-handle

svn path=/trunk/; revision=4549
This commit is contained in:
Gé van Geldorp 2003-04-18 09:37:01 +00:00
parent 63401fccd2
commit 296d8bc63f

View file

@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
/* $Id: handle.c,v 1.43 2003/03/17 22:28:55 gdalsnes Exp $ /* $Id: handle.c,v 1.44 2003/04/18 09:37:01 gvg Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -217,40 +217,60 @@ NtDuplicateObject (IN HANDLE SourceProcessHandle,
ObDereferenceObject(SourceProcess); ObDereferenceObject(SourceProcess);
return(Status); return(Status);
} }
KeAcquireSpinLock(&SourceProcess->HandleTable.ListLock, &oldIrql);
SourceHandleRep = ObpGetObjectByHandle(&SourceProcess->HandleTable, /* Check for magic handle first */
SourceHandle); if (SourceHandle == NtCurrentThread())
if (SourceHandleRep == NULL)
{ {
KeReleaseSpinLock(&SourceProcess->HandleTable.ListLock, oldIrql); ObReferenceObjectByHandle(SourceHandle,
ObDereferenceObject(SourceProcess); PROCESS_DUP_HANDLE,
ObDereferenceObject(TargetProcess); NULL,
return(STATUS_INVALID_HANDLE); UserMode,
&ObjectBody,
NULL);
ObCreateHandle(TargetProcess,
ObjectBody,
THREAD_ALL_ACCESS,
InheritHandle,
&TargetHandle);
} }
ObjectBody = SourceHandleRep->ObjectBody; else
ObReferenceObjectByPointer(ObjectBody, {
0, KeAcquireSpinLock(&SourceProcess->HandleTable.ListLock, &oldIrql);
NULL, SourceHandleRep = ObpGetObjectByHandle(&SourceProcess->HandleTable,
UserMode); SourceHandle);
if (SourceHandleRep == NULL)
{
KeReleaseSpinLock(&SourceProcess->HandleTable.ListLock, oldIrql);
ObDereferenceObject(SourceProcess);
ObDereferenceObject(TargetProcess);
return(STATUS_INVALID_HANDLE);
}
ObjectBody = SourceHandleRep->ObjectBody;
ObReferenceObjectByPointer(ObjectBody,
0,
NULL,
UserMode);
if (Options & DUPLICATE_SAME_ACCESS) if (Options & DUPLICATE_SAME_ACCESS)
{ {
DesiredAccess = SourceHandleRep->GrantedAccess; DesiredAccess = SourceHandleRep->GrantedAccess;
} }
KeReleaseSpinLock(&SourceProcess->HandleTable.ListLock, oldIrql); KeReleaseSpinLock(&SourceProcess->HandleTable.ListLock, oldIrql);
if (!SourceHandleRep->Inherit) if (!SourceHandleRep->Inherit)
{ {
ObDereferenceObject(TargetProcess); ObDereferenceObject(TargetProcess);
ObDereferenceObject(SourceProcess); ObDereferenceObject(SourceProcess);
ObDereferenceObject(ObjectBody); ObDereferenceObject(ObjectBody);
return STATUS_INVALID_HANDLE; return STATUS_INVALID_HANDLE;
}
ObCreateHandle(TargetProcess,
ObjectBody,
DesiredAccess,
InheritHandle,
&TargetHandle);
} }
ObCreateHandle(TargetProcess,
ObjectBody,
DesiredAccess,
InheritHandle,
&TargetHandle);
if (Options & DUPLICATE_CLOSE_SOURCE) if (Options & DUPLICATE_CLOSE_SOURCE)
{ {