diff options
| author | Amlal <amlalelmahrouss@icloud.com> | 2024-12-21 21:59:13 +0100 |
|---|---|---|
| committer | Amlal <amlalelmahrouss@icloud.com> | 2024-12-21 21:59:45 +0100 |
| commit | 610f91d87152cbe48d3054fcf437d8239da6ef35 (patch) | |
| tree | a386f7047ab73d088169ab2371ddc6ffe8020f1c /dev/Kernel/src/CodeMgr.cc | |
| parent | 509fcca5986651c8ba712fb395f8498f2dea4109 (diff) | |
IMP: :boom: Breaking changes some checks are needed to be done.
Signed-off-by: Amlal <amlalelmahrouss@icloud.com>
Diffstat (limited to 'dev/Kernel/src/CodeMgr.cc')
| -rw-r--r-- | dev/Kernel/src/CodeMgr.cc | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/dev/Kernel/src/CodeMgr.cc b/dev/Kernel/src/CodeMgr.cc new file mode 100644 index 00000000..4a3fdcf1 --- /dev/null +++ b/dev/Kernel/src/CodeMgr.cc @@ -0,0 +1,38 @@ +/* ------------------------------------------- + + Copyright (C) 2024, TQ B.V, all rights reserved. + +------------------------------------------- */ + +#include <KernelKit/CodeMgr.h> +#include <NewKit/Utils.h> +#include <KernelKit/UserProcessScheduler.h> + +namespace Kernel +{ + /// @brief Executes a new process from a function. Kernel code only. + /// @note This sets up a new stack, anything on the main function that calls the Kernel will not be accessible. + /// @param main the start of the process. + /// @return if the process was started or not. + ProcessID rtl_create_process(rtl_main_kind main, const Char* process_name) noexcept + { + if (*process_name == 0) + return kProcessInvalidID; + + UserProcess* process_hdr = new UserProcess(); + + process_hdr->Image.fCode = reinterpret_cast<VoidPtr>(main); + process_hdr->Kind = UserProcess::kExectuableKind; + process_hdr->StackSize = kib_cast(8); + + rt_set_memory(process_hdr->Name, 0, kProcessNameLen); + rt_copy_memory((VoidPtr)process_name, process_hdr->Name, rt_string_len(process_name)); + + ProcessID id = UserProcessScheduler::The().Spawn(process_hdr); + + if (id == kProcessInvalidID) + delete process_hdr; + + return id; + } +} // namespace Kernel |
