Fix Process/Thread information structures to match Windows 2000 and have proper structure. Fix bug in ntdll related to OpenProcess

svn path=/trunk/; revision=14675
This commit is contained in:
Alex Ionescu 2005-04-18 17:48:01 +00:00
parent 5817ae7a54
commit 6e2aa454ad
3 changed files with 45 additions and 42 deletions

View file

@ -562,12 +562,12 @@ QSI_DEF(SystemProcessInformation)
/* scan the process list */ /* scan the process list */
PSYSTEM_PROCESSES Spi PSYSTEM_PROCESS_INFORMATION Spi
= (PSYSTEM_PROCESSES) Buffer; = (PSYSTEM_PROCESS_INFORMATION) Buffer;
*ReqSize = sizeof(SYSTEM_PROCESSES); *ReqSize = sizeof(SYSTEM_PROCESS_INFORMATION);
if (Size < sizeof(SYSTEM_PROCESSES)) if (Size < sizeof(SYSTEM_PROCESS_INFORMATION))
{ {
return (STATUS_INFO_LENGTH_MISMATCH); // in case buffer size is too small return (STATUS_INFO_LENGTH_MISMATCH); // in case buffer size is too small
} }
@ -578,14 +578,14 @@ QSI_DEF(SystemProcessInformation)
do do
{ {
PSYSTEM_PROCESSES SpiCur; PSYSTEM_PROCESS_INFORMATION SpiCur;
int curSize, i = 0; int curSize, i = 0;
ANSI_STRING imgName; ANSI_STRING imgName;
int inLen=32; // image name len in bytes int inLen=32; // image name len in bytes
PLIST_ENTRY current_entry; PLIST_ENTRY current_entry;
PETHREAD current; PETHREAD current;
SpiCur = (PSYSTEM_PROCESSES)pCur; SpiCur = (PSYSTEM_PROCESS_INFORMATION)pCur;
current_entry = pr->ThreadListHead.Flink; current_entry = pr->ThreadListHead.Flink;
while (current_entry != &pr->ThreadListHead) while (current_entry != &pr->ThreadListHead)
@ -595,7 +595,7 @@ QSI_DEF(SystemProcessInformation)
} }
// size of the structure for every process // size of the structure for every process
curSize = sizeof(SYSTEM_PROCESSES)-sizeof(SYSTEM_THREADS)+sizeof(SYSTEM_THREADS)*nThreads; curSize = sizeof(SYSTEM_PROCESS_INFORMATION)-sizeof(SYSTEM_THREAD_INFORMATION)+sizeof(SYSTEM_THREAD_INFORMATION)*nThreads;
ovlSize += curSize+inLen; ovlSize += curSize+inLen;
if (ovlSize > Size) if (ovlSize > Size)
@ -607,45 +607,45 @@ QSI_DEF(SystemProcessInformation)
} }
// fill system information // fill system information
SpiCur->NextEntryDelta = curSize+inLen; // relative offset to the beginnnig of the next structure SpiCur->NextEntryOffset = curSize+inLen; // relative offset to the beginnnig of the next structure
SpiCur->ThreadCount = nThreads; SpiCur->NumberOfThreads = nThreads;
SpiCur->CreateTime = pr->CreateTime; SpiCur->CreateTime = pr->CreateTime;
SpiCur->UserTime.QuadPart = pr->Pcb.UserTime * 100000LL; SpiCur->UserTime.QuadPart = pr->Pcb.UserTime * 100000LL;
SpiCur->KernelTime.QuadPart = pr->Pcb.KernelTime * 100000LL; SpiCur->KernelTime.QuadPart = pr->Pcb.KernelTime * 100000LL;
SpiCur->ProcessName.Length = strlen(pr->ImageFileName) * sizeof(WCHAR); SpiCur->ImageName.Length = strlen(pr->ImageFileName) * sizeof(WCHAR);
SpiCur->ProcessName.MaximumLength = inLen; SpiCur->ImageName.MaximumLength = inLen;
SpiCur->ProcessName.Buffer = (void*)(pCur+curSize); SpiCur->ImageName.Buffer = (void*)(pCur+curSize);
// copy name to the end of the struct // copy name to the end of the struct
if(pr != PsIdleProcess) if(pr != PsIdleProcess)
{ {
RtlInitAnsiString(&imgName, pr->ImageFileName); RtlInitAnsiString(&imgName, pr->ImageFileName);
RtlAnsiStringToUnicodeString(&SpiCur->ProcessName, &imgName, FALSE); RtlAnsiStringToUnicodeString(&SpiCur->ImageName, &imgName, FALSE);
} }
else else
{ {
RtlInitUnicodeString(&SpiCur->ProcessName, NULL); RtlInitUnicodeString(&SpiCur->ImageName, NULL);
} }
SpiCur->BasePriority = pr->Pcb.BasePriority; SpiCur->BasePriority = pr->Pcb.BasePriority;
SpiCur->ProcessId = pr->UniqueProcessId; SpiCur->UniqueProcessId = pr->UniqueProcessId;
SpiCur->InheritedFromProcessId = pr->InheritedFromUniqueProcessId; SpiCur->InheritedFromUniqueProcessId = pr->InheritedFromUniqueProcessId;
SpiCur->HandleCount = (pr->ObjectTable ? ObpGetHandleCountByHandleTable(pr->ObjectTable) : 0); SpiCur->HandleCount = (pr->ObjectTable ? ObpGetHandleCountByHandleTable(pr->ObjectTable) : 0);
SpiCur->VmCounters.PeakVirtualSize = pr->PeakVirtualSize; SpiCur->PeakVirtualSize = pr->PeakVirtualSize;
SpiCur->VmCounters.VirtualSize = pr->VirtualSize.QuadPart; SpiCur->VirtualSize = pr->VirtualSize.QuadPart;
SpiCur->VmCounters.PageFaultCount = pr->LastFaultCount; SpiCur->PageFaultCount = pr->LastFaultCount;
SpiCur->VmCounters.PeakWorkingSetSize = pr->Vm.PeakWorkingSetSize; // Is this right using ->Vm. here ? SpiCur->PeakWorkingSetSize = pr->Vm.PeakWorkingSetSize; // Is this right using ->Vm. here ?
SpiCur->VmCounters.WorkingSetSize = pr->Vm.WorkingSetSize; // Is this right using ->Vm. here ? SpiCur->WorkingSetSize = pr->Vm.WorkingSetSize; // Is this right using ->Vm. here ?
SpiCur->VmCounters.QuotaPeakPagedPoolUsage = SpiCur->QuotaPeakPagedPoolUsage =
pr->QuotaPeakPoolUsage[0]; pr->QuotaPeakPoolUsage[0];
SpiCur->VmCounters.QuotaPagedPoolUsage = SpiCur->QuotaPagedPoolUsage =
pr->QuotaPoolUsage[0]; pr->QuotaPoolUsage[0];
SpiCur->VmCounters.QuotaPeakNonPagedPoolUsage = SpiCur->QuotaPeakNonPagedPoolUsage =
pr->QuotaPeakPoolUsage[1]; pr->QuotaPeakPoolUsage[1];
SpiCur->VmCounters.QuotaNonPagedPoolUsage = SpiCur->QuotaNonPagedPoolUsage =
pr->QuotaPoolUsage[1]; pr->QuotaPoolUsage[1];
SpiCur->VmCounters.PagefileUsage = pr->PagefileUsage; // FIXME SpiCur->PagefileUsage = pr->PagefileUsage; // FIXME
SpiCur->VmCounters.PeakPagefileUsage = pr->PeakPagefileUsage; SpiCur->PeakPagefileUsage = pr->PeakPagefileUsage;
// KJK::Hyperion: I don't know what does this mean. VM_COUNTERS // KJK::Hyperion: I don't know what does this mean. VM_COUNTERS
// doesn't seem to contain any equivalent field // doesn't seem to contain any equivalent field
//SpiCur->TotalPrivateBytes = pr->NumberOfPrivatePages; //FIXME: bytes != pages //SpiCur->TotalPrivateBytes = pr->NumberOfPrivatePages; //FIXME: bytes != pages
@ -656,17 +656,17 @@ QSI_DEF(SystemProcessInformation)
current = CONTAINING_RECORD(current_entry, ETHREAD, current = CONTAINING_RECORD(current_entry, ETHREAD,
ThreadListEntry); ThreadListEntry);
SpiCur->Threads[i].KernelTime.QuadPart = current->Tcb.KernelTime * 100000LL; SpiCur->TH[i].KernelTime.QuadPart = current->Tcb.KernelTime * 100000LL;
SpiCur->Threads[i].UserTime.QuadPart = current->Tcb.UserTime * 100000LL; SpiCur->TH[i].UserTime.QuadPart = current->Tcb.UserTime * 100000LL;
// SpiCur->Threads[i].CreateTime = current->CreateTime; // SpiCur->TH[i].CreateTime = current->CreateTime;
SpiCur->Threads[i].WaitTime = current->Tcb.WaitTime; SpiCur->TH[i].WaitTime = current->Tcb.WaitTime;
SpiCur->Threads[i].StartAddress = (PVOID) current->StartAddress; SpiCur->TH[i].StartAddress = (PVOID) current->StartAddress;
SpiCur->Threads[i].ClientId = current->Cid; SpiCur->TH[i].ClientId = current->Cid;
SpiCur->Threads[i].Priority = current->Tcb.Priority; SpiCur->TH[i].Priority = current->Tcb.Priority;
SpiCur->Threads[i].BasePriority = current->Tcb.BasePriority; SpiCur->TH[i].BasePriority = current->Tcb.BasePriority;
SpiCur->Threads[i].ContextSwitchCount = current->Tcb.ContextSwitches; SpiCur->TH[i].ContextSwitches = current->Tcb.ContextSwitches;
SpiCur->Threads[i].State = current->Tcb.State; SpiCur->TH[i].ThreadState = current->Tcb.State;
SpiCur->Threads[i].WaitReason = current->Tcb.WaitReason; SpiCur->TH[i].WaitReason = current->Tcb.WaitReason;
i++; i++;
current_entry = current_entry->Flink; current_entry = current_entry->Flink;
} }
@ -675,7 +675,7 @@ QSI_DEF(SystemProcessInformation)
nThreads = 0; nThreads = 0;
if ((pr == syspr) || (pr == NULL)) if ((pr == syspr) || (pr == NULL))
{ {
SpiCur->NextEntryDelta = 0; SpiCur->NextEntryOffset = 0;
break; break;
} }
else else

View file

@ -49,6 +49,7 @@ struct _KEXCEPTION_FRAME;
#define IPI_REQUEST_DPC 2 #define IPI_REQUEST_DPC 2
#define IPI_REQUEST_FREEZE 3 #define IPI_REQUEST_FREEZE 3
#ifndef __USE_W32API
typedef enum _KTHREAD_STATE { typedef enum _KTHREAD_STATE {
Initialized, Initialized,
Ready, Ready,
@ -59,6 +60,7 @@ typedef enum _KTHREAD_STATE {
Transition, Transition,
DeferredReady, DeferredReady,
} THREAD_STATE, *PTHREAD_STATE; } THREAD_STATE, *PTHREAD_STATE;
#endif
/* MACROS *************************************************************************/ /* MACROS *************************************************************************/

View file

@ -363,7 +363,7 @@ PspCreateProcess(OUT PHANDLE ProcessHandle,
Status = PsCreateCidHandle(Process, Status = PsCreateCidHandle(Process,
PsProcessType, PsProcessType,
&Process->UniqueProcessId); &Process->UniqueProcessId);
DPRINT1("Created CID: %d\n", Process->UniqueProcessId); DPRINT("Created CID: %d\n", Process->UniqueProcessId);
if(!NT_SUCCESS(Status)) if(!NT_SUCCESS(Status))
{ {
DPRINT1("Failed to create CID handle (unique process ID)! Status: 0x%x\n", Status); DPRINT1("Failed to create CID handle (unique process ID)! Status: 0x%x\n", Status);
@ -873,7 +873,8 @@ NtOpenProcess(OUT PHANDLE ProcessHandle,
if (ClientId->UniqueThread) if (ClientId->UniqueThread)
{ {
/* Get the Process */ /* Get the Process */
DPRINT1("Opening by Thread ID: %x\n", ClientId->UniqueThread); if (ClientId->UniqueThread == (HANDLE)-1) KEBUGCHECK(0);
DPRINT("Opening by Thread ID: %x\n", ClientId->UniqueThread);
Status = PsLookupProcessThreadByCid(ClientId, Status = PsLookupProcessThreadByCid(ClientId,
&Process, &Process,
&Thread); &Thread);
@ -882,7 +883,7 @@ NtOpenProcess(OUT PHANDLE ProcessHandle,
else else
{ {
/* Get the Process */ /* Get the Process */
DPRINT1("Opening by Process ID: %x\n", ClientId->UniqueProcess); DPRINT("Opening by Process ID: %x\n", ClientId->UniqueProcess);
Status = PsLookupProcessByProcessId(ClientId->UniqueProcess, Status = PsLookupProcessByProcessId(ClientId->UniqueProcess,
&Process); &Process);
DPRINT("Found: %x\n", Process); DPRINT("Found: %x\n", Process);