heap_graft_to_top.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #include <assert.h>
  2. #include "private.h"
  3. /*--------------------------------------------------------- */
  4. void
  5. lub_heap_graft_to_top(lub_heap_t *this,
  6. lub_heap_block_t *free_block,
  7. void *ptr,
  8. words_t words,
  9. bool_t seg_end,
  10. bool_t other_free_block)
  11. {
  12. lub_heap_tag_t *tail;
  13. assert(1 == free_block->free.tag.free);
  14. /* remove the previous block from the free tree */
  15. lub_bintree_remove(&this->free_tree,free_block);
  16. if(BOOL_FALSE == other_free_block)
  17. {
  18. tail = lub_heap_block__get_tail(free_block);
  19. /*
  20. * taint the memory being given back
  21. * NB. we don't bother to taint all the memory if we are
  22. * combining two free blocks; they'll already be tainted.
  23. */
  24. lub_heap_taint_memory((char*)tail,
  25. LUB_HEAP_TAINT_FREE,
  26. (words << 2) + sizeof(lub_heap_tag_t));
  27. }
  28. else
  29. {
  30. char *tmp = ptr;
  31. /* clear out the freeblock details */
  32. lub_heap_taint_memory(tmp - sizeof(lub_heap_tag_t),
  33. LUB_HEAP_TAINT_FREE,
  34. sizeof(lub_heap_tag_t) + sizeof(lub_heap_free_block_t));
  35. }
  36. /* update the size of the previous block */
  37. free_block->free.tag.words += words;
  38. this->stats.free_bytes += (words << 2);
  39. /* make sure we retain the segment details */
  40. tail = lub_heap_block__get_tail(free_block);
  41. tail->segment = seg_end;
  42. tail->free = 1;
  43. /* update the size of the tail */
  44. tail->words = free_block->free.tag.words;
  45. /* insert back into the tree */
  46. lub_bintree_insert(&this->free_tree,free_block);
  47. }
  48. /*--------------------------------------------------------- */