Native

NAME

Mmap::Native - interface to posix mmap() and mmunmap() calls

SYNOPSIS


use Mmap::Native;

my $f = $*CWD.add('META6.json'); $f = $f.open;
my $d = mmap Pointer, 50, PROT_READ, MAP_SHARED, $f.native-descriptor, 0;
my $e = blob-from-pointer $d, :50elems, :type(Buf[uint8]);

is $e.decode('utf8'), /'"auth": "zef:massa"'/;

DESCRIPTION

Mmap::Native is a raw interface to the C library mmap and munmap calls.

It's mostly used for mmaping Blob objects and other raw C pointers. It's recommended that the library using it present a most Raku-esque interface and hide the mmapping altogether. This is just a low level library.

CONSTANTS

Remember to always use +| to combine flag values!

### The `$prot` argument flags

Describes the desired memory protection of the mapping (and must not conflict with the open mode of the file). It is either PROT_NONE or the bitwise OR of one or more of the following flags:

Flag | Description
PROT_READ | page can be read
PROT_WRITE | page can be written
PROT_EXEC | page can be executed
PROT_SEM | page may be used for atomic ops
PROT_NONE | page can not be accessed
PROT_GROWSDOWN | mprotect flag: extend change to start of growsdown vma
PROT_GROWSUP | mprotect flag: extend change to end of growsup vma

### The `$flags` argument

Determines whether updates to the mapping are visible to other processes mapping the same region, and whether updates are carried through to the underlying file. This behavior is determined by including exactly one of the following values:

Flag | Description
MAP_SHARED | Share changes
MAP_PRIVATE | Changes are private
MAP_SHARED_VALIDATE | share and validate extension flags
MAP_TYPE | Mask for type of mapping
MAP_FIXED | Interpret addr exactly
MAP_ANONYMOUS | don't use a file
MAP_GROWSDOWN | stack-like segment
MAP_DENYWRITE | ETXTBSY
MAP_EXECUTABLE | mark it as an executable
MAP_LOCKED | pages are locked
MAP_NORESERVE | don't check for reservations
MAP_POPULATE | populate (prefault) pagetables
MAP_NONBLOCK | do not block on IO
MAP_STACK | give out an address that is best suited for process/thread stacks
MAP_HUGETLB | create a huge page mapping
MAP_SYNC | perform synchronous page faults for the mapping
MAP_FIXED_NOREPLACE | MAP_FIXED which doesn't unmap underlying mapping
MAP_UNINITIALIZED | For anonymous mmap, memory could be * uninitialized
MLOCK_ONFAULT | Lock pages in range after they are faulted in, do not prefault
MS_ASYNC | sync memory asynchronously
MS_INVALIDATE | invalidate the caches
MS_SYNC | synchronous memory sync
MADV_NORMAL | no further special treatment
MADV_RANDOM | expect random page references
MADV_SEQUENTIAL | expect sequential page references
MADV_WILLNEED | will need these pages
MADV_DONTNEED | don't need these pages
MADV_FREE | free pages only if memory pressure
MADV_REMOVE | remove these pages & resources
MADV_DONTFORK | don't inherit across fork
MADV_DOFORK | do inherit across fork
MADV_HWPOISON | poison a page for testing
MADV_SOFT_OFFLINE | soft offline page for testing
MADV_MERGEABLE | KSM may merge identical pages
MADV_UNMERGEABLE | KSM may not merge identical pages
MADV_HUGEPAGE | Worth backing with hugepages
MADV_NOHUGEPAGE | Not worth backing with hugepages
MADV_DONTDUMP | Explicity exclude from the core dump, overrides the coredump filter bits
MADV_DODUMP | Clear the MADV_DONTDUMP flag
MADV_WIPEONFORK | Zero memory on fork, child only
MADV_KEEPONFORK | Undo MADV_WIPEONFORK
MADV_COLD | deactivate these pages
MADV_PAGEOUT | reclaim these pages
MADV_POPULATE_READ | populate (prefault) page tables readable
MADV_POPULATE_WRITE | populate (prefault) page tables writable
MADV_DONTNEED_LOCKED | like DONTNEED, but drop locked pages too
MADV_COLLAPSE | Synchronous hugepage collapse

FUNCTIONS

AUTHOR

Humberto Massa `[email protected]`

COPYRIGHT AND LICENSE

Copyright Ā© 2024 Humberto Massa

This library is free software; you can redistribute it and/or modify it under either the Artistic License 2.0 or the LGPL v3.0, at your convenience.

Mmap::Native v0.0.6

interface to posix mmap() and mmunmap() calls

Authors

  • Humberto Massa

License

Artistic-2.0

Dependencies

NativeHelpers::Blob

Test Dependencies

Provides

  • Mmap::Native

Documentation

The Camelia image is copyright 2009 by Larry Wall. "Raku" is a trademark of the Yet Another Society. All rights reserved.

Built with Podlite — the markup and publishing tools behind this site.