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
--MTFjS3R2zZZVGaSB Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, May 11, 2010 at 08:23:41PM +0100, Robert Watson wrote: >=20 > On Mon, 10 May 2010, Lev Serebryakov wrote: >=20 > > I'm proting some application from Linux, which discover its stack bound= s=20 > > by reading and pasing "/proc/self/maps". FreeBSD have=20 > >"/prov/curproc/map", but I can not find how to determine which record is= =20 > >for stack (I've looked into implementation of proc_fs, but it doesn't=20 > >contain any specail processing for process stack). > > > > How could I determine stack bounds of current process on FreeBSD 7/8/9? >=20 > The "procstat -v" command in 8.x and 9.x will give this information based= =20 > on sysctls; we're about to integrate a libprocstat(3) library which will= =20 > provide a public API for this information. I'd agree with Kostik that yo= u=20 > should think carefully about whether the application really needs this=20 > 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. --MTFjS3R2zZZVGaSB Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (FreeBSD) iEYEARECAAYFAkvptPAACgkQC3+MBN1Mb4hMcgCgwPxd4vHdSAxUA0Pp2viMVTDv U0MAoJ4u91c1JUUsNh1/NGV0pJ4CaKiH =Gomc -----END PGP SIGNATURE----- --MTFjS3R2zZZVGaSB--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20100511195008.GX83316>