Skip to main content

Module fork

Module fork 

Source
Expand description

fork() syscall implementation with copy-on-write (COW).

This module implements the fork() syscall, which creates a new child process by cloning the calling process. The child gets a copy of the parent’s address space, but the actual physical memory is shared between parent and child until either of them writes to it, at which point the kernel transparently creates a private copy for the writing process (copy-on-write).

The main entry point is sys_fork, which performs the necessary checks, clones the address space with COW semantics, and creates a new Task for the child process. The handle_cow_fault function is called from the page fault handler when a write fault occurs on a COW page, and it resolves the fault by either making the page writable (if the faulting process is the sole owner) or by copying the page to a new frame and updating the mapping.

Source : https://man7.org/linux/man2/fork.2.html https://man7.org/linux/man2/vfork.2.html https://man7.org/linux/man2/clone.2.html

TODO: implement vfork() and clone() with more fine-grained control over sharing.

COW : https://en.wikipedia.org/wiki/Copy-on-write https://lwn.net/Articles/531114/

Structs§

ForkResult
Result returned by sys_fork.

Functions§

handle_cow_fault
Called from the page fault handler when a write fault occurs on a present page. Returns Ok(()) if the fault was successfully handled (COW resolution), or Err if it wasn’t a COW fault (real access violation).
sys_fork
SYS_PROC_FORK (302): fork with copy-on-write address-space cloning.