mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-08 02:31:19 +00:00
a41e372b39
Former-commit-id: fa0dc873367b92a06b10fd989e3fec960c03065a [formerly e98efffa565ea6aa3eadeb19c2f9a66a56eb5ddd] Former-commit-id: ce6e4f01d12015e67a51aa7d928a6ab8e8eedeee
68 lines
1.4 KiB
Go
68 lines
1.4 KiB
Go
// Copyright 2011 Evan Shaw. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
// +build darwin dragonfly freebsd linux openbsd solaris netbsd
|
|
|
|
package mmap
|
|
|
|
import (
|
|
"syscall"
|
|
)
|
|
|
|
func mmap(len int, inprot, inflags, fd uintptr, off int64) ([]byte, error) {
|
|
flags := syscall.MAP_SHARED
|
|
prot := syscall.PROT_READ
|
|
switch {
|
|
case inprot© != 0:
|
|
prot |= syscall.PROT_WRITE
|
|
flags = syscall.MAP_PRIVATE
|
|
case inprot&RDWR != 0:
|
|
prot |= syscall.PROT_WRITE
|
|
}
|
|
if inprot&EXEC != 0 {
|
|
prot |= syscall.PROT_EXEC
|
|
}
|
|
if inflags&ANON != 0 {
|
|
flags |= syscall.MAP_ANON
|
|
}
|
|
|
|
b, err := syscall.Mmap(int(fd), off, len, prot, flags)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return b, nil
|
|
}
|
|
|
|
func flush(addr, len uintptr) error {
|
|
_, _, errno := syscall.Syscall(_SYS_MSYNC, addr, len, _MS_SYNC)
|
|
if errno != 0 {
|
|
return syscall.Errno(errno)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func lock(addr, len uintptr) error {
|
|
_, _, errno := syscall.Syscall(syscall.SYS_MLOCK, addr, len, 0)
|
|
if errno != 0 {
|
|
return syscall.Errno(errno)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func unlock(addr, len uintptr) error {
|
|
_, _, errno := syscall.Syscall(syscall.SYS_MUNLOCK, addr, len, 0)
|
|
if errno != 0 {
|
|
return syscall.Errno(errno)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func unmap(addr, len uintptr) error {
|
|
_, _, errno := syscall.Syscall(syscall.SYS_MUNMAP, addr, len, 0)
|
|
if errno != 0 {
|
|
return syscall.Errno(errno)
|
|
}
|
|
return nil
|
|
}
|