libc: implement fork

This commit is contained in:
2026-05-30 10:03:36 +01:00
parent bfd191a336
commit addd36d237
2 changed files with 25 additions and 1 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
set(source_dirs assert stdio stdlib string errno ctype wctype) set(source_dirs assert stdio stdlib string errno ctype wctype unistd)
foreach (dir ${source_dirs}) foreach (dir ${source_dirs})
file(GLOB dir_sources ${CMAKE_CURRENT_SOURCE_DIR}/${dir}/*.c) file(GLOB dir_sources ${CMAKE_CURRENT_SOURCE_DIR}/${dir}/*.c)
+24
View File
@@ -0,0 +1,24 @@
#include <errno.h>
#include <magenta/task.h>
#include <sys/types.h>
pid_t fork(void)
{
kern_handle_t new_task = KERN_HANDLE_INVALID,
new_space = KERN_HANDLE_INVALID;
kern_status_t status = task_duplicate(&new_task, &new_space);
if (status != KERN_OK) {
return __set_errno(__errno_from_kern_status(status));
}
if (new_task == KERN_HANDLE_INVALID) {
/* child task */
return 0;
}
tid_t child = 0;
task_config_get(new_task, TASK_CFG_ID, &child, sizeof child);
/* parent task */
return child;
}