How to get stack bounds of current process?

Kostik Belousov kostikbel at gmail.com
Tue May 11 19:50:13 UTC 2010


On Tue, May 11, 2010 at 08:23:41PM +0100, Robert Watson wrote:
> 
> On Mon, 10 May 2010, Lev Serebryakov wrote:
> 
> > I'm proting some application from Linux, which discover its stack bounds 
> > by reading and pasing "/proc/self/maps".  FreeBSD have 
> >"/prov/curproc/map", but I can not find how to determine which record is 
> >for stack (I've looked into implementation of proc_fs, but it doesn't 
> >contain any specail processing for process stack).
> >
> > How could I determine stack bounds of current process on FreeBSD 7/8/9?
> 
> The "procstat -v" command in 8.x and 9.x will give this information based 
> on sysctls; we're about to integrate a libprocstat(3) library which will 
> provide a public API for this information.  I'd agree with Kostik that you 
> should think carefully about whether the application really needs this 
> information :-).

Unfortunately, it is not that simple. How to guess which vm_map_entries
are from the stack ? To complicate the issue, the stack is usually
fragmented, i.e. continuous VA area is covered by several adjanced
entries.

The answer "look at the kern.ps_strings" is bad as well, since it
gives wrong answer e.g. for ia32 binary on amd64.

Idea to look at the highest mapped address and then descend might
be safest, but as I already pointed out, libthr.so clamps the
main stack to keep its size the same as for non-main threads.

And this is ignoring issues of non-main thread stacks, as well as
signal altstacks.

As I said, there is no good answer to the question, and better strategy
is to understand why application need this.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-hackers/attachments/20100511/a83b91f4/attachment.pgp


More information about the freebsd-hackers mailing list