github.com/pkujhd/goloader@v0.0.0-20240411034752-1a28096bd7bd/mmap/mmap_linux_amd64.go (about) 1 //go:build linux && amd64 2 // +build linux,amd64 3 4 package mmap 5 6 import ( 7 "os" 8 "syscall" 9 ) 10 11 func MakeThreadJITCodeExecutable(ptr uintptr, len int) { 12 } 13 14 func Mmap(size int) ([]byte, error) { 15 data, err := syscall.Mmap( 16 0, 17 0, 18 size, 19 syscall.PROT_READ|syscall.PROT_WRITE|syscall.PROT_EXEC, 20 syscall.MAP_PRIVATE|syscall.MAP_ANON|syscall.MAP_32BIT) 21 if err != nil { 22 err = os.NewSyscallError("syscall.Mmap", err) 23 } 24 return data, err 25 } 26 27 func MmapData(size int) ([]byte, error) { 28 data, err := syscall.Mmap( 29 0, 30 0, 31 size, 32 syscall.PROT_READ|syscall.PROT_WRITE, 33 syscall.MAP_PRIVATE|syscall.MAP_ANON|syscall.MAP_32BIT) 34 if err != nil { 35 err = os.NewSyscallError("syscall.Mmap", err) 36 } 37 return data, err 38 } 39 40 func Munmap(b []byte) (err error) { 41 err = syscall.Munmap(b) 42 if err != nil { 43 err = os.NewSyscallError("syscall.Munmap", err) 44 } 45 return 46 }