delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/1997/04/14/18:12:57

Message-Id: <199704142208.SAA19546@delorie.com>
From: Oberhumer Markus <k3040e4 AT c210 DOT edvz DOT uni-linz DOT ac DOT at>
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

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 <stdio.h>
#include <stdlib.h>
extern int _stklen;

int main()
{
  printf("stack: %d total, %d available\n", _stklen, _stackavail());
  return 0;
}
#endif



- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019