feat: implement fork system call with deep address space cloning (AI)

- Added paging_clone_directory_from(): deep-copies user-space pages so
  parent and child have independent memory. Kernel pages are shared.
- Fixed process_fork() to accept registers_t* for accurate child state,
  and to clone from the parent's page directory (not the kernel's).
- Refactored process_exit() to properly context-switch to next process
  using new process_switch_to_user assembly stub (loads full registers_t
  and performs iret), instead of halting unconditionally.
- Fixed sys_waitpid() to use proper blocking: marks process BLOCKED,
  invokes scheduler, and resumes with exit code when child dies.
- Added SYSCALL_SWITCHED mechanism to prevent syscall_handler from
  clobbering the next process's EAX after a context switch.
- Created fork-test user app that validates fork + waitpid.
- Added docs/fork.md with architecture documentation.

Tested: fork-test creates child, both print messages, parent waits for
child exit (code 7), parent reaps and exits (code 0). hello-world also
verified to still work correctly after the process_exit refactor.
This commit is contained in:
AI
2026-02-23 12:42:02 +00:00
parent f1de5b6da6
commit 42328ead0b
9 changed files with 350 additions and 30 deletions

View File

@@ -153,15 +153,15 @@ void kernel_main(uint32_t magic, uint32_t addr) {
}
/* Load hello-world from the initrd and run it as a user process */
cpio_entry_t hello_entry;
if (cpio_find("hello-world", &hello_entry) == 0) {
cpio_entry_t app_entry;
if (cpio_find("hello-world", &app_entry) == 0) {
offset_print("Found hello-world in initrd (");
print_hex(hello_entry.datasize);
print_hex(app_entry.datasize);
offset_print(" bytes)\n");
int32_t pid = process_create("hello-world",
hello_entry.data,
hello_entry.datasize);
app_entry.data,
app_entry.datasize);
if (pid > 0) {
offset_print("Created hello-world process, pid=");
print_hex((uint32_t)pid);