gommap: github.com/glycerine/gommap Index | Files

package gommap

import "github.com/glycerine/gommap"

This package offers the MMap type that manipulates a memory mapped file or device.

IMPORTANT NOTE (1): The MMap type is backed by an unsafe memory region, which is not covered by the normal rules of Go's memory management. If a slice is taken out of it, and then the memory is explicitly unmapped through one of the available methods, both the MMap value itself and the slice obtained will now silently point to invalid memory. Attempting to access data in them will crash the application.

Index

Package Files

consts.go gommap.go mmap_linux_amd64.go

type AdviseFlags Uses

type AdviseFlags uint
const (
    MADV_NORMAL     AdviseFlags = 0x0
    MADV_RANDOM     AdviseFlags = 0x1
    MADV_SEQUENTIAL AdviseFlags = 0x2
    MADV_WILLNEED   AdviseFlags = 0x3
    MADV_DONTNEED   AdviseFlags = 0x4
    MADV_REMOVE     AdviseFlags = 0x9
    MADV_DONTFORK   AdviseFlags = 0xa
    MADV_DOFORK     AdviseFlags = 0xb
)

type MMap Uses

type MMap []byte

The MMap type represents a memory mapped file or device. The slice offers direct access to the memory mapped content.

IMPORTANT: Please see note in the package documentation regarding the way in which this type behaves.

func Map Uses

func Map(fd uintptr, prot ProtFlags, flags MapFlags) (MMap, error)

Map creates a new mapping in the virtual address space of the calling process. This function will attempt to map the entire file by using the fstat system call with the provided file descriptor to discover its length.

func MapAt Uses

func MapAt(addr uintptr, fd uintptr, offset, length int64, prot ProtFlags, flags MapFlags) (MMap, error)

MapAt creates a new mapping in the virtual address space of the calling process, using the specified region of the provided file or device. The provided addr parameter will be used as a hint of the address where the kernel should position the memory mapped region. If -1 is provided as length, this function will attempt to map until the end of the provided file descriptor by using the fstat system call to discover its length.

func MapRegion Uses

func MapRegion(fd uintptr, offset, length int64, prot ProtFlags, flags MapFlags) (MMap, error)

MapRegion creates a new mapping in the virtual address space of the calling process, using the specified region of the provided file or device. If -1 is provided as length, this function will attempt to map until the end of the provided file descriptor by using the fstat system call to discover its length.

func (MMap) Advise Uses

func (mmap MMap) Advise(advice AdviseFlags) error

Advise advises the kernel about how to handle the mapped memory region in terms of input/output paging within the memory region defined by the mmap slice.

func (MMap) IsResident Uses

func (mmap MMap) IsResident() ([]bool, error)

IsResident returns a slice of booleans informing whether the respective memory page in mmap was mapped at the time the call was made.

func (MMap) Lock Uses

func (mmap MMap) Lock() error

Lock locks the mapped region defined by the mmap slice, preventing it from being swapped out.

func (MMap) Protect Uses

func (mmap MMap) Protect(prot ProtFlags) error

Protect changes the protection flags for the memory mapped region defined by the mmap slice.

func (MMap) Sync Uses

func (mmap MMap) Sync(flags SyncFlags) error

Sync flushes changes made to the region determined by the mmap slice back to the device. Without calling this method, there are no guarantees that changes will be flushed back before the region is unmapped. The flags parameter specifies whether flushing should be done synchronously (before the method returns) with MS_SYNC, or asynchronously (flushing is just scheduled) with MS_ASYNC.

func (MMap) Unlock Uses

func (mmap MMap) Unlock() error

Unlock unlocks the mapped region defined by the mmap slice, allowing it to swap out again.

func (MMap) UnsafeUnmap Uses

func (mmap MMap) UnsafeUnmap() error

UnsafeUnmap deletes the memory mapped region defined by the mmap slice. This will also flush any remaining changes, if necessary. Using mmap or any other slices based on it after this method has been called will crash the application.

type MapFlags Uses

type MapFlags uint
const (
    MAP_SHARED    MapFlags = 0x1
    MAP_PRIVATE   MapFlags = 0x2
    MAP_FIXED     MapFlags = 0x10
    MAP_ANONYMOUS MapFlags = 0x20
    MAP_GROWSDOWN MapFlags = 0x100
    MAP_LOCKED    MapFlags = 0x2000
    MAP_NONBLOCK  MapFlags = 0x10000
    MAP_NORESERVE MapFlags = 0x4000
    MAP_POPULATE  MapFlags = 0x8000
)

type ProtFlags Uses

type ProtFlags uint
const (
    PROT_NONE  ProtFlags = 0x0
    PROT_READ  ProtFlags = 0x1
    PROT_WRITE ProtFlags = 0x2
    PROT_EXEC  ProtFlags = 0x4
)

type SyncFlags Uses

type SyncFlags uint
const (
    MS_SYNC       SyncFlags = 0x4
    MS_ASYNC      SyncFlags = 0x1
    MS_INVALIDATE SyncFlags = 0x2
)

Package gommap imports 4 packages (graph) and is imported by 3 packages. Updated 2016-07-29. Refresh now. Tools for package owners.