Message-Id: <199704142208.SAA19546@delorie.com> From: Oberhumer Markus Subject: Re: stackavail() ? To: fighteer AT cs DOT com Date: Tue, 15 Apr 1997 00:03:27 +0200 (METDST) Cc: sandmann AT clio DOT rice DOT edu (Charles W. Sandmann), djgpp-workers AT delorie DOT com (djgpp-workers) In-Reply-To: <334CEC36.76D9@cs.com> from "John M. Aldrich" at Apr 10, 97 06:33:42 am Return-Read-To: markus DOT oberhumer AT jk DOT uni-linz DOT ac DOT at Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Content-Length: 698 Thanks for your feedback. After investigating src/libc/crt0/crt0.s I've come to the following solution which works fine on my machine. It looks pretty simple, though, so is there something I might have missed ? /* make return value signed, just in case we already overflowed the stack */ extern __inline__ int _stackavail(void) { extern unsigned __djgpp_stack_limit; unsigned sp; __asm__ __volatile__ ("movl %%esp,%k0\n" : "=r" (sp) : ); return sp - __djgpp_stack_limit; } #ifdef TEST /* compile with 'gcc -Wall -O2' */ #include #include extern int _stklen; int main() { printf("stack: %d total, %d available\n", _stklen, _stackavail()); return 0; } #endif