1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
tlsf_add_pool(tlsf, (char*)mem + tlsf_size(), bytes - tlsf_size());
------------------------------------------------------------------------------------------------
static const size_t block_header_free_bit = 1 << 0; static const size_t block_header_prev_free_bit = 1 << 1;
------------------------------------------------------------------------------------------------
pool_t tlsf_add_pool(tlsf_t tlsf, void* mem, size_t bytes) { block_header_t* block; block_header_t* next;
const size_t pool_overhead = tlsf_pool_overhead(); const size_t pool_bytes = align_down(bytes - pool_overhead, ALIGN_SIZE);
if (((ptrdiff_t)mem % ALIGN_SIZE) != 0) { printf("tlsf_add_pool: Memory must be aligned by %u bytes.\n", (unsigned int)ALIGN_SIZE); return 0; }
if (pool_bytes < block_size_min || pool_bytes > block_size_max) { #if defined (TLSF_64BIT) printf("tlsf_add_pool: Memory size must be between 0x%x and 0x%x00 bytes.\n", (unsigned int)(pool_overhead + block_size_min), (unsigned int)((pool_overhead + block_size_max) / 256)); #else printf("tlsf_add_pool: Memory size must be between %u and %u bytes.\n", (unsigned int)(pool_overhead + block_size_min), (unsigned int)(pool_overhead + block_size_max)); #endif return 0; }
block = offset_to_block(mem, -(tlsfptr_t)block_header_overhead); block_set_size(block, pool_bytes); block_set_free(block); block_set_prev_used(block); block_insert(tlsf_cast(control_t*, tlsf), block);
next = block_link_next(block); block_set_size(next, 0); block_set_used(next); block_set_prev_free(next);
return mem; }
|