Implement system and idle process creation and initialization functions
This commit is contained in:
@@ -18,13 +18,31 @@ namespace PS
|
|||||||
class Process
|
class Process
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
STATIC PEPROCESS IdleProcess;
|
||||||
STATIC PEPROCESS SystemProcess;
|
STATIC PEPROCESS SystemProcess;
|
||||||
|
STATIC HANDLE SystemProcessHandle;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
STATIC XTAPI XTSTATUS CreateIdleProcess(IN PKPROCESSOR_CONTROL_BLOCK Prcb);
|
STATIC XTAPI XTSTATUS CreateIdleProcess(IN PKPROCESSOR_CONTROL_BLOCK Prcb);
|
||||||
|
STATIC XTAPI XTSTATUS CreateInitialSystemProcess(VOID);
|
||||||
|
STATIC XTAPI XTSTATUS CreateSystemProcess(OUT PHANDLE ProcessHandle,
|
||||||
|
IN ACCESS_MASK AccessMask,
|
||||||
|
IN POBJECT_ATTRIBUTES Attributes);
|
||||||
STATIC XTAPI VOID DeleteProcess(IN PVOID ProcessObject);
|
STATIC XTAPI VOID DeleteProcess(IN PVOID ProcessObject);
|
||||||
STATIC XTFASTCALL PEPROCESS GetCurrentProcess(VOID);
|
STATIC XTFASTCALL PEPROCESS GetCurrentProcess(VOID);
|
||||||
STATIC XTFASTCALL PEPROCESS GetSystemProcess(VOID);
|
STATIC XTFASTCALL PEPROCESS GetSystemProcess(VOID);
|
||||||
|
STATIC XTAPI VOID InitializeIdleProcess(VOID);
|
||||||
|
|
||||||
|
private:
|
||||||
|
STATIC XTAPI XTSTATUS CreateKernelProcess(OUT PHANDLE ProcessHandle,
|
||||||
|
IN ACCESS_MASK AccessMask,
|
||||||
|
IN POBJECT_ATTRIBUTES Attributes,
|
||||||
|
IN HANDLE ParentProcess,
|
||||||
|
IN ULONG Flags,
|
||||||
|
IN HANDLE SectionHandle,
|
||||||
|
IN HANDLE DebugPort,
|
||||||
|
IN HANDLE ExceptionPort,
|
||||||
|
IN BOOLEAN JobMember);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,9 +9,15 @@
|
|||||||
#include <xtos.hh>
|
#include <xtos.hh>
|
||||||
|
|
||||||
|
|
||||||
|
/* Pointer to the IDLE process object */
|
||||||
|
PEPROCESS PS::Process::IdleProcess;
|
||||||
|
|
||||||
/* Pointer to the system process object */
|
/* Pointer to the system process object */
|
||||||
PEPROCESS PS::Process::SystemProcess;
|
PEPROCESS PS::Process::SystemProcess;
|
||||||
|
|
||||||
|
/* Global handle to the root system process */
|
||||||
|
HANDLE PS::Process::SystemProcessHandle;
|
||||||
|
|
||||||
/* Global object type descriptor for Process objects */
|
/* Global object type descriptor for Process objects */
|
||||||
POBJECT_TYPE PS::ProcessManager::ProcessType;
|
POBJECT_TYPE PS::ProcessManager::ProcessType;
|
||||||
|
|
||||||
|
|||||||
@@ -50,6 +50,141 @@ PS::Process::CreateIdleProcess(IN PKPROCESSOR_CONTROL_BLOCK Prcb)
|
|||||||
return KE::KThread::InitializeIdleThread(IdleProcess, IdleThread, Prcb, AR::ProcessorSupport::GetBootStack());
|
return KE::KThread::InitializeIdleThread(IdleProcess, IdleThread, Prcb, AR::ProcessorSupport::GetBootStack());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates and initializes the primary system process.
|
||||||
|
*
|
||||||
|
* @return This routine returns a status code indicating the success or failure of the operation.
|
||||||
|
*
|
||||||
|
* @since XT 1.0
|
||||||
|
*/
|
||||||
|
XTAPI
|
||||||
|
XTSTATUS
|
||||||
|
PS::Process::CreateInitialSystemProcess(VOID)
|
||||||
|
{
|
||||||
|
OBJECT_ATTRIBUTES Attributes;
|
||||||
|
XTSTATUS Status;
|
||||||
|
|
||||||
|
/* Initialize process object attributes */
|
||||||
|
OB::Manager::InitializeObjectAttributes(&Attributes, NULLPTR, 0, NULLPTR, NULLPTR);
|
||||||
|
|
||||||
|
/* Spawn the root system process */
|
||||||
|
Status = CreateKernelProcess(&SystemProcessHandle, SE_PROCESS_ALL_ACCESS, &Attributes,
|
||||||
|
NULLPTR, 0, NULLPTR, NULLPTR, NULLPTR, FALSE);
|
||||||
|
if(Status != STATUS_SUCCESS)
|
||||||
|
{
|
||||||
|
/* Process creation failed, return error code */
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Reference the process handle for a persistent kernel object pointer */
|
||||||
|
Status = OB::LifeCycle::ReferenceObject(SystemProcessHandle, 0L, PS::ProcessManager::GetProcessType(),
|
||||||
|
KernelMode, (PVOID *)&SystemProcess, NULLPTR);
|
||||||
|
if(Status != STATUS_SUCCESS)
|
||||||
|
{
|
||||||
|
/* Handle reference failed, return error code */
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set the diagnostic image file name */
|
||||||
|
RTL::String::CopyString(&SystemProcess->ImageFileName[0], "System", 6);
|
||||||
|
|
||||||
|
/* Allocate memory for the process creation audit information */
|
||||||
|
Status = MM::Allocator::AllocatePool(PagedPool, sizeof(OBJECT_NAME_INFORMATION),
|
||||||
|
(PVOID *)&SystemProcess->AuditProcessCreationInfo.ImageFileName,
|
||||||
|
TAG_SE_PRIVILEGE_ARRAY);
|
||||||
|
if(Status != STATUS_SUCCESS || !SystemProcess->AuditProcessCreationInfo.ImageFileName)
|
||||||
|
{
|
||||||
|
/* Memory allocation failed, return error code */
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Zero the allocated audit information */
|
||||||
|
RtlZeroMemory(SystemProcess->AuditProcessCreationInfo.ImageFileName, sizeof(OBJECT_NAME_INFORMATION));
|
||||||
|
|
||||||
|
/* Return success */
|
||||||
|
return STATUS_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates, configures, and publishes a new kernel process object.
|
||||||
|
*
|
||||||
|
* @param ProcessHandle
|
||||||
|
* Receives the handle to the newly created process.
|
||||||
|
*
|
||||||
|
* @param AccessMask
|
||||||
|
* Supplies the desired access rights to be granted.
|
||||||
|
*
|
||||||
|
* @param Attributes
|
||||||
|
* Supplies an optional pointer to the object attributes for process namespace insertion.
|
||||||
|
*
|
||||||
|
* @param ParentProcess
|
||||||
|
* Supplies an optional handle to the parent process.
|
||||||
|
*
|
||||||
|
* @param Flags
|
||||||
|
* Supplies process creation behavioral flags.
|
||||||
|
*
|
||||||
|
* @param SectionHandle
|
||||||
|
* Supplies an optional handle to the backed file mapping section.
|
||||||
|
*
|
||||||
|
* @param DebugPort
|
||||||
|
* Supplies an optional handle to the debugging registration port.
|
||||||
|
*
|
||||||
|
* @param ExceptionPort
|
||||||
|
* Supplies an optional handle to the IPC exception port.
|
||||||
|
*
|
||||||
|
* @param JobMember
|
||||||
|
* Specifies if the process is part of a job hierarchy.
|
||||||
|
*
|
||||||
|
* @return This routine returns a status code indicating the success or failure of the operation.
|
||||||
|
*
|
||||||
|
* @since XT 1.0
|
||||||
|
*/
|
||||||
|
XTAPI
|
||||||
|
XTSTATUS
|
||||||
|
PS::Process::CreateKernelProcess(OUT PHANDLE ProcessHandle,
|
||||||
|
IN ACCESS_MASK AccessMask,
|
||||||
|
IN POBJECT_ATTRIBUTES Attributes,
|
||||||
|
IN HANDLE ParentProcess,
|
||||||
|
IN ULONG Flags,
|
||||||
|
IN HANDLE SectionHandle,
|
||||||
|
IN HANDLE DebugPort,
|
||||||
|
IN HANDLE ExceptionPort,
|
||||||
|
IN BOOLEAN JobMember)
|
||||||
|
{
|
||||||
|
UNIMPLEMENTED;
|
||||||
|
|
||||||
|
/* Not implemented */
|
||||||
|
return STATUS_NOT_IMPLEMENTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new process as a child of the main system process.
|
||||||
|
*
|
||||||
|
* @param ProcessHandle
|
||||||
|
* Receives the handle to the newly created process.
|
||||||
|
*
|
||||||
|
* @param AccessMask
|
||||||
|
* Supplies the desired access rights to be granted.
|
||||||
|
*
|
||||||
|
* @param Attributes
|
||||||
|
* Supplies an optional pointer to the object attributes for process namespace insertion.
|
||||||
|
*
|
||||||
|
* @return This routine returns a status code indicating the success or failure of the operation.
|
||||||
|
*
|
||||||
|
* @since XT 1.0
|
||||||
|
*/
|
||||||
|
XTAPI
|
||||||
|
XTSTATUS
|
||||||
|
PS::Process::CreateSystemProcess(OUT PHANDLE ProcessHandle,
|
||||||
|
IN ACCESS_MASK AccessMask,
|
||||||
|
IN POBJECT_ATTRIBUTES Attributes)
|
||||||
|
{
|
||||||
|
/* Create new process */
|
||||||
|
return CreateKernelProcess(ProcessHandle, AccessMask, Attributes, SystemProcessHandle,
|
||||||
|
0, NULLPTR, NULLPTR, NULLPTR, FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes a Process object when the final reference is released.
|
* Deletes a Process object when the final reference is released.
|
||||||
*
|
*
|
||||||
@@ -96,3 +231,31 @@ PS::Process::GetSystemProcess(VOID)
|
|||||||
/* Return the system process */
|
/* Return the system process */
|
||||||
return SystemProcess;
|
return SystemProcess;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes the system idle process.
|
||||||
|
*
|
||||||
|
* @return This routine does not return any value.
|
||||||
|
*
|
||||||
|
* @since XT 1.0
|
||||||
|
*/
|
||||||
|
XTAPI
|
||||||
|
VOID
|
||||||
|
PS::Process::InitializeIdleProcess(VOID)
|
||||||
|
{
|
||||||
|
/* Bind the currently executing bootstrap process as the system idle process */
|
||||||
|
IdleProcess = GetCurrentProcess();
|
||||||
|
|
||||||
|
/* Initialize the process lock and rundown protection */
|
||||||
|
KE::PushLock::InitializePushLock(&IdleProcess->ProcessLock);
|
||||||
|
EX::Rundown::InitializeProtection(&IdleProcess->RundownProtect);
|
||||||
|
|
||||||
|
/* Prepare the process thread tracking list */
|
||||||
|
RTL::LinkedList::InitializeListHead(&IdleProcess->ThreadListHead);
|
||||||
|
|
||||||
|
/* Set the diagnostic image file name */
|
||||||
|
RTL::String::CopyString(&IdleProcess->ImageFileName[0], "Idle", 4);
|
||||||
|
|
||||||
|
/* Reset the accounting metric */
|
||||||
|
IdleProcess->ProcessControlBlock.KernelTime = 0;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user