MCPcopy Create free account
hub / github.com/Simple-XX/SimpleKernel / sys_clone

Function sys_clone

src/syscall.cpp:117–145  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

115}
116
117[[nodiscard]] auto sys_clone(uint64_t flags, void* stack, int* parent_tid,
118 int* child_tid, void* tls) -> int {
119 auto& task_manager = TaskManagerSingleton::instance();
120 auto current = task_manager.GetCurrentTask();
121
122 if (!current || !current->trap_context_ptr) {
123 klog::Err("[Syscall] sys_clone: Invalid current task or trap context");
124 return -1;
125 }
126
127 // 调用 TaskManager 的 Clone 方法
128 auto result = task_manager.Clone(flags, stack, parent_tid, child_tid, tls,
129 *current->trap_context_ptr);
130
131 if (!result.has_value()) {
132 // 失败返回 -1
133 klog::Err("[Syscall] sys_clone failed: {}", result.error().message());
134 return -1;
135 }
136
137 Pid child_pid = result.value();
138 if (child_pid == 0) {
139 // 子进程/线程返回 0
140 return 0;
141 } else {
142 // 父进程返回子进程 PID
143 return static_cast<int>(child_pid);
144 }
145}
146
147[[nodiscard]] auto sys_fork() -> int {
148 auto& task_manager = TaskManagerSingleton::instance();

Callers 1

syscall_dispatcherFunction · 0.85

Calls 4

ErrFunction · 0.85
GetCurrentTaskMethod · 0.80
CloneMethod · 0.80
messageMethod · 0.80

Tested by

no test coverage detected