public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* How to get current stack size ?
@ 2003-02-20  2:05 Igor Bukanov
  2003-02-20  8:59 ` Fergus Henderson
  0 siblings, 1 reply; 2+ messages in thread
From: Igor Bukanov @ 2003-02-20  2:05 UTC (permalink / raw)
  To: gcc

Hi!

Is there any internal function in GCC that I can use to determine 
currently consumed stack space? Or I should better ask glibc guys about it?

I would like to prevent too deep recursion in a recursive descent parser 
which parse external data and limiting amount of stack space that can be 
consumed during recursion seems to be a simple solution. Initially I 
thought to use something like the following scheme which calculates 
address differences:

char* stack_mark;

void parse() {
	char dummy;
	stack_mark = &dummy;
	...
	recursively_called_function();
	
	....

}

void recursively_called_function() {
	char dummy;
	ptrdiff_t consumed_stack_size = &dummy - stack_mark;
	if (consumed_stack_size > STACK_LIMIT
	    || -consumed_stack_size > STACK_LIMIT)
	{
		report_error();
	}
	...
}

The trouble is that parse() can be called from some other libraries that 
may also be under deep recursion and checking against stack size 
consumed during parse may miss stack overflow. So I need absolute value 
for the stack size.

Thanks in advance, Igor Bukanov


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: How to get current stack size ?
  2003-02-20  2:05 How to get current stack size ? Igor Bukanov
@ 2003-02-20  8:59 ` Fergus Henderson
  0 siblings, 0 replies; 2+ messages in thread
From: Fergus Henderson @ 2003-02-20  8:59 UTC (permalink / raw)
  To: Igor Bukanov; +Cc: gcc

On 20-Feb-2003, Igor Bukanov <igor@icesoft.no> wrote:
> Is there any internal function in GCC that I can use to determine 
> currently consumed stack space? Or I should better ask glibc guys about it?

This sounds more like a glibc issue.  Try getrusage() -- the "ru_isrss"
member of "struct rusage" reports "integral unshared stack size",
which sounds like it should do what you want (although I have not tested it).

Alternatively, look at the code for GC_get_stack_base() in the Boehm
conservative collector (which is included in the GCC sources).

-- 
Fergus Henderson <fjh@cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2003-02-20  7:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-02-20  2:05 How to get current stack size ? Igor Bukanov
2003-02-20  8:59 ` Fergus Henderson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).