From owner-freebsd-hackers@FreeBSD.ORG Tue Jun 11 05:45:52 2013 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 245A84FE for ; Tue, 11 Jun 2013 05:45:52 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) by mx1.freebsd.org (Postfix) with ESMTP id 909C91CA1 for ; Tue, 11 Jun 2013 05:45:51 +0000 (UTC) Received: from tom.home (kostik@localhost [127.0.0.1]) by kib.kiev.ua (8.14.7/8.14.7) with ESMTP id r5B5jiZe094767 for ; Tue, 11 Jun 2013 08:45:44 +0300 (EEST) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.8.3 kib.kiev.ua r5B5jiZe094767 Received: (from kostik@localhost) by tom.home (8.14.7/8.14.7/Submit) id r5B5jiPc094765 for freebsd-hackers@freebsd.org; Tue, 11 Jun 2013 08:45:44 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Tue, 11 Jun 2013 08:45:44 +0300 From: Konstantin Belousov To: FreeBSD hackers Mail List Subject: Re: Where is stack of program? Message-ID: <20130611054544.GI3047@kib.kiev.ua> References: <20130610164425.GA2966@vagner-wrk.bsdway.ru> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="Hb99djDM/33ECHXq" Content-Disposition: inline In-Reply-To: <20130610164425.GA2966@vagner-wrk.bsdway.ru> User-Agent: Mutt/1.5.21 (2010-09-15) X-Spam-Status: No, score=-2.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED autolearn=no version=3.3.2 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on tom.home X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.14 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 Jun 2013 05:45:52 -0000 --Hb99djDM/33ECHXq Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Mon, Jun 10, 2013 at 08:44:25PM +0400, Vagner wrote: > Hi! > I need method of finding in struct vm_map or vm_object segments of > memory which is situated in the stack. > Can you help me please? Note that the stack is per-thread. The concept is somewhat machine-specific, some architectures utilize two stacks, on some the stack is purely software convention. You did not specified what context your code is to be run, e.g. is it kernel or user space ? Assuming it is kernel since you mentioned vm_something. The least error prone route is the thread context (frame) -> tf_esp on i386 (or tf_rsp on amd64) -> lookup of the map entry in the process p_vmspace. In reality, the stack is often fragmented, since the stack grow code does not coalesce the adjacent grow-down map entries. --Hb99djDM/33ECHXq Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.20 (FreeBSD) iQIcBAEBAgAGBQJRtrmHAAoJEJDCuSvBvK1Bp2MP/RU9H5Tk8jOV7O7duw2OEVxV 9X2Hvt7KyhO0oqnbXEtjUhLIuhr6DnXNn8rG9amtW5asflPxKpGfm6SAJigMHJ6m e0u+vxoywiswcoDW9s01z3DWjdcLaHN70juYPYgO2RLNB2tni7S3rWxd4c3aJXbk o2Q4Mh8Pfiqu+Lql42MFUO8wxd2I1vmdMgceaP3+W6ydobcDjdtH/xIqjs745EI2 3DJQ8F1Nf9x8+42D0jkMZ9kfCxmI2fg7XLZmod2l6jUTvET6WivA08RDMPgjG3AT aj6TmgYELA+N78p3AYiuw+J/E7+RXfMN2myxRnLVytiWO2RKc8TxE48O+tOpre7H iWLhoTBZX8TKsbHpldV4DcVpedISBd0B3dadEhdUig4aaBIXaihrDaaM63nDGaho zjQMLkXWJf3nQ/H07hQlMq5YckNGTWzcmN/UwR+Z1o8dC7nID+S1y6iqRbk0imga WP7lYzhfXesEPpX53JcfYPrAmsTYu7/IxyMivo+xlJ5w28+FejoIk605hx2tORuR uIBSKONb5VwIcQr4m4aZ8GcrFxNdlDBUpaS4ow6qaMap9s6DRBItHjmiN80/n3be 7LQRuQscOE7mo03X8FAW6jmqES9wK9XVe6yvpCWU8ixmC+PfI78IqZxZzMUG37f7 RFAzyVQPUWFN5Kwhlnba =WvAu -----END PGP SIGNATURE----- --Hb99djDM/33ECHXq--