Skip to content

Enable mmap stdlib module (memory-mapped file I/O) #301

@ppenna

Description

@ppenna

Summary

Enable the mmap C extension module, which provides memory-mapped file I/O support.

Current State

Commented out in Modules/Setup.stdlib:

#mmap mmapmodule.c

Why Enable It

  • mmap enables efficient file I/O by mapping files directly into memory
  • Used by multiprocessing.shared_memory for shared memory segments
  • importlib can use mmap for faster module loading
  • Many data processing libraries rely on mmap for large file handling
  • ctypes may use mmap internally

Work Required

  1. Uncomment in Modules/Setup.stdlib:
    mmap mmapmodule.c
    
  2. Nanvix POSIX syscall requirements:
    • mmap(addr, length, prot, flags, fd, offset) — map files/memory
    • munmap(addr, length) — unmap memory
    • msync(addr, length, flags) — synchronize mapped memory
    • madvise(addr, length, advice) — memory advisory (optional)
    • mremap(old_addr, old_size, new_size, flags) — resize mapping (Linux-specific, optional)
  3. Required headers: <sys/mman.h>
  4. Protection flags needed: PROT_READ, PROT_WRITE, PROT_EXEC
  5. Mapping flags needed: MAP_SHARED, MAP_PRIVATE, MAP_ANONYMOUS
  6. Build and test: python -c "import mmap; print(mmap.PAGESIZE)"

POSIX API Dependencies

API Purpose
mmap() Create memory mapping
munmap() Remove memory mapping
msync() Flush changes to disk
madvise() Memory usage hints (optional)
mprotect() Change protection (optional)

Complexity

High — requires Nanvix to support virtual memory mapping syscalls. This is a fundamental OS capability.

Source Files

  • Modules/mmapmodule.c

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions