Overview
Implement file-backed mmap(fd, offset, length, MAP_PRIVATE, ...) in the kernel.
Motivation
This is a prerequisite for dynamic linking (#199). The dynamic linker (ld-musl-riscv64.so.1) maps shared libraries into memory using file-backed mmap with MAP_PRIVATE. Without this, ld.so cannot load shared libraries.
Current State
Solaya currently supports anonymous mmap (no file descriptor). File-backed mmap is not yet implemented.
Requirements
mmap(fd, offset, length, PROT_READ|PROT_EXEC, MAP_PRIVATE, ...) — map a file region into virtual memory read-only / executable
mmap(fd, offset, length, PROT_READ|PROT_WRITE, MAP_PRIVATE, ...) — map a file region with copy-on-write semantics
- Copy-on-write: writes to
MAP_PRIVATE file-backed mappings must not affect the underlying file
munmap for these regions (already needed for anonymous mmap)
Implementation Notes
MAP_PRIVATE with file: initially map pages as read-only backed by file content; on write fault, copy the page (CoW)
- Or: eagerly copy the file content into anonymous pages on mapping (simpler, correct for
MAP_PRIVATE)
- The simpler eager-copy approach is acceptable for the dynamic linker use case
Relevant Files
kernel/src/syscalls/mm_ops.rs — mmap syscall implementation
kernel/src/memory/ — page allocator, page tables
kernel/src/processes/process.rs — process memory map
Created by Claude Code
Overview
Implement file-backed
mmap(fd, offset, length, MAP_PRIVATE, ...)in the kernel.Motivation
This is a prerequisite for dynamic linking (#199). The dynamic linker (
ld-musl-riscv64.so.1) maps shared libraries into memory using file-backedmmapwithMAP_PRIVATE. Without this,ld.socannot load shared libraries.Current State
Solaya currently supports anonymous
mmap(no file descriptor). File-backedmmapis not yet implemented.Requirements
mmap(fd, offset, length, PROT_READ|PROT_EXEC, MAP_PRIVATE, ...)— map a file region into virtual memory read-only / executablemmap(fd, offset, length, PROT_READ|PROT_WRITE, MAP_PRIVATE, ...)— map a file region with copy-on-write semanticsMAP_PRIVATEfile-backed mappings must not affect the underlying filemunmapfor these regions (already needed for anonymous mmap)Implementation Notes
MAP_PRIVATEwith file: initially map pages as read-only backed by file content; on write fault, copy the page (CoW)MAP_PRIVATE)Relevant Files
kernel/src/syscalls/mm_ops.rs— mmap syscall implementationkernel/src/memory/— page allocator, page tableskernel/src/processes/process.rs— process memory mapCreated by Claude Code