#include <stdio.h>
#include <rtos.h>
#include <conio.h>

/*
 * Demonstrate buffer overrun detection
 */


#if defined(__TURBOC__) || defined(__BORLANDC__)
#define STACKLEN 2048
#else
#define STACKLEN 4096
#endif


/*********************************************************/
void test(DWORD arg)
{
    char *p;

#define TESTSIZE 512
    p = kcalloc( TESTSIZE, 1 );
    if ( p != NULL ) {
        memset( p, 0, TESTSIZE + 1 );
        kfree( p );
    }
}

/*********************************************************/

int main(int argc, char **argv)
{
    int i;

    // changing the next line would all that is needed to make this
    // a pre-emptive multithreaded application

    kpreemptive = 0;
    kdebug = 1;
    rt_init(100);
    kwindow( 1, 6, 80, 16 );
    cputs("Will demonstrate capturing a buffer overrun\r\n");
    cputs("starting...\r\n");

    rt_newthread( test,  1,4096, 0, "worker 1" );

    for ( i = 0 ; i < 1000 ; ++i ) {
        rt_sleep( 10 );
        cprintf("in main %i\n\r", i);
    }
}

