github.com/dearplain/goloader@v0.0.0-20190107071432-2b1e47d74273/mmap_unix.go (about) 1 // +build darwin dragonfly freebsd linux openbsd solaris netbsd 2 3 package goloader 4 5 import ( 6 "os" 7 "syscall" 8 ) 9 10 func Mmap(size int) ([]byte, error) { 11 data, err := syscall.Mmap( 12 0, 13 0, 14 size, 15 syscall.PROT_READ|syscall.PROT_WRITE|syscall.PROT_EXEC, 16 syscall.MAP_PRIVATE|syscall.MAP_ANON) 17 if err != nil { 18 err = os.NewSyscallError("syscall.Mmap", err) 19 } 20 return data, err 21 } 22 23 func Munmap(b []byte) (err error) { 24 err = syscall.Munmap(b) 25 if err != nil { 26 err = os.NewSyscallError("syscall.Munmap", err) 27 } 28 return 29 }