_task_restart() frees and corrupts stack

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

_task_restart() frees and corrupts stack

Jump to solution
853 Views
kkramb
Contributor II

I'm using MQX 3.8 with Code Warrior 10.2 for a ColdFire MCF52258 project.

 

The MQX documentation says that _task_restart() is suppossed to restart the specified task with the same stack.  In my application, _task_restart() causes the specified task's stack to be freed.  The task does restart using a stack area near, but no exactly in the original location.  And since the memory is free it eventually gets allocated to other purposes, which causes the task's stack to become corrupted.

 

I have started to dig into the MQX code.  The _task_restart_func() routine seems to intentionally free the task's stack.  Then it attempts to rebuild the stack.  But it seems to calculate a size and location that is slightly different from the original.  And I don't see yet where it actually attempts to reallocate the memory.

 

Is this a problem with MQX or may I have done something wrong at a higher level?  If it's a problem with MQX has anyone already developed a fix?

 

Thanks,

 -- Kevin

 

0 Kudos
1 Solution
483 Views
kkramb
Contributor II

I've figured out my problem with _task_restart().  I was using MXQ v3.8 beta 2 and this was a bug in the beta.  But it has been fixed in the official release of MXQ v3.8.  Since upgrading MXQ to the official release, _task_restart() now calculates the correct size and location of the stack and it does not free the stack*.

 

* MQX_ALLOW_TYPED_MEMORY and MQX_CHECK_MEMORY_ALLOCATION_ERRORS must be defined as 1 in order for _task_restart() to handle the stack correctly.  This is the default behavior in mqx_cnfg.h but if you define either as 0 in your user_config.h then _task_restart() will free the stack, which will lead to eventual stack corruption.

 

View solution in original post

0 Kudos
2 Replies
484 Views
kkramb
Contributor II

I've figured out my problem with _task_restart().  I was using MXQ v3.8 beta 2 and this was a bug in the beta.  But it has been fixed in the official release of MXQ v3.8.  Since upgrading MXQ to the official release, _task_restart() now calculates the correct size and location of the stack and it does not free the stack*.

 

* MQX_ALLOW_TYPED_MEMORY and MQX_CHECK_MEMORY_ALLOCATION_ERRORS must be defined as 1 in order for _task_restart() to handle the stack correctly.  This is the default behavior in mqx_cnfg.h but if you define either as 0 in your user_config.h then _task_restart() will free the stack, which will lead to eventual stack corruption.

 

0 Kudos
483 Views
c0170
Senior Contributor III

Hi ÂµManaged,

 

thanks for providing an explanation how you solved the problem, it might help others !

 

Regards,

MartinK

0 Kudos