Lines Matching refs:heap
68 static buffer_alloc_ctx heap; variable
95 memory_header *cur = heap.first; in debug_chain()
104 cur = heap.first_free; in debug_chain()
155 memory_header *prv = heap.first, *cur; in verify_chain()
165 if (heap.first->prev != NULL) { in verify_chain()
173 cur = heap.first->next; in verify_chain()
201 memory_header *new, *cur = heap.first_free; in buffer_alloc_calloc()
210 if (heap.buf == NULL || heap.first == NULL) { in buffer_alloc_calloc()
250 heap.alloc_count++; in buffer_alloc_calloc()
264 heap.first_free = cur->next_free; in buffer_alloc_calloc()
275 heap.total_used += cur->size; in buffer_alloc_calloc()
276 if (heap.total_used > heap.maximum_used) { in buffer_alloc_calloc()
277 heap.maximum_used = heap.total_used; in buffer_alloc_calloc()
286 if ((heap.verify & MBEDTLS_MEMORY_VERIFY_ALLOC) && verify_chain() != 0) { in buffer_alloc_calloc()
321 heap.first_free = new; in buffer_alloc_calloc()
335 heap.header_count++; in buffer_alloc_calloc()
336 if (heap.header_count > heap.maximum_header_count) { in buffer_alloc_calloc()
337 heap.maximum_header_count = heap.header_count; in buffer_alloc_calloc()
339 heap.total_used += cur->size; in buffer_alloc_calloc()
340 if (heap.total_used > heap.maximum_used) { in buffer_alloc_calloc()
341 heap.maximum_used = heap.total_used; in buffer_alloc_calloc()
350 if ((heap.verify & MBEDTLS_MEMORY_VERIFY_ALLOC) && verify_chain() != 0) { in buffer_alloc_calloc()
365 if (ptr == NULL || heap.buf == NULL || heap.first == NULL) { in buffer_alloc_free()
369 if (p < heap.buf || p >= heap.buf + heap.len) { in buffer_alloc_free()
395 heap.free_count++; in buffer_alloc_free()
396 heap.total_used -= hdr->size; in buffer_alloc_free()
409 heap.header_count--; in buffer_alloc_free()
427 heap.header_count--; in buffer_alloc_free()
437 heap.first_free = hdr->next_free; in buffer_alloc_free()
451 heap.first_free = hdr; in buffer_alloc_free()
469 hdr->next_free = heap.first_free; in buffer_alloc_free()
470 if (heap.first_free != NULL) { in buffer_alloc_free()
471 heap.first_free->prev_free = hdr; in buffer_alloc_free()
473 heap.first_free = hdr; in buffer_alloc_free()
476 if ((heap.verify & MBEDTLS_MEMORY_VERIFY_FREE) && verify_chain() != 0) { in buffer_alloc_free()
483 heap.verify = verify; in mbedtls_memory_buffer_set_verify()
497 heap.header_count, heap.total_used, in mbedtls_memory_buffer_alloc_status()
498 heap.maximum_header_count, heap.maximum_used, in mbedtls_memory_buffer_alloc_status()
499 heap.maximum_header_count * sizeof(memory_header) in mbedtls_memory_buffer_alloc_status()
500 + heap.maximum_used, in mbedtls_memory_buffer_alloc_status()
501 heap.alloc_count, heap.free_count); in mbedtls_memory_buffer_alloc_status()
503 if (heap.first->next == NULL) { in mbedtls_memory_buffer_alloc_status()
513 *alloc_count = heap.alloc_count; in mbedtls_memory_buffer_alloc_count_get()
514 *free_count = heap.free_count; in mbedtls_memory_buffer_alloc_count_get()
519 *max_used = heap.maximum_used; in mbedtls_memory_buffer_alloc_max_get()
520 *max_blocks = heap.maximum_header_count; in mbedtls_memory_buffer_alloc_max_get()
525 heap.maximum_used = 0; in mbedtls_memory_buffer_alloc_max_reset()
526 heap.maximum_header_count = 0; in mbedtls_memory_buffer_alloc_max_reset()
531 *cur_used = heap.total_used; in mbedtls_memory_buffer_alloc_cur_get()
532 *cur_blocks = heap.header_count; in mbedtls_memory_buffer_alloc_cur_get()
540 if (mbedtls_mutex_lock(&heap.mutex) != 0) { in buffer_alloc_calloc_mutexed()
544 if (mbedtls_mutex_unlock(&heap.mutex)) { in buffer_alloc_calloc_mutexed()
554 if (mbedtls_mutex_lock(&heap.mutex)) { in buffer_alloc_free_mutexed()
558 (void) mbedtls_mutex_unlock(&heap.mutex); in buffer_alloc_free_mutexed()
564 memset(&heap, 0, sizeof(buffer_alloc_ctx)); in mbedtls_memory_buffer_alloc_init()
567 mbedtls_mutex_init(&heap.mutex); in mbedtls_memory_buffer_alloc_init()
586 heap.buf = buf; in mbedtls_memory_buffer_alloc_init()
587 heap.len = len; in mbedtls_memory_buffer_alloc_init()
589 heap.first = (memory_header *) buf; in mbedtls_memory_buffer_alloc_init()
590 heap.first->size = len - sizeof(memory_header); in mbedtls_memory_buffer_alloc_init()
591 heap.first->magic1 = MAGIC1; in mbedtls_memory_buffer_alloc_init()
592 heap.first->magic2 = MAGIC2; in mbedtls_memory_buffer_alloc_init()
593 heap.first_free = heap.first; in mbedtls_memory_buffer_alloc_init()
599 mbedtls_mutex_free(&heap.mutex); in mbedtls_memory_buffer_alloc_free()
601 mbedtls_platform_zeroize(&heap, sizeof(buffer_alloc_ctx)); in mbedtls_memory_buffer_alloc_free()
622 heap.total_used != 0 || in check_all_free()
624 heap.first != heap.first_free || in check_all_free()
625 (void *) heap.first != (void *) heap.buf) { in check_all_free()
669 end = heap.buf + heap.len; in mbedtls_memory_buffer_alloc_self_test()
683 TEST_ASSERT(heap.buf + heap.len == end); in mbedtls_memory_buffer_alloc_self_test()