This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

stack overflow

Other Parts Discussed in Thread: SYSBIOS

Hi,

I am looking for an example on how to detect the stack overflow with sysBios6. I would like to do this in real-time. I read in the sysBios user guide that task overflow check happens during task switch. I already have a hook in my code for task switch as shown below.

Void switchFxn(Task_Handle prev, Task_Handle next)

{

...

}

So, whenever a task switch happens, the above function switchFxn() will be called.

Here is my question:

Within switchFxn() function, what parameter or what function I need to check for getting information about stack overflow?

 

Thanks,

Rahul

 

 

  • Hi Rahul,

    Are you asking how to add your own task stack overflow check while switching context between tasks?  By default, BIOS already checks the task stacks when task switches occur.  If a stack overflow is detected, an error is raised.  You can refer to the cdoc for this error for more information.  Are you trying to augment this functionality in some way?

    Regards,

    Shreyas

  •  

    Hi Shreyas,

     

    Thank you for your reply. I am not planning to add my own task stack overflow check. Since, BIOS checks task stacks when task switch occurs by default, I am ok with that. But, I want to find a way to read the status/output of BIOS stackoverflow check. My real-time application does not print sysBIOS messages/errors. So, I want to pass the stackoverflow check function output to my own print function in my application.

     

    Thanks,

    Rahul

     

  • OK.   Since the task stack is an internal resource belonging to the Task instance, you wouldn't be able to use any documented API for checking the task stack yourself.  You would have to.  You could check out the existing Task_checkStacks() implementation in packages/ti/sysbios/knl/Task.c:

    You could theoretically replace the Error_raise's with your own error handler.  Task_SupportProxy_checkStack is an internal API so you would need to #define ti_sysbios_knl_Task__internalaccess before using <ti/sysbios/knl/Task.h> to use it.

    /*
     *  ======== Task_checkStacks ========
     */
    Void Task_checkStacks(Task_Handle oldTask, Task_Handle newTask)
    {
        /*
         * oldTask is NULL for the very first stack switch, skip it
         */
        if (oldTask == NULL) {
        return;
        }

        /* check top of stacks for 0xbe */
        if (!Task_SupportProxy_checkStack(oldTask->stack, oldTask->stackSize)) {
        Error_raise(NULL, Task_E_stackOverflow, oldTask, 0);
        }

        if (!Task_SupportProxy_checkStack(newTask->stack, newTask->stackSize)) {
        Error_raise(NULL, Task_E_stackOverflow, newTask, 0);
        }

        /* check sp's for being in bounds */
        if ((oldTask->context < (Ptr)oldTask->stack) ||
            (oldTask->context > (Ptr)(oldTask->stack+oldTask->stackSize))) {
        Error_raise(NULL, Task_E_spOutOfBounds, oldTask, oldTask->context);
        }

        if ((newTask->context < (Ptr)newTask->stack) ||
            (newTask->context > (Ptr)(newTask->stack+newTask->stackSize))) {
        Error_raise(NULL, Task_E_spOutOfBounds, newTask, newTask->context);
        }
    }