heap_clean_stacks.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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 lub_heap_clean_stacks(void)
  17. {
  18. /* disable task switching */
  19. taskLock();
  20. num_tasks = taskIdListGet(id_list, MAX_TASKS);
  21. /* deschedule to ensure that the current task stack details are upto date */
  22. taskDelay(1);
  23. /* iterate round the tasks in the system */
  24. for (i = 0; i < num_tasks; i++) {
  25. if (OK == taskInfoGet(id_list[i], &info)) {
  26. p = info.td_pStackBase - info.td_stackHigh;
  27. delta = info.td_stackHigh - info.td_stackCurrent;
  28. /* now clean the stack */
  29. for (; delta--; p++) {
  30. *p = 0xCC;
  31. }
  32. }
  33. }
  34. /* reenable task switching */
  35. taskUnlock();
  36. }
  37. /*--------------------------------------------------------- */