Fix for Linux Sparc where heap addresses have their MSB set, a case that pread() can't handle.
Indeed Linux's pread() implementation has a limitation: it treats the offset argument as a signed offset, hence it can't access the top half of the memory space.
And on Sparc, heap addresses have their MSB set, for example:
So the problem with bootchart-collector using pread() to read from /dev/{pid}/mem becomes obvious: the first call to pread() successfully reads from the stack, but subsequent calls fail reading from the heap and return EINVAL.
The fix is to replace the call to pread() by two system calls: lseek() which can handle unsigned offsets and then read(). There is no real performance degradation and it is portable.
Fix for Linux Sparc where heap addresses have their MSB set, a case that
pread()
can't handle.Indeed Linux's
pread()
implementation has a limitation: it treats the offset argument as a signed offset, hence it can't access the top half of the memory space. And on Sparc, heap addresses have their MSB set, for example:So the problem with bootchart-collector using
pread()
to read from/dev/{pid}/mem
becomes obvious: the first call topread()
successfully reads from the stack, but subsequent calls fail reading from the heap and returnEINVAL
. The fix is to replace the call topread()
by two system calls:lseek()
which can handle unsigned offsets and thenread()
. There is no real performance degradation and it is portable.