Lines Matching refs:heap

92 static buffer_alloc_ctx heap;  variable
118 memory_header *cur = heap.first; in debug_chain()
128 cur = heap.first_free; in debug_chain()
185 memory_header *prv = heap.first, *cur = heap.first->next; in verify_chain()
187 if( verify_header( heap.first ) != 0 ) in verify_chain()
196 if( heap.first->prev != NULL ) in verify_chain()
234 memory_header *new, *cur = heap.first_free; in buffer_alloc_calloc()
243 if( heap.buf == NULL || heap.first == NULL ) in buffer_alloc_calloc()
280 heap.alloc_count++; in buffer_alloc_calloc()
295 heap.first_free = cur->next_free; in buffer_alloc_calloc()
304 heap.total_used += cur->size; in buffer_alloc_calloc()
305 if( heap.total_used > heap.maximum_used ) in buffer_alloc_calloc()
306 heap.maximum_used = heap.total_used; in buffer_alloc_calloc()
314 if( ( heap.verify & MBEDTLS_MEMORY_VERIFY_ALLOC ) && verify_chain() != 0 ) in buffer_alloc_calloc()
347 heap.first_free = new; in buffer_alloc_calloc()
359 heap.header_count++; in buffer_alloc_calloc()
360 if( heap.header_count > heap.maximum_header_count ) in buffer_alloc_calloc()
361 heap.maximum_header_count = heap.header_count; in buffer_alloc_calloc()
362 heap.total_used += cur->size; in buffer_alloc_calloc()
363 if( heap.total_used > heap.maximum_used ) in buffer_alloc_calloc()
364 heap.maximum_used = heap.total_used; in buffer_alloc_calloc()
372 if( ( heap.verify & MBEDTLS_MEMORY_VERIFY_ALLOC ) && verify_chain() != 0 ) in buffer_alloc_calloc()
386 if( ptr == NULL || heap.buf == NULL || heap.first == NULL ) in buffer_alloc_free()
389 if( p < heap.buf || p > heap.buf + heap.len ) in buffer_alloc_free()
416 heap.free_count++; in buffer_alloc_free()
417 heap.total_used -= hdr->size; in buffer_alloc_free()
431 heap.header_count--; in buffer_alloc_free()
449 heap.header_count--; in buffer_alloc_free()
460 heap.first_free = hdr->next_free; in buffer_alloc_free()
472 heap.first_free = hdr; in buffer_alloc_free()
488 hdr->next_free = heap.first_free; in buffer_alloc_free()
489 if( heap.first_free != NULL ) in buffer_alloc_free()
490 heap.first_free->prev_free = hdr; in buffer_alloc_free()
491 heap.first_free = hdr; in buffer_alloc_free()
494 if( ( heap.verify & MBEDTLS_MEMORY_VERIFY_FREE ) && verify_chain() != 0 ) in buffer_alloc_free()
500 heap.verify = verify; in mbedtls_memory_buffer_set_verify()
514 heap.header_count, heap.total_used, in mbedtls_memory_buffer_alloc_status()
515 heap.maximum_header_count, heap.maximum_used, in mbedtls_memory_buffer_alloc_status()
516 heap.maximum_header_count * sizeof( memory_header ) in mbedtls_memory_buffer_alloc_status()
517 + heap.maximum_used, in mbedtls_memory_buffer_alloc_status()
518 heap.alloc_count, heap.free_count ); in mbedtls_memory_buffer_alloc_status()
520 if( heap.first->next == NULL ) in mbedtls_memory_buffer_alloc_status()
531 *max_used = heap.maximum_used; in mbedtls_memory_buffer_alloc_max_get()
532 *max_blocks = heap.maximum_header_count; in mbedtls_memory_buffer_alloc_max_get()
537 heap.maximum_used = 0; in mbedtls_memory_buffer_alloc_max_reset()
538 heap.maximum_header_count = 0; in mbedtls_memory_buffer_alloc_max_reset()
543 *cur_used = heap.total_used; in mbedtls_memory_buffer_alloc_cur_get()
544 *cur_blocks = heap.header_count; in mbedtls_memory_buffer_alloc_cur_get()
552 if( mbedtls_mutex_lock( &heap.mutex ) != 0 ) in buffer_alloc_calloc_mutexed()
555 if( mbedtls_mutex_unlock( &heap.mutex ) ) in buffer_alloc_calloc_mutexed()
564 if( mbedtls_mutex_lock( &heap.mutex ) ) in buffer_alloc_free_mutexed()
567 (void) mbedtls_mutex_unlock( &heap.mutex ); in buffer_alloc_free_mutexed()
573 memset( &heap, 0, sizeof(buffer_alloc_ctx) ); in mbedtls_memory_buffer_alloc_init()
577 mbedtls_mutex_init( &heap.mutex ); in mbedtls_memory_buffer_alloc_init()
593 heap.buf = buf; in mbedtls_memory_buffer_alloc_init()
594 heap.len = len; in mbedtls_memory_buffer_alloc_init()
596 heap.first = (memory_header *) buf; in mbedtls_memory_buffer_alloc_init()
597 heap.first->size = len - sizeof(memory_header); in mbedtls_memory_buffer_alloc_init()
598 heap.first->magic1 = MAGIC1; in mbedtls_memory_buffer_alloc_init()
599 heap.first->magic2 = MAGIC2; in mbedtls_memory_buffer_alloc_init()
600 heap.first_free = heap.first; in mbedtls_memory_buffer_alloc_init()
606 mbedtls_mutex_free( &heap.mutex ); in mbedtls_memory_buffer_alloc_free()
608 mbedtls_zeroize( &heap, sizeof(buffer_alloc_ctx) ); in mbedtls_memory_buffer_alloc_free()
627 heap.total_used != 0 || in check_all_free()
629 heap.first != heap.first_free || in check_all_free()
630 (void *) heap.first != (void *) heap.buf ) in check_all_free()
674 end = heap.buf + heap.len; in mbedtls_memory_buffer_alloc_self_test()
686 TEST_ASSERT( heap.buf + heap.len == end ); in mbedtls_memory_buffer_alloc_self_test()