Category : Files from Magazines
Archive   : CGAZV4N2.ZIP
Filename : BLOWSTK.C

 
Output of file : BLOWSTK.C contained in archive : CGAZV4N2.ZIP
/**********************************************************************
* blowstk.c - demonstrate stack overflow checking
*
* Author: John Rex
* Date: July, 1989
* Compilers: Turbo C 2.0, MSC 5.1
* Memory model: any
* Compile time switches:
* SAFETY_MARGIN - minimum number of bytes that we are willing to
* leave free on the stack for system interrupts,
* calls to error handling routines, etc.
*
* Usage: Just compile and invoke. It runs a recursive routine to blow
* the stack. The number of successful calls is reported.
*
* Sources: This code was derived from study of the Turbo C and Microsoft
* C run-time libraries and startup code.
*
* Source code and object code may be used freely.
********************************************************************/

#define SAFETY_MARGIN 500

#if defined(__TURBOC__)
#if defined(__SMALL__) || defined(__MEDIUM__) || defined(__TINY__)
#define TURBOSMALL
#else
#define TURBOLARGE
#endif
#else
#define MSC
#endif

int count; /* set to max # of calls we were able to make */

void blowstack(int i)
{
/* stack check protocols */

#if defined(TURBOSMALL)
extern unsigned __brklvl;

if (_SP < (__brklvl + SAFETY_MARGIN)) { /* true if blown */
count = i;
return;
}
#endif

#if defined(TURBOLARGE)
if (_SP < SAFETY_MARGIN) { /* true if blown */
count = i;
return;
}
#endif

#if defined(MSC)
unsigned getsp();
extern int end;

if ( getsp() < (((unsigned) &end) + SAFETY_MARGIN)) { /* true if blown */
count = i;
return;
}
#endif

/* otherwise, recurse! */
blowstack(i+1);
}

#include
void main()
{
blowstack(1);
printf("Blowstack() made %d calls\n", count);
}


  3 Responses to “Category : Files from Magazines
Archive   : CGAZV4N2.ZIP
Filename : BLOWSTK.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/