From owner-freebsd-current@FreeBSD.ORG Wed Nov 29 23:24:12 2006 Return-Path: X-Original-To: freebsd-current@freebsd.org Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id A6A3716A412 for ; Wed, 29 Nov 2006 23:24:12 +0000 (UTC) (envelope-from cswiger@mac.com) Received: from smtpout.mac.com (smtpout.mac.com [17.250.248.184]) by mx1.FreeBSD.org (Postfix) with ESMTP id 264BC43C9D for ; Wed, 29 Nov 2006 23:24:08 +0000 (GMT) (envelope-from cswiger@mac.com) Received: from mac.com (smtpin05-en2 [10.13.10.150]) by smtpout.mac.com (Xserve/8.12.11/smtpout14/MantshX 4.0) with ESMTP id kATNO7FW010768; Wed, 29 Nov 2006 15:24:07 -0800 (PST) Received: from [17.214.13.96] (a17-214-13-96.apple.com [17.214.13.96]) (authenticated bits=0) by mac.com (Xserve/smtpin05/MantshX 4.0) with ESMTP id kATNO42C010603; Wed, 29 Nov 2006 15:24:05 -0800 (PST) In-Reply-To: <456E0EDA.60603@samsco.org> References: <45622068.2050705@student.tue.nl> <200611291204.03716.jhb@freebsd.org> <20061129223221.GA359@what-creek.com> <456E0C66.4060404@samsco.org> <20061129225025.GA584@what-creek.com> <456E0EDA.60603@samsco.org> Mime-Version: 1.0 (Apple Message framework v752.2) Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Message-Id: <56E4A436-FE9E-4247-90B3-42FF6A23FEDC@mac.com> Content-Transfer-Encoding: 7bit From: Chuck Swiger Date: Wed, 29 Nov 2006 15:24:03 -0800 To: Scott Long X-Mailer: Apple Mail (2.752.2) X-Brightmail-Tracker: AAAAAA== X-Brightmail-scanned: yes Cc: freebsd-current@freebsd.org, John Birrell Subject: Re: calcru-triggered panic? X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 29 Nov 2006 23:24:12 -0000 On Nov 29, 2006, at 2:51 PM, Scott Long wrote: >> Is it possible to check how deep the stack is and avoid using a stack >> buffer if too deep? >> -- >> John Birrell > > I don't know how to do it in a platform-independent way. For i386, > I'd check %esp and see if it's getting close to a 2x page boundary. You should be able to take the address of an automatic variable which gets allocated on the stack...? #include int main(int argc, char *argv[]) { volatile int stack_location; printf("stack is at: %0p\n", &stack_location); } On a few platforms [1], they have a set of registers dedicated as temps which might be used instead of the stack, although taking the address of the variable should be enough to prevent the compiler from allocating it in a register. But using "volatile" will keep the compiler from doing anything fancy with it. -- -Chuck [1]: The HP/PA and SPARC's register windows, for example. But quick testing suggests that the above finds the stack on x86, SPARC, and PPC hardware, although I'm obviously testing userland code rather than running it inside a kernel module. :-)