STKTEST.C
资源名称:ertos.rar [点击查看]
上传用户:sunrenlu
上传日期:2022-06-13
资源大小:1419k
文件大小:1k
源码类别:
操作系统开发
开发平台:
DOS
- #include <stdio.h>
- #include <rtos.h>
- /*
- * Demonstrate's eRTOS ability to catch stack overflow in child threads.
- * We will recursively call demo() until it crashes
- * In normal cases, will detect overwriting of SS:0 and SP wraparound
- */
- /*********************************************************/
- void demo(void)
- {
- cprintf("r Current SS:SP : %04x:%04x Stack Used : %04x ", _SS, _SP, rt_stackused( NULL ) );
- rt_sleep(1);
- demo();
- }
- /*********************************************************/
- void test(DWORD arg)
- {
- cprintf("r Starting SS:SP : %04x:%04xrn ", _SS, _SP );
- cprintf("with stack length %04x rn", kcurthread->th_stacklen );
- demo();
- }
- /*********************************************************/
- main()
- {
- int i;
- // changing the next line would all that is needed to make this
- // a pre-emptive multithreaded application
- kdebug = 1;
- rt_init(100);
- kcheckstacksig = 0; /* turn off SP:00 testing, or else we will get *
- * stack signature error. */
- cputs("demonstrate stack overflow...rn");
- rt_timerfreq( 100 );
- rt_newthread( test, 1,4096, 0, "worker 1" );
- for ( i = 0 ; i < 1000 ; ++i ) {
- rt_sleep( 10 );
- }
- }