NTOSKRNL PS: NtOpenThread implemented.
authorEmanuele Aliberti <ea@iol.it>
Wed, 20 Aug 2003 15:02:53 +0000 (15:02 +0000)
committerEmanuele Aliberti <ea@iol.it>
Wed, 20 Aug 2003 15:02:53 +0000 (15:02 +0000)
svn path=/trunk/; revision=5704

reactos/ntoskrnl/ps/thread.c

index feef72f..6b76a8a 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: thread.c,v 1.116 2003/08/18 11:52:31 hbirr Exp $
+/* $Id: thread.c,v 1.117 2003/08/20 15:02:53 ea Exp $
  *
  * COPYRIGHT:              See COPYING in the top level directory
  * PROJECT:                ReactOS kernel
@@ -648,13 +648,71 @@ NTSTATUS STDCALL NtAlertThread (IN HANDLE ThreadHandle)
    return(STATUS_SUCCESS);
 }
 
+/**********************************************************************
+ *     NtOpenThread/4
+ *
+ *     @implemented
+ */
 NTSTATUS STDCALL 
 NtOpenThread(OUT PHANDLE ThreadHandle,
             IN ACCESS_MASK DesiredAccess,
             IN POBJECT_ATTRIBUTES ObjectAttributes,
             IN PCLIENT_ID ClientId)
 {
-       UNIMPLEMENTED;
+   NTSTATUS Status = STATUS_INVALID_PARAMETER;
+
+   if((NULL != ThreadHandle)&&(NULL != ObjectAttributes))
+   {
+      PETHREAD EThread = NULL;
+
+      if((ClientId)
+       && (ClientId->UniqueProcess)
+       && (ClientId->UniqueThread))
+      {
+         // It is an error to specify both
+        // ObjectAttributes.ObjectName
+         // and ClientId.
+         if((ObjectAttributes)
+          && (ObjectAttributes->ObjectName)
+          && (0 < ObjectAttributes->ObjectName->Length))
+        {
+            return(STATUS_INVALID_PARAMETER_MIX);
+        }
+        // Parameters mix OK
+        Status = PsLookupProcessThreadByCid(ClientId,
+                     NULL,
+                     & EThread);
+      }
+      else if((ObjectAttributes)
+            && (ObjectAttributes->ObjectName)
+            && (0 < ObjectAttributes->ObjectName->Length))
+      {
+         // Three Ob attributes are forbidden
+         if(!(ObjectAttributes->Attributes &
+            (OBJ_PERMANENT | OBJ_EXCLUSIVE | OBJ_OPENIF)))
+        {
+            Status = ObReferenceObjectByName(ObjectAttributes->ObjectName,
+                        ObjectAttributes->Attributes,
+                        NULL,
+                        DesiredAccess,
+                        PsThreadType,
+                        UserMode,
+                        NULL,
+                        (PVOID*) & EThread);
+        }
+      }
+      // EThread may be OK...
+      if(STATUS_SUCCESS == Status)
+      {
+         Status = ObCreateHandle(PsGetCurrentProcess(),
+                     EThread,
+                     DesiredAccess,
+                     FALSE,
+                     ThreadHandle);
+         ObDereferenceObject(EThread); 
+      }
+   }
+   return(Status);  
 }
 
 NTSTATUS STDCALL