1
0

heap_graft_to_bottom.c 1.9 KB

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