1
0

heap_clean_stacks.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #include <string.h>
  2. #include <taskLib.h>
  3. #include "../private.h"
  4. #define MAX_TASKS 1024
  5. /*
  6. * We use global variables to avoid having anything from this
  7. * procedure on the stack as we are clearing it!!!
  8. * We are task locked so these shouldn't get corrupted
  9. */
  10. static int id_list[MAX_TASKS];
  11. static int i,num_tasks;
  12. static TASK_DESC info;
  13. static char *p;
  14. static unsigned delta;
  15. /*--------------------------------------------------------- */
  16. void
  17. lub_heap_clean_stacks(void)
  18. {
  19. /* disable task switching */
  20. taskLock();
  21. num_tasks = taskIdListGet(id_list,MAX_TASKS);
  22. /* deschedule to ensure that the current task stack details are upto date */
  23. taskDelay(1);
  24. /* iterate round the tasks in the system */
  25. for(i = 0;
  26. i < num_tasks;
  27. i++)
  28. {
  29. if(OK == taskInfoGet(id_list[i],&info))
  30. {
  31. p = info.td_pStackBase - info.td_stackHigh;
  32. delta = info.td_stackHigh - info.td_stackCurrent;
  33. /* now clean the stack */
  34. for(;
  35. delta--;
  36. p++)
  37. {
  38. *p = 0xCC;
  39. }
  40. }
  41. }
  42. /* reenable task switching */
  43. taskUnlock();
  44. }
  45. /*--------------------------------------------------------- */