Update EPROCESS to latest version. Basic Fast Referencing Stubs to allow Token access...
authorAlex Ionescu <aionescu@gmail.com>
Fri, 6 May 2005 22:54:40 +0000 (22:54 +0000)
committerAlex Ionescu <aionescu@gmail.com>
Fri, 6 May 2005 22:54:40 +0000 (22:54 +0000)
svn path=/trunk/; revision=15065

22 files changed:
reactos/include/ddk/extypes.h
reactos/include/ddk/setypes.h
reactos/ntoskrnl/ex/sysinfo.c
reactos/ntoskrnl/include/internal/mm.h
reactos/ntoskrnl/include/internal/ob.h
reactos/ntoskrnl/include/internal/ps.h
reactos/ntoskrnl/include/internal/se.h
reactos/ntoskrnl/io/irp.c
reactos/ntoskrnl/kd/wrappers/gdbstub.c
reactos/ntoskrnl/kdbg/kdb_cli.c
reactos/ntoskrnl/ob/object.c
reactos/ntoskrnl/ps/debug.c
reactos/ntoskrnl/ps/job.c
reactos/ntoskrnl/ps/kill.c
reactos/ntoskrnl/ps/process.c
reactos/ntoskrnl/ps/psmgr.c
reactos/ntoskrnl/ps/query.c
reactos/ntoskrnl/ps/security.c
reactos/ntoskrnl/ps/thread.c
reactos/ntoskrnl/ps/win32.c
reactos/ntoskrnl/se/token.c
reactos/w32api/include/ddk/winddk.h

index 29cfd89..de23f80 100644 (file)
@@ -94,6 +94,28 @@ typedef struct _EX_RUNDOWN_REF {
     };
 } EX_RUNDOWN_REF, *PEX_RUNDOWN_REF;
 
+typedef struct _EX_FAST_REF {
+    union {
+        PVOID Object;
+        ULONG RefCnt:3;
+        ULONG Value;
+    };
+} EX_FAST_REF, *PEX_FAST_REF;
+
+typedef struct _EX_PUSH_LOCK {
+    union {
+        struct {
+            ULONG Locked:1;
+            ULONG Waiting:1;
+            ULONG Waking:1;
+            ULONG MultipleShared:1;
+            ULONG Shared:28;
+        };
+        ULONG Value;
+        PVOID Ptr;
+    };
+} EX_PUSH_LOCK, *PEX_PUSH_LOCK;
+
 typedef struct 
 {
    LONG Count;
index 10bdff2..0871a43 100644 (file)
@@ -151,6 +151,12 @@ typedef struct _SECURITY_CLIENT_CONTEXT
     TOKEN_CONTROL               ClientTokenControl;
 } SECURITY_CLIENT_CONTEXT, *PSECURITY_CLIENT_CONTEXT;
 
+#ifndef __USE_W32API
+typedef struct _SE_AUDIT_PROCESS_CREATION_INFO
+{
+    struct _OBJECT_NAME_INFORMATION *ImageFileName;
+} SE_AUDIT_PROCESS_CREATION_INFO, *PSE_AUDIT_PROCESS_CREATION_INFO;
+#endif
 
 typedef struct _SE_EXPORTS
 {
index 65883e2..514cff7 100644 (file)
@@ -633,23 +633,17 @@ QSI_DEF(SystemProcessInformation)
                SpiCur->InheritedFromUniqueProcessId = pr->InheritedFromUniqueProcessId;
                SpiCur->HandleCount = (pr->ObjectTable ? ObpGetHandleCountByHandleTable(pr->ObjectTable) : 0);
                SpiCur->PeakVirtualSize = pr->PeakVirtualSize;
-               SpiCur->VirtualSize = pr->VirtualSize.QuadPart;
-               SpiCur->PageFaultCount = pr->LastFaultCount;
+               SpiCur->VirtualSize = pr->VirtualSize;
+               SpiCur->PageFaultCount = pr->Vm.PageFaultCount;
                SpiCur->PeakWorkingSetSize = pr->Vm.PeakWorkingSetSize; // Is this right using ->Vm. here ?
                SpiCur->WorkingSetSize = pr->Vm.WorkingSetSize; // Is this right using ->Vm. here ?
-               SpiCur->QuotaPeakPagedPoolUsage =
-                                       pr->QuotaPeakPoolUsage[0];
-               SpiCur->QuotaPagedPoolUsage =
-                                       pr->QuotaPoolUsage[0];
-               SpiCur->QuotaPeakNonPagedPoolUsage =
-                                       pr->QuotaPeakPoolUsage[1];
-               SpiCur->QuotaNonPagedPoolUsage =
-                                       pr->QuotaPoolUsage[1];
-               SpiCur->PagefileUsage = pr->PagefileUsage; // FIXME
-               SpiCur->PeakPagefileUsage = pr->PeakPagefileUsage;
-               // KJK::Hyperion: I don't know what does this mean. VM_COUNTERS
-               // doesn't seem to contain any equivalent field
-               //SpiCur->TotalPrivateBytes = pr->NumberOfPrivatePages; //FIXME: bytes != pages
+               SpiCur->QuotaPeakPagedPoolUsage = pr->QuotaPeak[0];
+               SpiCur->QuotaPagedPoolUsage = pr->QuotaUsage[0];
+               SpiCur->QuotaPeakNonPagedPoolUsage = pr->QuotaPeak[1];
+               SpiCur->QuotaNonPagedPoolUsage = pr->QuotaUsage[1];
+               SpiCur->PagefileUsage = pr->QuotaUsage[3];
+               SpiCur->PeakPagefileUsage = pr->QuotaPeak[3];
+               SpiCur->PrivateUsage = pr->CommitCharge;
 
           current_entry = pr->ThreadListHead.Flink;
           while (current_entry != &pr->ThreadListHead)
index 24d06a6..a69c4bd 100644 (file)
@@ -188,6 +188,28 @@ typedef struct _PAGEFAULT_HISTORY
 
 #endif /* __USE_W32API */
 
+typedef struct _MMADDRESS_NODE
+{
+   union {
+       ULONG Balance:2;
+       struct _MMADDRESS_NODE *Parent;
+   } u1;
+   struct _MMADDRESS_NODE *LeftChild;
+   struct _MMADDRESS_NODE *RightChild;
+   ULONG StartingVpn;
+   ULONG EndingVpn;
+} MMADDRESS_NODE, *PMMADDRESS_NODE;
+
+typedef struct _MM_AVL_TABLE
+{
+    MMADDRESS_NODE BalancedRoot;
+    ULONG DepthOfTree:5;
+    ULONG Unused:3;
+    ULONG NumberGenericTableElements:24;
+    PVOID NodeHint;
+    PVOID NodeFreeHint;
+} MM_AVL_TABLE, *PMM_AVL_TABLE;
+
 typedef struct _MEMORY_AREA
 {
   PVOID StartingAddress;
index 4efc22f..1b68c44 100644 (file)
@@ -209,7 +209,6 @@ typedef struct _TYPE_OBJECT
   POBJECT_TYPE ObjectType;
 } TYPE_OBJECT, *PTYPE_OBJECT;
 
-
 /*
  * Enumeration of object types
  */
@@ -326,6 +325,25 @@ ObpReferenceCachedSecurityDescriptor(IN PSECURITY_DESCRIPTOR SecurityDescriptor)
 VOID
 ObpDereferenceCachedSecurityDescriptor(IN PSECURITY_DESCRIPTOR SecurityDescriptor);
 
+VOID
+FASTCALL
+ObInitializeFastReference(IN PEX_FAST_REF FastRef, 
+                          PVOID Object);
+
+PVOID
+FASTCALL
+ObFastReplaceObject(IN PEX_FAST_REF FastRef,
+                    PVOID Object);
+                    
+PVOID
+FASTCALL
+ObFastReferenceObject(IN PEX_FAST_REF FastRef);
+
+VOID
+FASTCALL
+ObFastDereferenceObject(IN PEX_FAST_REF FastRef,
+                        PVOID Object);
+                        
 /* Secure object information functions */
 
 typedef struct _CAPTURED_OBJECT_ATTRIBUTES
index 11ce50e..e995122 100644 (file)
@@ -126,127 +126,140 @@ typedef struct _ETHREAD
 typedef struct _ETHREAD *PETHREAD;
 
 #endif /* __USE_W32API */
-
+  
+#include <pshpack4.h>
 struct _EPROCESS
 {
-  /* Microkernel specific process state. */
-  KPROCESS              Pcb;                          /* 000 */
-  /* Exit status of the process. */
-  NTSTATUS              ExitStatus;                   /* 068 */
-  /* Unknown. */
-  KEVENT                LockEvent;                    /* 06C */
-  /* Unknown. */
-  ULONG                 LockCount;                    /* 07C */
-
-  /* Time of process creation. */
-  LARGE_INTEGER         CreateTime;                   /* 080 */
-
-  /* Time of process exit. */
-  LARGE_INTEGER         ExitTime;                     /* 088 */
-  /* Unknown. */
-  PKTHREAD              LockOwner;                    /* 090 */
-  /* Process id. */
-  HANDLE                UniqueProcessId;              /* 094 */
-  /* Unknown. */
-  LIST_ENTRY            ActiveProcessLinks;           /* 098 */
-  /* Unknown. */
-  ULONG                 QuotaPeakPoolUsage[2];        /* 0A0 */
-  /* Unknown. */
-  ULONG                 QuotaPoolUsage[2];            /* 0A8 */
-  /* Unknown. */
-  ULONG                 PagefileUsage;                /* 0B0 */
-  /* Unknown. */
-  ULONG                 CommitCharge;                 /* 0B4 */
-  /* Unknown. */
-  ULONG                 PeakPagefileUsage;            /* 0B8 */
-  /* Unknown. */
-  ULONG                 PeakVirtualSize;              /* 0BC */
-  /* Unknown. */
-  LARGE_INTEGER         VirtualSize;                  /* 0C0 */
-
-  MMSUPPORT             Vm;
-  LIST_ENTRY            SessionProcessLinks;
-  struct _EPORT         *DebugPort;
-  struct _EPORT         *ExceptionPort;
-  PHANDLE_TABLE         ObjectTable;
-  PVOID                 Token;
-  FAST_MUTEX            WorkingSetLock;
-  ULONG                 WorkingSetPage;
-  UCHAR                 ProcessOutswapEnabled;
-  UCHAR                 ProcessOutswapped;
-  UCHAR                 AddressSpaceInitialized;
-  UCHAR                 AddressSpaceDeleted;
-  FAST_MUTEX            AddressCreationLock;
-  KSPIN_LOCK            HyperSpaceLock;
-  PETHREAD              ForkInProgress;
-  USHORT                VmOperation;
-  UCHAR                 ForkWasSuccessful;
-  UCHAR                 MmAgressiveWsTrimMask;
-  PKEVENT               VmOperationEvent;
-  PVOID                 PaeTop;
-  ULONG                 LastFaultCount;
-  ULONG                 ModifiedPageCount;
-  PVOID                 VadRoot;
-  PVOID                 VadHint;
-  PVOID                 CloneRoot;
-  ULONG                 NumberOfPrivatePages;
-  ULONG                 NumberOfLockedPages;
-  USHORT                NextPageColor;
-  UCHAR                 ExitProcessCalled;
-  UCHAR                 CreateProcessReported;
-  HANDLE                SectionHandle;
-  PPEB                  Peb;
-  PVOID                 SectionBaseAddress;
-  PEPROCESS_QUOTA_BLOCK QuotaBlock;
-  NTSTATUS              LastThreadExitStatus;
-  PPAGEFAULT_HISTORY    WorkingSetWatch;
-  HANDLE                Win32WindowStation;
-  HANDLE                InheritedFromUniqueProcessId;
-  ULONG                 GrantedAccess;
-  ULONG                 DefaultHardErrorProcessing;
-  PVOID                 LdtInformation;
-  PVOID                 VadFreeHint;
-  PVOID                 VdmObjects;
-  PVOID                 DeviceObjects;
-  ULONG                 SessionId;
-  LIST_ENTRY            PhysicalVadList;
-  HARDWARE_PTE_X86      PageDirectoryPte;
-  ULONGLONG             Filler;
-  ULONG                 PaePageDirectoryPage;
-  CHAR                  ImageFileName[16];
-  ULONG                 VmTrimFaultValue;
-  UCHAR                 SetTimerResolution;
-  UCHAR                 PriorityClass;
-  UCHAR                 SubSystemMinorVersion;
-  UCHAR                 SubSystemMajorVersion;
-  USHORT                SubSystemVersion;
-  struct _W32PROCESS    *Win32Process;
-  struct _EJOB          *Job;
-  ULONG                 JobStatus;
-  LIST_ENTRY            JobLinks;
-  PVOID                 LockedPagesList;
-  struct _EPORT         *SecurityPort;
-  PWOW64_PROCESS        Wow64;
-  LARGE_INTEGER         ReadOperationCount;
-  LARGE_INTEGER         WriteOperationCount;
-  LARGE_INTEGER         OtherOperationCount;
-  LARGE_INTEGER         ReadTransferCount;
-  LARGE_INTEGER         WriteTransferCount;
-  LARGE_INTEGER         OtherTransferCount;
-  ULONG                 CommitChargeLimit;
-  ULONG                 CommitChargePeak;
-  LIST_ENTRY            ThreadListHead;
-  PRTL_BITMAP           VadPhysicalPagesBitMap;
-  ULONG                 VadPhysicalPages;
-  KSPIN_LOCK            AweLock;
-  ULONG                 Cookie;
-
-  /*
-   * FIXME - ReactOS specified - remove the following fields ASAP!!!
-   */
-  MADDRESS_SPACE        AddressSpace;
-  LIST_ENTRY            ProcessListEntry;
+    KPROCESS              Pcb;                          /* 000 */
+    EX_PUSH_LOCK          ProcessLock;                  /* 078 */
+    LARGE_INTEGER         CreateTime;                   /* 080 */
+    LARGE_INTEGER         ExitTime;                     /* 088 */    
+    EX_RUNDOWN_REF        RundownProtect;               /* 090 */
+    HANDLE                UniqueProcessId;              /* 094 */  
+    LIST_ENTRY            ActiveProcessLinks;           /* 098 */  
+    ULONG                 QuotaUsage[3];                /* 0A0 */
+    ULONG                 QuotaPeak[3];                 /* 0AC */
+    ULONG                 CommitCharge;                 /* 0B8 */  
+    ULONG                 PeakVirtualSize;              /* 0BC */  
+    ULONG                 VirtualSize;                  /* 0C0 */  
+    LIST_ENTRY            SessionProcessLinks;          /* 0C4 */
+    PVOID                 DebugPort;                    /* 0CC */
+    PVOID                 ExceptionPort;                /* 0D0 */
+    PHANDLE_TABLE         ObjectTable;                  /* 0D4 */
+    EX_FAST_REF           Token;                        /* 0D8 */
+    ULONG                 WorkingSetPage;               /* 0DC */
+    KGUARDED_MUTEX        AddressCreationLock;          /* 0E0 */
+    KSPIN_LOCK            HyperSpaceLock;               /* 100 */
+    PETHREAD              ForkInProgress;               /* 104 */
+    ULONG                 HardwareTrigger;              /* 108 */
+    MM_AVL_TABLE          PhysicalVadroot;              /* 10C */
+    PVOID                 CloneRoot;                    /* 110 */
+    ULONG                 NumberOfPrivatePages;         /* 114 */
+    ULONG                 NumberOfLockedPages;          /* 118 */
+    PVOID                 *Win32Process;                /* 11C */
+    struct _EJOB          *Job;                         /* 120 */
+    PVOID                 SectionObject;                /* 124 */
+    PVOID                 SectionBaseAddress;           /* 128 */
+    PEPROCESS_QUOTA_BLOCK QuotaBlock;                   /* 12C */
+    PPAGEFAULT_HISTORY    WorkingSetWatch;              /* 130 */
+    PVOID                 Win32WindowStation;           /* 134 */
+    HANDLE                InheritedFromUniqueProcessId; /* 138 */
+    PVOID                 LdtInformation;               /* 13C */
+    PVOID                 VadFreeHint;                  /* 140 */
+    PVOID                 VdmObjects;                   /* 144 */
+    PVOID                 DeviceMap;                    /* 148 */
+    PVOID                 Spare0[3];                    /* 14C */
+    union {
+        HARDWARE_PTE_X86  PagedirectoryPte;             /* 158 */
+        ULONGLONG         Filler;                       /* 158 */
+    };
+    ULONG                 Session;                      /* 160 */
+    UCHAR                 ImageFileName[16];            /* 164 */
+    LIST_ENTRY            JobLinks;                     /* 174 */
+    PVOID                 LockedPagesList;              /* 17C */
+    LIST_ENTRY            ThreadListHead;               /* 184 */
+    PVOID                 SecurityPort;                 /* 188 */
+    PVOID                 PaeTop;                       /* 18C */
+    ULONG                 ActiveThreds;                 /* 190 */
+    ACCESS_MASK           GrantedAccess;                /* 194 */
+    ULONG                 DefaultHardErrorProcessing;   /* 198 */
+    NTSTATUS              LastThreadExitStatus;         /* 19C */
+    PPEB                  Peb;                          /* 1A0 */
+    EX_FAST_REF           PrefetchTrace;                /* 1A4 */
+    LARGE_INTEGER         ReadOperationCount;           /* 1A8 */
+    LARGE_INTEGER         WriteOperationCount;          /* 1B0 */
+    LARGE_INTEGER         OtherOperationCount;          /* 1B8 */
+    LARGE_INTEGER         ReadTransferCount;            /* 1C0 */
+    LARGE_INTEGER         WriteTransferCount;           /* 1C8 */
+    LARGE_INTEGER         OtherTransferCount;           /* 1D0 */
+    ULONG                 CommitChargeLimit;            /* 1D8 */
+    ULONG                 CommitChargePeak;             /* 1DC */
+    PVOID                 AweInfo;                      /* 1E0 */
+    SE_AUDIT_PROCESS_CREATION_INFO SeAuditProcessCreationInfo; /* 1E4 */
+    MMSUPPORT             Vm;                           /* 1E8 */
+    LIST_ENTRY            MmProcessLinks;               /* 230 */
+    ULONG                 ModifiedPageCount;            /* 238 */
+    ULONG                 JobStatus;                    /* 23C */
+    union {
+        struct {
+            ULONG         CreateReported:1;
+            ULONG         NoDebugInherit:1;
+            ULONG         ProcessExiting:1;
+            ULONG         ProcessDelete:1;
+            ULONG         Wow64SplitPages:1;
+            ULONG         VmDeleted:1;
+            ULONG         OutswapEnabled:1;
+            ULONG         Outswapped:1;
+            ULONG         ForkFailed:1;
+            ULONG         Wow64VaSpace4Gb:1;
+            ULONG         AddressSpaceInitialized:2;
+            ULONG         SetTimerResolution:1;
+            ULONG         BreakOnTermination:1;
+            ULONG         SessionCreationUnderway:1;
+            ULONG         WriteWatch:1;
+            ULONG         ProcessInSession:1;
+            ULONG         OverrideAddressSpace:1;
+            ULONG         HasAddressSpace:1;
+            ULONG         LaunchPrefetched:1;
+            ULONG         InjectInpageErrors:1;
+            ULONG         VmTopDown:1;
+            ULONG         ImageNotifyDone:1;
+            ULONG         PdeUpdateNeeded:1;
+            ULONG         VdmAllowed:1;
+            ULONG         SmapAllowed:1;
+            ULONG         CreateFailed:1;
+            ULONG         DefaultIoPriority:3;
+            ULONG         Spare1:1;
+            ULONG         Spare2:1;
+        };
+        ULONG             Flags;                        /* 240 */
+    };
+  
+    NTSTATUS              ExitStatus;                   /* 244 */
+    USHORT                NextPageColor;                /* 248 */
+    union {
+        struct {
+            UCHAR         SubSystemMinorVersion;        /* 24A */
+            UCHAR         SubSystemMajorVersion;        /* 24B */
+        };
+        USHORT            SubSystemVersion;             /* 24A */
+    };
+    UCHAR                 PriorityClass;                /* 24C */
+    MM_AVL_TABLE          VadRoot;                      /* 250 */
+    ULONG                 Cookie;                       /* 270 */
+
+/***************************************************************
+ *                REACTOS SPECIFIC START 
+ ***************************************************************/    
+    /* FIXME WILL BE DEPRECATED WITH PUSHLOCK SUPPORT IN 0.3.0 */
+    KEVENT                LockEvent;                    /* 274 */
+    ULONG                 LockCount;                    /* 284 */
+    struct _KTHREAD       *LockOwner;                   /* 288 */
+    
+    /* FIXME MOVE TO AVL TREES                                 */
+    MADDRESS_SPACE        AddressSpace;                 /* 28C */
 };
+#include <poppack.h>
 
 #define PROCESS_STATE_TERMINATED (1)
 #define PROCESS_STATE_ACTIVE     (2)
index d4e5d27..a836631 100644 (file)
@@ -20,7 +20,6 @@
 #ifndef __NTOSKRNL_INCLUDE_INTERNAL_SE_H
 #define __NTOSKRNL_INCLUDE_INTERNAL_SE_H
 
-
 extern POBJECT_TYPE SepTokenObjectType;
 
 /* SID Authorities */
@@ -110,6 +109,8 @@ BOOLEAN SepInitSecurityIDs(VOID);
 BOOLEAN SepInitDACLs(VOID);
 BOOLEAN SepInitSDs(VOID);
 
+VOID SeDeassignPrimaryToken(struct _EPROCESS *Process);
+
 NTSTATUS STDCALL 
 SepCreateImpersonationTokenDacl(PTOKEN Token, 
                                 PTOKEN PrimaryToken,
index 5cdc17e..4e2e9ff 100644 (file)
@@ -901,7 +901,7 @@ STDCALL
 IoGetRequestorSessionId(IN PIRP Irp,
                         OUT PULONG pSessionId)
 {
-    *pSessionId = IoGetRequestorProcess(Irp)->SessionId;
+    *pSessionId = IoGetRequestorProcess(Irp)->Session;
     
     return STATUS_SUCCESS;
 }
index 1a1e470..e1ba3fb 100644 (file)
@@ -789,7 +789,7 @@ GspQuery(PCHAR Request)
     AProcess = PsActiveProcessHead.Flink;
     while(AProcess != &PsActiveProcessHead)
     {
-      Process = CONTAINING_RECORD(AProcess, EPROCESS, ProcessListEntry);
+      Process = CONTAINING_RECORD(AProcess, EPROCESS, ActiveProcessLinks);
       AThread = Process->ThreadListHead.Flink;
       if(AThread != &Process->ThreadListHead)
       {
@@ -831,10 +831,10 @@ GspQuery(PCHAR Request)
       else
       {
         PETHREAD Thread = NULL;
-        AProcess = Process->ProcessListEntry.Flink;
+        AProcess = Process->ActiveProcessLinks.Flink;
         while(AProcess != &PsActiveProcessHead)
         {
-          Process = CONTAINING_RECORD(AProcess, EPROCESS, ProcessListEntry);
+          Process = CONTAINING_RECORD(AProcess, EPROCESS, ActiveProcessLinks);
           AThread = Process->ThreadListHead.Flink;
           if(AThread != &Process->ThreadListHead)
           {
index 0d8342a..65c7c94 100644 (file)
@@ -1078,7 +1078,7 @@ KdbpCmdProc(ULONG Argc, PCHAR Argv[])
       KdbpPrint("  PID         State       Filename\n");
       do
       {
-         Process = CONTAINING_RECORD(Entry, EPROCESS, ProcessListEntry);
+         Process = CONTAINING_RECORD(Entry, EPROCESS, ActiveProcessLinks);
 
          if (Process == KdbCurrentProcess)
          {
index dfc455f..9e18216 100644 (file)
@@ -507,7 +507,7 @@ ObFindObject(POBJECT_ATTRIBUTES ObjectAttributes,
 
   if (current)
      RtlpCreateUnicodeString (RemainingPath, current, NonPagedPool);
-  ExFreePool(PathString.Buffer);
+  RtlFreeUnicodeString (&PathString);
   *ReturnedObject = CurrentObject;
 
   return STATUS_SUCCESS;
@@ -806,7 +806,7 @@ ObCreateObject (IN KPROCESSOR_MODE ObjectAttributesAccessMode OPTIONAL,
            }
          RtlFreeUnicodeString(&Header->Name);
          RtlFreeUnicodeString(&RemainingPath);
-         ExFreePoolWithTag(Header, Header->ObjectType->Tag);
+         ExFreePool(Header);
          DPRINT("Create Failed\n");
          return Status;
        }
@@ -1000,7 +1000,7 @@ ObpDeleteObject(POBJECT_HEADER Header)
     }
 
   DPRINT("ObPerformRetentionChecks() = Freeing object\n");
-  ExFreePoolWithTag(Header, Header->ObjectType->Tag);
+  ExFreePool(Header);
 
   return(STATUS_SUCCESS);
 }
@@ -1010,14 +1010,16 @@ VOID STDCALL
 ObpDeleteObjectWorkRoutine (IN PVOID Parameter)
 {
   PRETENTION_CHECK_PARAMS Params = (PRETENTION_CHECK_PARAMS)Parameter;
-  ULONG Tag;
+  /* ULONG Tag; */ /* See below */
 
   ASSERT(Params);
   ASSERT(KeGetCurrentIrql() == PASSIVE_LEVEL); /* We need PAGED_CODE somewhere... */
 
-  Tag = Params->ObjectHeader->ObjectType->Tag;
+  /* Turn this on when we have ExFreePoolWithTag
+  Tag = Params->ObjectHeader->ObjectType->Tag; */
   ObpDeleteObject(Params->ObjectHeader);
-  ExFreePoolWithTag(Params, Tag); 
+  ExFreePool(Params);
+  /* ExFreePoolWithTag(Params, Tag); */
 }
 
 
@@ -1115,7 +1117,6 @@ ObfReferenceObject(IN PVOID Object)
 
 }
 
-
 /**********************************************************************
  * NAME                                                        EXPORTED
  *     ObfDereferenceObject@4
@@ -1161,6 +1162,56 @@ ObfDereferenceObject(IN PVOID Object)
     }
 }
 
+VOID
+FASTCALL
+ObInitializeFastReference(IN PEX_FAST_REF FastRef, 
+                          PVOID Object)
+{
+    /* FIXME: Fast Referencing is Unimplemented */
+    FastRef->Object = Object;
+}
+
+
+PVOID
+FASTCALL
+ObFastReferenceObject(IN PEX_FAST_REF FastRef)
+{
+    /* FIXME: Fast Referencing is Unimplemented */
+    
+    /* Do a normal Reference */
+    ObReferenceObject(FastRef->Object);
+    
+    /* Return the Object */
+    return FastRef->Object;
+}
+
+VOID
+FASTCALL
+ObFastDereferenceObject(IN PEX_FAST_REF FastRef,
+                        PVOID Object)
+{
+    /* FIXME: Fast Referencing is Unimplemented */
+    
+    /* Do a normal Dereference */
+    ObDereferenceObject(FastRef->Object);
+}
+
+PVOID
+FASTCALL
+ObFastReplaceObject(IN PEX_FAST_REF FastRef,
+                    PVOID Object)
+{
+    PVOID OldObject = FastRef->Object;
+    
+    /* FIXME: Fast Referencing is Unimplemented */
+    FastRef->Object = Object;
+    
+    /* Do a normal Dereference */
+    ObDereferenceObject(OldObject);
+
+    /* Return old Object*/
+    return OldObject;
+}
 
 /**********************************************************************
  * NAME                                                        EXPORTED
index b4c0cb1..35a6db6 100644 (file)
@@ -280,9 +280,8 @@ PspDumpThreads(BOOLEAN IncludeSystem)
     CurrentProcess = PsActiveProcessHead.Flink;
     while(CurrentProcess != &PsActiveProcessHead)
     {
-    
         /* Get the process */
-        Process = CONTAINING_RECORD(CurrentProcess, EPROCESS, ProcessListEntry);
+        Process = CONTAINING_RECORD(CurrentProcess, EPROCESS, ActiveProcessLinks);
         
         /* Skip the Initial Process if requested */
         if((Process != PsInitialSystemProcess) ||
index b28740c..7115be5 100644 (file)
@@ -160,7 +160,7 @@ NtAssignProcessToJobObject (
                 Status = PsLockProcess(Process, FALSE);
                 if(NT_SUCCESS(Status))
                 {
-                    if(Process->Job == NULL && Process->SessionId == Job->SessionId)
+                    if(Process->Job == NULL && Process->Session == Job->SessionId)
                     {
                         /* Just store the pointer to the job object in the process, we'll
                         assign it later. The reason we can't do this here is that locking
@@ -263,7 +263,7 @@ NtCreateJobObject (
 
         /* setup the job object */
         InitializeListHead(&Job->ProcessListHead);
-        Job->SessionId = CurrentProcess->SessionId; /* inherit the session id from the caller */
+        Job->SessionId = CurrentProcess->Session; /* inherit the session id from the caller */
 
         Status = ExInitializeResource(&Job->JobLock);
         if(!NT_SUCCESS(Status))
index 171374b..8e04756 100644 (file)
@@ -93,7 +93,7 @@ PspKillMostProcesses(VOID)
     current_entry = PsActiveProcessHead.Flink;
     while (current_entry != &PsActiveProcessHead)
     {
-        current = CONTAINING_RECORD(current_entry, EPROCESS, ProcessListEntry);
+        current = CONTAINING_RECORD(current_entry, EPROCESS, ActiveProcessLinks);
         current_entry = current_entry->Flink;
     
         if (current->UniqueProcessId != PsInitialSystemProcess->UniqueProcessId &&
@@ -150,7 +150,7 @@ PspDeleteProcess(PVOID ObjectBody)
 
     /* Remove it from the Active List */
     ExAcquireFastMutex(&PspActiveProcessMutex);
-    RemoveEntryList(&Process->ProcessListEntry);
+    RemoveEntryList(&Process->ActiveProcessLinks);
     ExReleaseFastMutex(&PspActiveProcessMutex);
     
     /* Delete the CID Handle */   
@@ -162,8 +162,10 @@ PspDeleteProcess(PVOID ObjectBody)
     /* KDB hook */
     KDB_DELETEPROCESS_HOOK(Process);
     
-    /* Dereference the Token and release Memory Information */
-    ObDereferenceObject(Process->Token);
+    /* Dereference the Token */
+    SeDeassignPrimaryToken(Process);
+    
+    /* Release Memory Information */
     MmReleaseMmInfo(Process);
  
     /* Delete the W32PROCESS structure if there's one associated */
index 1999b56..cc65454 100644 (file)
@@ -135,12 +135,12 @@ PsGetNextProcess(PEPROCESS OldProcess)
     {
         /* Get the Process Link */
         PLIST_ENTRY Flink = (NextProcess == PsIdleProcess ? PsActiveProcessHead.Flink :
-                             NextProcess->ProcessListEntry.Flink);
+                             NextProcess->ActiveProcessLinks.Flink);
         
         /* Move to the next Process if we're not back at the beginning */
         if (Flink != &PsActiveProcessHead)
         {
-            NextProcess = CONTAINING_RECORD(Flink, EPROCESS, ProcessListEntry);
+            NextProcess = CONTAINING_RECORD(Flink, EPROCESS, ActiveProcessLinks);
         }
         else
         {
@@ -292,7 +292,7 @@ PspCreateProcess(OUT PHANDLE ProcessHandle,
     if (pParentProcess) 
     {
         Process->InheritedFromUniqueProcessId = pParentProcess->UniqueProcessId;
-        Process->SessionId = pParentProcess->SessionId;
+        Process->Session = pParentProcess->Session;
     }
     
     /* FIXME: Set up the Quota Block from the Parent
@@ -393,7 +393,7 @@ PspCreateProcess(OUT PHANDLE ProcessHandle,
     /* W00T! The process can now be activated */
     DPRINT("Inserting into Active Process List\n");
     ExAcquireFastMutex(&PspActiveProcessMutex);
-    InsertTailList(&PsActiveProcessHead, &Process->ProcessListEntry);
+    InsertTailList(&PsActiveProcessHead, &Process->ActiveProcessLinks);
     ExReleaseFastMutex(&PspActiveProcessMutex);
     
     /* FIXME: SeCreateAccessStateEx */
@@ -547,7 +547,7 @@ BOOLEAN
 STDCALL
 PsGetProcessExitProcessCalled(PEPROCESS Process)
 {
-    return Process->ExitProcessCalled; 
+    return Process->ProcessExiting;
 }
 
 /*
@@ -636,7 +636,7 @@ ULONG
 STDCALL
 PsGetCurrentProcessSessionId(VOID)
 {
-    return PsGetCurrentProcess()->SessionId;
+    return PsGetCurrentProcess()->Session;
 }
 
 /*
@@ -666,7 +666,7 @@ HANDLE
 STDCALL
 PsGetProcessSessionId(PEPROCESS Process)
 {
-    return (HANDLE)Process->SessionId;
+    return (HANDLE)Process->Session;
 }
 
 /*
index f6bbff6..d60224f 100644 (file)
@@ -186,7 +186,7 @@ PsInitProcessManagment(VOID)
    PsIdleProcess->Pcb.QuantumReset = 6;
    InitializeListHead(&PsIdleProcess->Pcb.ThreadListHead);
    InitializeListHead(&PsIdleProcess->ThreadListHead);
-   InitializeListHead(&PsIdleProcess->ProcessListEntry);
+   InitializeListHead(&PsIdleProcess->ActiveProcessLinks);
    KeInitializeDispatcherHeader(&PsIdleProcess->Pcb.Header,
                                ProcessObject,
                                sizeof(EPROCESS),
@@ -248,7 +248,7 @@ PsInitProcessManagment(VOID)
    PsInitialSystemProcess->Win32WindowStation = (HANDLE)0;
    
    InsertHeadList(&PsActiveProcessHead,
-                 &PsInitialSystemProcess->ProcessListEntry);
+                 &PsInitialSystemProcess->ActiveProcessLinks);
    InitializeListHead(&PsInitialSystemProcess->ThreadListHead);
    
 #ifndef SCHED_REWRITE
@@ -257,7 +257,7 @@ PsInitProcessManagment(VOID)
     /* No parent, this is the Initial System Process. Assign Boot Token */
     BootToken = SepCreateSystemProcessToken();
     BootToken->TokenInUse = TRUE;
-    PsInitialSystemProcess->Token = BootToken;
+    PsInitialSystemProcess->Token.Object = BootToken; /* FIXME */
     ObReferenceObject(BootToken);
 #endif
 }
index 3e6034c..48d5321 100644 (file)
@@ -287,7 +287,7 @@ NtQueryInformationProcess(IN  HANDLE ProcessHandle,
 
         _SEH_TRY
         {
-          SessionInfo->SessionId = Process->SessionId;
+          SessionInfo->SessionId = Process->Session;
           if (ReturnLength)
           {
             *ReturnLength = sizeof(PROCESS_SESSION_INFORMATION);
@@ -318,16 +318,16 @@ NtQueryInformationProcess(IN  HANDLE ProcessHandle,
           * incompatibilities in current headers (no unnamed union),
           * I opted for cast.
           */
-         pOut->VirtualSize                = (ULONG)Process->VirtualSize.QuadPart;
+         pOut->VirtualSize                = (ULONG)Process->VirtualSize;
          pOut->PageFaultCount             = Process->Vm.PageFaultCount;
          pOut->PeakWorkingSetSize         = Process->Vm.PeakWorkingSetSize;
          pOut->WorkingSetSize             = Process->Vm.WorkingSetSize;
-         pOut->QuotaPeakPagedPoolUsage    = Process->QuotaPeakPoolUsage[0]; // TODO: Verify!
-         pOut->QuotaPagedPoolUsage        = Process->QuotaPoolUsage[0];     // TODO: Verify!
-         pOut->QuotaPeakNonPagedPoolUsage = Process->QuotaPeakPoolUsage[1]; // TODO: Verify!
-         pOut->QuotaNonPagedPoolUsage     = Process->QuotaPoolUsage[1];     // TODO: Verify!
-         pOut->PagefileUsage              = Process->PagefileUsage;
-         pOut->PeakPagefileUsage          = Process->PeakPagefileUsage;
+         pOut->QuotaPeakPagedPoolUsage    = Process->QuotaPeak[0]; // TODO: Verify!
+         pOut->QuotaPagedPoolUsage        = Process->QuotaUsage[0];     // TODO: Verify!
+         pOut->QuotaPeakNonPagedPoolUsage = Process->QuotaPeak[1]; // TODO: Verify!
+         pOut->QuotaNonPagedPoolUsage     = Process->QuotaUsage[1];     // TODO: Verify!
+         pOut->PagefileUsage              = Process->QuotaUsage[2];
+         pOut->PeakPagefileUsage          = Process->QuotaPeak[2];
 
          if (ReturnLength)
          {
@@ -841,7 +841,7 @@ NtSetInformationProcess(IN HANDLE ProcessHandle,
           Status = PsLockProcess(Process, FALSE);
           if(NT_SUCCESS(Status))
           {
-            Process->SessionId = SessionInfo.SessionId;
+            Process->Session = SessionInfo.SessionId;
 
             /* Update the session id in the PEB structure */
             if(Process->Peb != NULL)
index 6daa00f..a3dcae3 100644 (file)
 #define NDEBUG
 #include <internal/debug.h>
 
+/* INTERNAL ******************************************************************/
+
+/* FIXME: Turn into Macro */
+VOID
+STDCALL
+PspLockProcessSecurityShared(PEPROCESS Process)
+{
+    /* Enter a Guarded Region */
+    KeEnterGuardedRegion();
+        
+    /* Lock the Process */
+    //ExAcquirePushLockShared(&Process->ProcessLock);    
+}
+
+/* FIXME: Turn into Macro */
+VOID
+STDCALL
+PspUnlockProcessSecurityShared(PEPROCESS Process)
+{
+    /* Unlock the Process */
+    //ExReleasePushLockShared(&Process->ProcessLock);
+        
+    /* Leave Guarded Region */
+    KeLeaveGuardedRegion();
+}
+
 /* FUNCTIONS *****************************************************************/
 
 /*
@@ -104,12 +130,26 @@ PACCESS_TOKEN
 STDCALL
 PsReferencePrimaryToken(PEPROCESS Process)
 {
-    /* Reference and return the Token */
-    ObReferenceObjectByPointer(Process->Token,
-                               TOKEN_ALL_ACCESS,
-                               SepTokenObjectType,
-                               KernelMode);
-    return(Process->Token);
+    PACCESS_TOKEN Token;
+    
+    /* Fast Reference the Token */
+    Token = ObFastReferenceObject(&Process->Token);
+    
+    /* Check if we got the Token or if we got locked */
+    if (!Token)
+    {
+        /* Lock the Process */
+        PspLockProcessSecurityShared(Process);
+        
+        /* Do a Locked Fast Reference */
+        //Token = ObFastReferenceObjectLocked(&Process->Token);
+        
+        /* Unlock the Process */
+        PspUnlockProcessSecurityShared(Process);
+    }
+    
+    /* Return the Token */
+    return Token;
 }
 
 /*
@@ -156,7 +196,8 @@ PspInitializeProcessSecurity(PEPROCESS Process,
         PTOKEN pParentToken;
         OBJECT_ATTRIBUTES ObjectAttributes;
 
-        pParentToken = (PACCESS_TOKEN)Parent->Token;
+        /* Get the Parent Token */
+        pParentToken = PsReferencePrimaryToken(Parent);
 
         /* Initialize the Object Attributes */
         InitializeObjectAttributes(&ObjectAttributes,
@@ -180,7 +221,11 @@ PspInitializeProcessSecurity(PEPROCESS Process,
             return Status;
         }
      
-        Process->Token = pNewToken;    
+        /* Dereference the Token */
+        ObFastDereferenceObject(&Parent->Token, pParentToken);
+        
+        /* Set the new Token */
+        ObInitializeFastReference(&Process->Token, pNewToken);
     
     } else {
         
@@ -227,7 +272,6 @@ PspAssignPrimaryToken(PEPROCESS Process,
     Status = SeExchangePrimaryToken(Process, Token, &OldToken);
         
     /* Derefernece Tokens and Return */
-    if (NT_SUCCESS(Status)) ObDereferenceObject(OldToken);
     ObDereferenceObject(Token);
     return(Status);
 }
@@ -356,22 +400,37 @@ PsReferenceEffectiveToken(PETHREAD Thread,
     PEPROCESS Process;
     PACCESS_TOKEN Token;
    
-    if (Thread->ActiveImpersonationInfo == FALSE) {
-        
+    if (Thread->ActiveImpersonationInfo == FALSE) 
+    {    
         Process = Thread->ThreadsProcess;
         *TokenType = TokenPrimary;
         *EffectiveOnly = FALSE;
-        Token = Process->Token;
     
-    } else {
-
+        /* Fast Reference the Token */
+        Token = ObFastReferenceObject(&Process->Token);
+    
+        /* Check if we got the Token or if we got locked */
+        if (!Token)
+        {
+            /* Lock the Process */
+            PspLockProcessSecurityShared(Process);
+        
+            /* Do a Locked Fast Reference */
+            //Token = ObFastReferenceObjectLocked(&Process->Token);
+        
+            /* Unlock the Process */
+            PspUnlockProcessSecurityShared(Process);
+        }   
+    } 
+    else 
+    {
         Token = Thread->ImpersonationInfo->Token;
         *TokenType = TokenImpersonation;
         *EffectiveOnly = Thread->ImpersonationInfo->EffectiveOnly;
         *Level = Thread->ImpersonationInfo->ImpersonationLevel;
     }
     
-    return(Token);
+    return Token;
 }
 
 NTSTATUS 
index fe57eb0..a12c093 100644 (file)
@@ -423,7 +423,7 @@ HANDLE
 STDCALL
 PsGetThreadSessionId(PETHREAD Thread)
 {
-    return (HANDLE)Thread->ThreadsProcess->SessionId;
+    return (HANDLE)Thread->ThreadsProcess->Session;
 }
 
 /*
index 29b3192..2a0a557 100644 (file)
@@ -54,7 +54,7 @@ PsGetWin32Thread(VOID)
 PW32PROCESS STDCALL
 PsGetWin32Process(VOID)
 {
-  return(PsGetCurrentProcess()->Win32Process);
+  return (PW32PROCESS)PsGetCurrentProcess()->Win32Process;
 }
 
 NTSTATUS STDCALL
index ab4f269..67da059 100644 (file)
@@ -79,33 +79,45 @@ NTSTATUS SepCopyProxyData(PVOID* Dest, PVOID Src)
    return(STATUS_NOT_IMPLEMENTED);
 }
 
-NTSTATUS SeExchangePrimaryToken(PEPROCESS Process,
-                               PACCESS_TOKEN NewTokenP,
-                               PACCESS_TOKEN* OldTokenP)
+NTSTATUS 
+SeExchangePrimaryToken(PEPROCESS Process,
+                       PACCESS_TOKEN NewTokenP,
+                       PACCESS_TOKEN* OldTokenP)
 {
-   PTOKEN OldToken;
-   PTOKEN NewToken = (PTOKEN)NewTokenP;
+    PTOKEN OldToken;
+    PTOKEN NewToken = (PTOKEN)NewTokenP;
    
-   PAGED_CODE();
+    PAGED_CODE();
    
-   if (NewToken->TokenType != TokenPrimary)
-     {
-       return(STATUS_UNSUCCESSFUL);
-     }
-   if (NewToken->TokenInUse != 0)
-     {
-       return(STATUS_UNSUCCESSFUL);
-     }
-   OldToken = Process->Token;
-   Process->Token = NewToken;
-   NewToken->TokenInUse = 1;
-   ObReferenceObjectByPointer(NewToken,
-                             TOKEN_ALL_ACCESS,
-                             SepTokenObjectType,
-                             KernelMode);
-   OldToken->TokenInUse = 0;
-   *OldTokenP = (PACCESS_TOKEN)OldToken;
-   return(STATUS_SUCCESS);
+    if (NewToken->TokenType != TokenPrimary) return(STATUS_BAD_TOKEN_TYPE);
+    if (NewToken->TokenInUse) return(STATUS_TOKEN_ALREADY_IN_USE);
+   
+    /* Mark new token in use */
+    NewToken->TokenInUse = 1;
+    
+    /* Reference the New Token */
+    ObReferenceObject(NewToken);
+    
+    /* Replace the old with the new */
+    OldToken = ObFastReplaceObject(&Process->Token, NewToken);
+    
+    /* Mark the Old Token as free */
+    OldToken->TokenInUse = 0;
+    
+    *OldTokenP = (PACCESS_TOKEN)OldToken;
+    return STATUS_SUCCESS;
+}
+
+VOID
+SeDeassignPrimaryToken(PEPROCESS Process)
+{
+    PTOKEN OldToken;
+    
+    /* Remove the Token */
+    OldToken = ObFastReplaceObject(&Process->Token, NULL);
+    
+    /* Mark the Old Token as free */
+    OldToken->TokenInUse = 0;
 }
 
 static ULONG
index 08e8806..5a85c39 100644 (file)
@@ -929,12 +929,17 @@ typedef struct _FAST_MUTEX {
   ULONG  OldIrql;
 } FAST_MUTEX, *PFAST_MUTEX;
 
+typedef struct _KGATE
+{
+    DISPATCHER_HEADER Header;
+} KGATE, *PKGATE, *RESTRICTED_POINTER PRKGATE;
+
 typedef struct _KGUARDED_MUTEX
 {
     LONG Count;
     struct _KTHREAD* Owner;
     ULONG Contention;
-    struct _KGATE* Gate;
+    KGATE Gate;
     union {
         struct {
             SHORT KernelApcDisable;
@@ -960,11 +965,6 @@ typedef struct _KMUTANT {
   UCHAR  ApcDisable;
 } KMUTANT, *PKMUTANT, *RESTRICTED_POINTER PRKMUTANT, KMUTEX, *PKMUTEX, *RESTRICTED_POINTER PRKMUTEX;
 
-typedef struct _KGATE
-{
-  DISPATCHER_HEADER Header;
-} KGATE, *PKGATE, *RESTRICTED_POINTER PRKGATE;
-
 typedef enum _TIMER_TYPE {
   NotificationTimer,
   SynchronizationTimer