#line 416 "/home/travis/build/felix-lang/felix/src/packages/pointers.fdoc"
  
  class Mmap
  {
    requires package "mmap";
    header """
      // MAP_ANON is an older form of MAP_ANONYMOUS, and should be compatible
      #if !defined(MAP_ANONYMOUS) && defined(MAP_ANON)
      #  define MAP_ANONYMOUS MAP_ANON
      #endif
    """;
  
    // Offset into file, should be defined elsewhere
    typedef off_t = ulong;
  
    type mmap_prot = "int";
    instance Eq[mmap_prot]{
       fun == : mmap_prot * mmap_prot -> bool = "$1==$2";
    }
    instance Bits[mmap_prot]{}
  
    inherit Eq[mmap_prot];
    inherit Bits[mmap_prot];
  
  
    type mmap_flags = "int";
    instance Eq[mmap_flags]{
       fun == : mmap_flags * mmap_flags -> bool = "$1==$2";
    }
    instance Bits[mmap_flags]{}
  
    inherit Eq[mmap_flags];
    inherit Bits[mmap_flags];
  
    // protection options
    const PROT_NONE  : mmap_prot;  // Posix: inaccessible
    const PROT_EXEC  : mmap_prot;  // Posix: allow exec
    const PROT_READ  : mmap_prot;  // Posix: allow read (and perhaps exec)
    const PROT_WRITE : mmap_prot;  // Posix: allow write (and perhaps write and exec)
  
    // Linux only
    const MAP_DENYWRITE: mmap_flags; // Linux only
  
    // flags: mode
    const MAP_FILE: mmap_flags;      // Posix: Default mode: map a file
    const MAP_ANONYMOUS: mmap_flags; // Linux, OSX: Map from VM pool
  
    // flags: map address
    const MAP_FIXED: mmap_flags;     // Posix: Client tries to fix the mapping address,
                              // must set address argument non-NULL
                              // Implementation dependent
                              // Default: system chooses address is not specified
                              // must set address NULL
  
    // flags: sharing
    const MAP_SHARED : mmap_flags;   // Posix: write changes to backing store on msync
    const MAP_PRIVATE : mmap_flags;  // Posix: don't write changes ever
  
    // System dependent:
    const MAP_HASSEMAPHORE: mmap_flags;
    const MAP_NORESERVE: mmap_flags;
    const MAP_LOCKED: mmap_flags;
    const MAP_GROWSDOWN: mmap_flags;
    const MAP_32BIT: mmap_flags;
    const MAP_POPULATE: mmap_flags;
    const MAP_NONBLOCK: mmap_flags;
  
    // return value of mmap
    const MAP_FAILED : address;
  
    // size of a page
    const _SC_PAGESIZE : long = "sysconf(_SC_PAGESIZE)";
  
    // establish a mapping
    fun mmap:
      address * //< start address
      size *    //< bytes to map
      mmap_prot *     //< protection
      mmap_flags *     //< flags
      int *     //< file descriptor
      off_t     //< offset into file, multiple of _SC_PAGESIZE
      -> address; //< start of reserved address space
  
    // unmap a region
    fun munmap: address * size -> int;
  
    // save region to backing store (MAP_SHARED only)
    fun msync: address * size * int -> int;
  }