1
0

heap_tainted_memory.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #include "string.h"
  2. #include "private.h"
  3. #include "context.h"
  4. /* flag to indicate whether to taint memory or not */
  5. static bool_t tainted = BOOL_FALSE;
  6. /*--------------------------------------------------------- */
  7. bool_t
  8. lub_heap_taint(bool_t enable)
  9. {
  10. bool_t result = tainted;
  11. tainted = enable;
  12. return result;
  13. }
  14. /*--------------------------------------------------------- */
  15. bool_t
  16. lub_heap_is_tainting(void)
  17. {
  18. return tainted;
  19. }
  20. /*--------------------------------------------------------- */
  21. void
  22. lub_heap_taint_memory(char *ptr,
  23. lub_heap_taint_t type,
  24. size_t size)
  25. {
  26. if(BOOL_TRUE == tainted)
  27. {
  28. #ifdef __vxworks
  29. extern function_t taskDestroy; /* fiddle a reference to the function ...*/
  30. extern function_t taskSuspend; /* ...and the next function in the library */
  31. /*
  32. * VxWorks taskDestroy() relies on being able to access
  33. * free memory.
  34. * It calls objFree() followed by objTerminate() !!!!
  35. * So we have to perform a crufty hack to avoid this
  36. * mistake blowing us out of the water...
  37. */
  38. if(LUB_HEAP_TAINT_FREE == type)
  39. {
  40. int i;
  41. /* obtain the backtrace of the stack */
  42. stackframe_t frame;
  43. lub_heap__get_stackframe(&frame,10);
  44. for(i = 0; i < 10; i++)
  45. {
  46. function_t *address = frame.backtrace[i];
  47. if((address > &taskDestroy) && (address < &taskSuspend))
  48. {
  49. return;
  50. }
  51. }
  52. }
  53. #endif /* __vxworks */
  54. /* taint the memory */
  55. memset(ptr,type,size);
  56. }
  57. }
  58. /*--------------------------------------------------------- */