diff --git a/reactos/include/ddk/pstypes.h b/reactos/include/ddk/pstypes.h index e8f8e816336..93164312c9c 100644 --- a/reactos/include/ddk/pstypes.h +++ b/reactos/include/ddk/pstypes.h @@ -268,6 +268,9 @@ typedef struct _KPROCESS typedef struct _EPROCESS { KPROCESS Pcb; + + ULONG UniqueProcessId; + ULONG InheritedFromUniqueProcessId; } EPROCESS, *PEPROCESS; #define PROCESS_STATE_TERMINATED (1) diff --git a/reactos/lib/kernel32/kernel32.def b/reactos/lib/kernel32/kernel32.def index a10502783fb..ee884ed1e9f 100644 --- a/reactos/lib/kernel32/kernel32.def +++ b/reactos/lib/kernel32/kernel32.def @@ -282,7 +282,8 @@ GetCurrentDirectoryW@8 GetCurrentDirectoryW = GetCurrentDirectoryW@8 GetCurrentProcess@0 GetCurrentProcess = GetCurrentProcess@0 -;GetCurrentProcessId@0 +GetCurrentProcessId@0 +GetCurrentProcessId = GetCurrentProcessId@0 GetCurrentThread@0 GetCurrentThread = GetCurrentThread@0 GetCurrentThreadId@0 diff --git a/reactos/ntoskrnl/ps/process.c b/reactos/ntoskrnl/ps/process.c index 0a303336ef4..fd4def4144c 100644 --- a/reactos/ntoskrnl/ps/process.c +++ b/reactos/ntoskrnl/ps/process.c @@ -29,6 +29,8 @@ HANDLE SystemProcessHandle = NULL; POBJECT_TYPE PsProcessType = NULL; +static ULONG NextUniqueProcessId = 0; + /* FUNCTIONS *****************************************************************/ VOID PsInitProcessManagment(VOID) @@ -78,6 +80,9 @@ VOID PsInitProcessManagment(VOID) InitializeListHead(&(KProcess->MemoryAreaList)); ObCreateHandleTable(NULL,FALSE,SystemProcess); KProcess->PageTableDirectory = get_page_directory(); + + SystemProcess->UniqueProcessId = NextUniqueProcessId; + SystemProcess->InheritedFromUniqueProcessId = NextUniqueProcessId; ObCreateHandle(SystemProcess, SystemProcess, @@ -192,6 +197,8 @@ NTSTATUS STDCALL ZwCreateProcess( KProcess = &(Process->Pcb); InitializeListHead(&(KProcess->MemoryAreaList)); + Process->UniqueProcessId = InterlockedIncrement(&NextUniqueProcessId); + Process->InheritedFromUniqueProcessId = ParentProcess->UniqueProcessId; ObCreateHandleTable(ParentProcess, InheritObjectTable, Process); @@ -273,6 +280,10 @@ NTSTATUS STDCALL ZwQueryInformationProcess(IN HANDLE ProcessHandle, ProcessInformation; memset(ProcessBasicInformationP, 0, sizeof(PROCESS_BASIC_INFORMATION)); ProcessBasicInformationP->AffinityMask = Process->Pcb.Affinity; + ProcessBasicInformationP->UniqueProcessId = + Process->UniqueProcessId; + ProcessBasicInformationP->InheritedFromUniqueProcessId = + Process->InheritedFromUniqueProcessId; Status = STATUS_SUCCESS; break; diff --git a/reactos/ntoskrnl/ps/thread.c b/reactos/ntoskrnl/ps/thread.c index fb4d452120b..285c7f23087 100644 --- a/reactos/ntoskrnl/ps/thread.c +++ b/reactos/ntoskrnl/ps/thread.c @@ -52,8 +52,7 @@ ULONG PiNrRunnableThreads = 0; static PETHREAD CurrentThread = NULL; -static ULONG NextThreadUniqueId = 0; -//static ULONG NextProcessUniqueId = 0; +static ULONG NextUniqueThreadId = 0; /* FUNCTIONS ***************************************************************/ @@ -257,8 +256,10 @@ NTSTATUS PsInitializeThread(HANDLE ProcessHandle, InitializeListHead(Thread->Tcb.ApcList); InitializeListHead(&(Thread->IrpList)); Thread->Cid.UniqueThread = (HANDLE)InterlockedIncrement( - &NextThreadUniqueId); - DbgPrint("Thread->Cid.UniqueThread %d\n",Thread->Cid.UniqueThread); + &NextUniqueThreadId); + Thread->Cid.UniqueProcess = (HANDLE)Thread->ThreadsProcess->UniqueProcessId; + DbgPrint("Thread->Cid.UniqueThread %d\nThread->Cid.UniqueProcess %d\n", + Thread->Cid.UniqueThread, Thread->Cid.UniqueThread); ObReferenceObjectByPointer(Thread, THREAD_ALL_ACCESS, PsThreadType,