Speaking of which, I don't believe msync() fails on non-readable
memory (PROT_NONE), so it isn't a perfectly reliable way of verifying
whether an address can be read from without segfaulting. In another
stack trace application, we had to abandon msync() for this purpose
and use pread() from /proc/self/mem instead - more expensive, but safer.
I think of msync as a filter for bogus addresses, not a reliable guarantee. The way libunwind is being used now (always on heap profiling), any slowdown would cause people to compile code with frame pointers and use a simpler unwinder.
If there is a way to check if a given virtual address is a known good stack address, we could use that. But unfortunately there is no portable way of doing that.
-Arun