This assignment extends xv6 with shared memory support and builds a multi-process logging system on top of it.
It integrates virtual memory manipulation, page-table operations, and synchronization using atomic primitives.
Enable one process to map a region of its virtual memory into another process’s address space — similar to real OS IPC mechanisms.
- Translates virtual→physical pages in the source.
- Maps them into the destination process’s page table.
- Handles alignment (page rounding) and offset correction.
- Copies permission flags and adds a new shared-page marker (
PTE_S). - Updates
szfor the destination process.
- Safely removes mappings without freeing shared physical pages unless owned by the process.
- Prevents double-frees during process termination.
sys_map_shared_pages();
sys_unmap_shared_pages();Validates:
- Parent/child shared communication
- Correct string exchange
- Proper unmapping and allocation after unmap
- Cleanup behavior when child terminates without unmapping
Use the shared memory abstraction to create a concurrent logging buffer written to by multiple children.
Each log entry has:
[ 32-bit header | message bytes ... ]
Header format:
- Upper 16 bits → child index
- Lower 16 bits → message length
Used:
__sync_val_compare_and_swap()for atomic header claims.
Alignment rules:
addr = (addr + 3) & ~3;Ensures 4-byte alignment for atomic header writes.
- Forks multiple children.
- Parent allocates and maps a shared buffer.
- Children write messages until buffer is full.
- Parent scans and prints messages.
- Kernel virtual memory manipulation
- Page-table design and multi-process address space management
- Atomic synchronization in shared memory
- Concurrent system design in a minimal OS
- Debugging low-level interactions between processes
For educational and demonstration purposes only.