Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 11 May 2010 22:50:08 +0300
From:      Kostik Belousov <kostikbel@gmail.com>
To:        Robert Watson <rwatson@freebsd.org>
Cc:        freebsd-hackers@freebsd.org, Lev Serebryakov <lev@freebsd.org>
Subject:   Re: How to get stack bounds of current process?
Message-ID:  <20100511195008.GX83316@deviant.kiev.zoral.com.ua>
In-Reply-To: <alpine.BSF.2.00.1005112022090.91621@fledge.watson.org>
References:  <1127023465.20100510115708@serebryakov.spb.ru> <alpine.BSF.2.00.1005112022090.91621@fledge.watson.org>

next in thread | previous in thread | raw e-mail | index | archive | help

[-- Attachment #1 --]
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.

[-- Attachment #2 --]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (FreeBSD)

iEYEARECAAYFAkvptPAACgkQC3+MBN1Mb4hMcgCgwPxd4vHdSAxUA0Pp2viMVTDv
U0MAoJ4u91c1JUUsNh1/NGV0pJ4CaKiH
=Gomc
-----END PGP SIGNATURE-----

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20100511195008.GX83316>