From owner-freebsd-hackers@FreeBSD.ORG Tue May 11 19:50:13 2010 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 0D5841065686; Tue, 11 May 2010 19:50:13 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from mail.zoral.com.ua (mx0.zoral.com.ua [91.193.166.200]) by mx1.freebsd.org (Postfix) with ESMTP id 9889B8FC17; Tue, 11 May 2010 19:50:12 +0000 (UTC) Received: from deviant.kiev.zoral.com.ua (root@deviant.kiev.zoral.com.ua [10.1.1.148]) by mail.zoral.com.ua (8.14.2/8.14.2) with ESMTP id o4BJoMQE067293 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 11 May 2010 22:50:22 +0300 (EEST) (envelope-from kostikbel@gmail.com) Received: from deviant.kiev.zoral.com.ua (kostik@localhost [127.0.0.1]) by deviant.kiev.zoral.com.ua (8.14.4/8.14.4) with ESMTP id o4BJo9bA049265; Tue, 11 May 2010 22:50:09 +0300 (EEST) (envelope-from kostikbel@gmail.com) Received: (from kostik@localhost) by deviant.kiev.zoral.com.ua (8.14.4/8.14.4/Submit) id o4BJo8nL049264; Tue, 11 May 2010 22:50:08 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: deviant.kiev.zoral.com.ua: kostik set sender to kostikbel@gmail.com using -f Date: Tue, 11 May 2010 22:50:08 +0300 From: Kostik Belousov To: Robert Watson Message-ID: <20100511195008.GX83316@deviant.kiev.zoral.com.ua> References: <1127023465.20100510115708@serebryakov.spb.ru> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="MTFjS3R2zZZVGaSB" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.2.3i X-Virus-Scanned: clamav-milter 0.95.2 at skuns.kiev.zoral.com.ua X-Virus-Status: Clean X-Spam-Status: No, score=-2.4 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_50, DNS_FROM_OPENWHOIS autolearn=no version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on skuns.kiev.zoral.com.ua Cc: freebsd-hackers@freebsd.org, Lev Serebryakov Subject: Re: How to get stack bounds of current process? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 11 May 2010 19:50:13 -0000 --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--