github.com/eh-steve/goloader@v0.0.0-20240111193454-90ff3cfdae39/mmap/zsyscall_openbsd.go (about) 1 //go:build openbsd 2 // +build openbsd 3 4 package mmap 5 6 import ( 7 "syscall" 8 "unsafe" 9 ) 10 11 //go:linkname syscall6X syscall.syscall6X 12 //go:nosplit 13 func syscall6X(fn, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err syscall.Errno) 14 15 //go:linkname syscall4 syscall.syscall 16 //go:nosplit 17 func syscall4(fn, a1, a2, a3 uintptr) (r1, r2 uintptr, err syscall.Errno) 18 19 func mmap(addr uintptr, length uintptr, prot int, flag int, fd int, pos int64) (ret uintptr, err error) { 20 r0, _, e1 := syscall6X(getFunctionPtr(libc_mmap_trampoline), uintptr(addr), uintptr(length), uintptr(prot), uintptr(flag), uintptr(fd), uintptr(pos)) 21 ret = uintptr(r0) 22 if e1 != 0 { 23 err = errnoErr(e1) 24 } 25 return 26 } 27 28 func libc_mmap_trampoline() 29 30 //go:cgo_import_dynamic libc_mmap mmap "libc.so" 31 32 func munmap(addr uintptr, length uintptr) (err error) { 33 _, _, e1 := syscall4(getFunctionPtr(libc_munmap_trampoline), uintptr(addr), uintptr(length), 0) 34 if e1 != 0 { 35 err = errnoErr(e1) 36 } 37 return 38 } 39 40 func libc_munmap_trampoline() 41 42 //go:cgo_import_dynamic libc_munmap munmap "libc.so" 43 44 type emptyInterface struct { 45 _type unsafe.Pointer 46 data unsafe.Pointer 47 } 48 49 func getFunctionPtr(function interface{}) uintptr { 50 return *(*uintptr)((*emptyInterface)(unsafe.Pointer(&function)).data) 51 }