123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- #include <assert.h>
- #include "private.h"
- void *lub_heap_slice_from_bottom(lub_heap_t * this,
- lub_heap_free_block_t ** ptr_block,
- words_t * words, bool_t seg_start)
- {
- void *result = NULL;
- lub_heap_free_block_t *block = *ptr_block;
-
- assert(1 == block->tag.free);
- if (BOOL_TRUE == lub_heap_block_check((lub_heap_block_t *) block)
- && (*words <= block->tag.words)) {
- words_t new_words = (block->tag.words - *words);
-
- lub_heap_tag_t *tail =
- lub_heap_block__get_tail((lub_heap_block_t *) block);
-
- if (new_words > (sizeof(lub_heap_free_block_t) >> 2)) {
- lub_heap_free_block_t *new_block;
-
- tail->words -= *words;
-
- new_block =
- (lub_heap_free_block_t *) (&block->tag + *words);
- new_block->tag.segment = seg_start;
- new_block->tag.free = 1;
- new_block->tag.words = tail->words;
-
- this->stats.free_bytes -= (*words << 2);
-
- lub_bintree_node_init(&new_block->bt_node);
- result = block;
- *ptr_block = new_block;
- } else {
-
- --this->stats.free_blocks;
- this->stats.free_bytes -= (block->tag.words << 2);
- this->stats.free_bytes +=
- sizeof(lub_heap_alloc_block_t);
- this->stats.free_overhead -=
- sizeof(lub_heap_alloc_block_t);
-
- *words = block->tag.words;
-
- result = block;
- *ptr_block = NULL;
- }
- if (NULL != result) {
-
- lub_heap_taint_memory(result, LUB_HEAP_TAINT_ALLOC,
- (*words << 2));
- }
- }
- return result;
- }
|