更换语言:
   Contact us
  • Follow CooCox
  •         
  • CooCox Market
  •         
  • Tech Support
  •     
Home  ›  CoOS › Memory Management

Stack Overflow Check

     Stack Overflow refers to that the size of the stack used when a task is running exceeds the size that assigned to the task, which results in writing data to the memory outside the stack. This may lead to the coverage of the system or other tasks’ data as well as the exception of memory access. The stack size assigned to each task is fixed in multi-tasking kernel. Once the stack overflow is not handled when the system is running, it may lead to system crashes.

     When creating a task in CooCox CoOS, the system will save the stack bottom address in the task control block and write a special value into the memory block of the stack bottom address in order to judge whether the stack overflows. CooCox CoOS will check whether there is a stack overflow during each task scheduling.

Code 8 Stack overflow inspection
  • if((pCurTcb->stkPtr < pCurTcb->stack)||(*(U32*)(pCurTcb->stack) != MAGIC_WORD))      
    {                                                            
           CoStkOverflowHook(pCurTcb->taskID);         /* Yes,call hander */     
    }


     When stack overflow in a task, the system will call CoStkOverflowHook (taskID) automatically. You can add the handling of stack overflow in the function. The parameter of this function is the ID of the task which has stack overflow.

Code 9 The handling function of stack overflow
  • void CoStkOverflowHook(OS_TID taskID)
    {
        /* Process stack overflow in here */
        for(; ;)
        {
            …
        }
    }



CooCox CoOS

© 2009 -2011 CooCox - Terms of Use         Business Model         Market             About us             Terms and Conditions