33
28
// Single-word zero for use when we need a valid pointer to 0 bytes.
34
29
// See mksyscall.sh.
37
// Mmap manager, for use by operating system-specific implementations.
41
active map[*byte][]byte // active mappings; key is last byte in mapping
42
mmap func(addr, length uintptr, prot, flags, fd int, offset int64) (uintptr, int)
43
munmap func(addr uintptr, length uintptr) int
46
func (m *mmapper) Mmap(fd int, offset int64, length int, prot int, flags int) (data []byte, errno int) {
51
// Map the requested memory.
52
addr, errno := m.mmap(0, uintptr(length), prot, flags, fd, offset)
57
// Slice memory layout
62
}{addr, length, length}
64
// Use unsafe to turn sl into a []byte.
65
b := *(*[]byte)(unsafe.Pointer(&sl))
67
// Register mapping in m and return it.
75
func (m *mmapper) Munmap(data []byte) (errno int) {
76
if len(data) == 0 || len(data) != cap(data) {
80
// Find the base of the mapping.
81
p := &data[cap(data)-1]
85
if b == nil || &b[0] != &data[0] {
89
// Unmap the memory and update m.
90
if errno := m.munmap(uintptr(unsafe.Pointer(&b[0])), uintptr(len(b))); errno != 0 {
93
m.active[p] = nil, false