github.com/cnboonhan/delve@v0.0.0-20230908061759-363f2388c2fb/pkg/proc/native/ptrace_linux_64bit.go (about)

     1  //go:build (linux && amd64) || (linux && arm64) || (linux && ppc64le)
     2  // +build linux,amd64 linux,arm64 linux,ppc64le
     3  
     4  package native
     5  
     6  import (
     7  	"syscall"
     8  	"unsafe"
     9  
    10  	sys "golang.org/x/sys/unix"
    11  )
    12  
    13  // processVmRead calls process_vm_readv
    14  func processVmRead(tid int, addr uintptr, data []byte) (int, error) {
    15  	len_iov := uint64(len(data))
    16  	local_iov := sys.Iovec{Base: &data[0], Len: len_iov}
    17  	remote_iov := remoteIovec{base: addr, len: uintptr(len_iov)}
    18  	n, _, err := syscall.Syscall6(sys.SYS_PROCESS_VM_READV, uintptr(tid), uintptr(unsafe.Pointer(&local_iov)), 1, uintptr(unsafe.Pointer(&remote_iov)), 1, 0)
    19  	if err != syscall.Errno(0) {
    20  		return 0, err
    21  	}
    22  	return int(n), nil
    23  }
    24  
    25  // processVmWrite calls process_vm_writev
    26  func processVmWrite(tid int, addr uintptr, data []byte) (int, error) {
    27  	len_iov := uint64(len(data))
    28  	local_iov := sys.Iovec{Base: &data[0], Len: len_iov}
    29  	remote_iov := remoteIovec{base: addr, len: uintptr(len_iov)}
    30  	n, _, err := syscall.Syscall6(sys.SYS_PROCESS_VM_WRITEV, uintptr(tid), uintptr(unsafe.Pointer(&local_iov)), 1, uintptr(unsafe.Pointer(&remote_iov)), 1, 0)
    31  	if err != syscall.Errno(0) {
    32  		return 0, err
    33  	}
    34  	return int(n), nil
    35  }