github.com/database64128/shadowsocks-go@v1.10.2-0.20240315062903-143a773533f1/mmap/mmap_unix_fast.go (about) 1 //go:build (freebsd || linux) && (amd64 || arm64 || loong64 || mips64 || mips64le || ppc64 || ppc64le || riscv64 || sparc64) 2 3 package mmap 4 5 import ( 6 "os" 7 8 "golang.org/x/sys/unix" 9 ) 10 11 func readFile(f *os.File, size int64) (uintptr, error) { 12 r0, _, e1 := unix.Syscall6(unix.SYS_MMAP, 0, uintptr(size), unix.PROT_READ, unix.MAP_SHARED, f.Fd(), 0) 13 if e1 != 0 { 14 return 0, os.NewSyscallError("mmap", e1) 15 } 16 return r0, nil 17 } 18 19 func unmap(addr uintptr, length int) error { 20 _, _, e1 := unix.Syscall(unix.SYS_MUNMAP, addr, uintptr(length), 0) 21 if e1 != 0 { 22 return os.NewSyscallError("munmap", e1) 23 } 24 return nil 25 }