How can I find the address bounds of the call stack at runtime (via some symbol or register)? I’m using nm and readelf to pick through my symbols and I’m not finding one. In the case of registers, it seems I’m limited to the current frame’s base and stack pointers and not the starting address.
I’d like to shy away from answers that involve parsing /proc/pid/maps – I always feel awkward parsing text for a systems-related problem. I’m using g++ on Linux x86/x86_64.
EDIT: Can I use the x86 segment register SS to calculate it?
The
/proc/pid/mapsfile on Linux provides some information on a process’s memory mappings:The
pmap(1)command formats this information into a display that I find more pleasing:Incidentally, in the eglibc source file
dl-execstack.c, I found the following comment: There is no portable way to know the bounds of the initial thread’s stack so as tomprotectit. This probably means the best mechanism is to parse the/proc/pid/mapsfiles, even though I think we’re all agreed it is tacky.