vmReadBytes reads at most maxSize bytes from the process's virtual memory starting at ptr. It returns an error if the address range isn't readable or if the notification is invalid.
(n *seccomp.Notif, ptr uintptr, maxSize int)
| 72 | // starting at ptr. It returns an error if the address range isn't readable or |
| 73 | // if the notification is invalid. |
| 74 | func (p *Process) vmReadBytes(n *seccomp.Notif, ptr uintptr, maxSize int) ([]byte, syscall.Errno, error) { |
| 75 | if maxSize == 0 { |
| 76 | return []byte{}, 0, nil |
| 77 | } |
| 78 | if ptr == 0 { |
| 79 | return nil, unix.EINVAL, nil |
| 80 | } |
| 81 | |
| 82 | b := make([]byte, maxSize) |
| 83 | read, err := readMemory(int(p.PID), b, ptr) |
| 84 | if err != nil { |
| 85 | if !n.Valid() { |
| 86 | return nil, 0, seccomp.ErrCancelled |
| 87 | } |
| 88 | var errno syscall.Errno |
| 89 | if errors.As(err, &errno) { |
| 90 | return nil, errno, nil |
| 91 | } |
| 92 | return nil, 0, fmt.Errorf("memory read: unknown error: %w", err) |
| 93 | } |
| 94 | if !n.Valid() { |
| 95 | return nil, 0, seccomp.ErrCancelled |
| 96 | } |
| 97 | return b[:read], 0, nil |
| 98 | } |
| 99 | |
| 100 | // vmReadUint32 reads a uint32 from the process' memory starting at ptr. |
| 101 | func (p *Process) vmReadUint32(n *seccomp.Notif, ptr uintptr) (uint32, syscall.Errno, error) { |
no test coverage detected