gommap

package module
Version: v0.0.0-...-0000000 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 12, 2012 License: BSD-3-Clause Imports: 4 Imported by: 37

Documentation

Overview

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

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AdviseFlags

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

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

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

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

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

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

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

func (mmap MMap) Lock() error

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

func (MMap) Protect

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

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

func (mmap MMap) Unlock() error

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

func (MMap) UnsafeUnmap

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

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

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

type SyncFlags

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

Directories

Path Synopsis
trunk module

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto