Skip to content

Implement file-backed mmap (MAP_PRIVATE) #230

@claude

Description

@claude

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions