0

For process_vm_readv the linux man page states:

[...] (Avoid) spanning memory pages (typically 4KiB) in a single remote iovec element. (Instead, split the remote read into two remote_iov elements and have them merge back into a single write local_iov entry. The first read entry goes up to the page boundary, while the second starts on the next page boundary.)

I get why this is a thing but I don't quite understand how I should work around it. Do I somehow need to find out where the page boundaries are? Or does the function figure this out on it's own as long as I provide 2 remote_iov elements? And if I read more than 4kiB and potentially cross 2 page boundaries do I need to split the remote element into 3 parts?

0

You should really read the whole paragraph -- that way of splitting the iovecs is not a hard requirement. It's only supposed to help in the case of a partial read, though it's not clear how it could help ;-)

That manpage is quite dubious and confusing; my testing shows that process_vm_readv() will always error out if the iov_start of the first iovec from the remote_iov list is not a valid address, but return a partial read if any of the pages spanned by iov_start + iov_len or the rest of the iovecs are not mapped in (which is expected and useful, but contradicts the emphasized parts below).

Note, however, that these system calls do not check the memory regions in the remote process until just before doing the read/write. Consequently, a partial read/write (see RETURN VALUE) may result if one of the remote_iov elements points to an invalid memory region in the remote process. No further reads/writes will be attempted beyond that point. Keep this in mind when attempting to read data of unknown length (such as C strings that are null-terminated) from a remote process, by avoiding spanning memory pages (typically 4KiB) in a single remote iovec element. (Instead, split the remote read into two remote_iov elements and have them merge back into a single write local_iov entry. The first read entry goes up to the page boundary, while the second starts on the next page boundary.)

[...]

This return value may be less than the total number of requested bytes, if a partial read/write occurred. (Partial transfers apply at the granularity of iovec elements. These system calls won't perform a partial transfer that splits a single iovec element.)

  • Thanks for clearing that up. Got quite confused by the manage. – HenrikS Feb 9 at 20:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.