memory_buffer_alloc.h
mbedtls/build_info.h
stddef.h
mbedtls/build_info.h
mbedtls/check_config.h
mbedtls/config_adjust_legacy_crypto.h
mbedtls/config_adjust_psa_from_legacy.h
mbedtls/config_adjust_psa_superset_legacy.h
mbedtls/config_adjust_ssl.h
mbedtls/config_adjust_x509.h
mbedtls/config_psa.h
mbedtls/mbedtls_config.h
memory_buffer_alloc.h
psa/crypto_adjust_auto_enabled.h
psa/crypto_adjust_config_dependencies.h
psa/crypto_adjust_config_key_pair_types.h
psa/crypto_adjust_config_synonyms.h
psa/crypto_legacy.h
limits.h
stddef.h
stdint.h
SECTION: Module settings

The configuration options you can set for this module are in this section. Either change them in mbedtls_config.h or define them on the compiler command line.

MBEDTLS_MEMORY_ALIGN_MULTIPLE
4

Align on multiples of this value

MBEDTLS_MEMORY_VERIFY_NONE
0
MBEDTLS_MEMORY_VERIFY_ALLOC
(1 << 0)
MBEDTLS_MEMORY_VERIFY_FREE
(1 << 1)
MBEDTLS_MEMORY_VERIFY_ALWAYS
(MBEDTLS_MEMORY_VERIFY_ALLOC | \ MBEDTLS_MEMORY_VERIFY_FREE)
void void mbedtls_memory_buffer_alloc_init (unsigned char *buf, size_t len) mbedtls_memory_buffer_alloc_init unsigned char * buf size_t len

Initialize use of stack-based memory allocator. The stack-based allocator does memory management inside the presented buffer and does not call calloc() and free(). It sets the global mbedtls_calloc() and mbedtls_free() pointers to its own functions. (Provided mbedtls_calloc() and mbedtls_free() are thread-safe if MBEDTLS_THREADING_C is defined).

This code is not optimized and provides a straight-forward implementation of a stack-based memory allocator.

buf

buffer to use as heap

len

size of the buffer

void void mbedtls_memory_buffer_alloc_free (void) mbedtls_memory_buffer_alloc_free void

Free the mutex for thread-safety and clear remaining memory.

void void mbedtls_memory_buffer_set_verify (int verify) mbedtls_memory_buffer_set_verify int verify

Determine when the allocator should automatically verify the state of the entire chain of headers / meta-data. (Default: MBEDTLS_MEMORY_VERIFY_NONE).

verify

One of MBEDTLS_MEMORY_VERIFY_NONE, MBEDTLS_MEMORY_VERIFY_ALLOC, MBEDTLS_MEMORY_VERIFY_FREE or MBEDTLS_MEMORY_VERIFY_ALWAYS

int int mbedtls_memory_buffer_alloc_verify (void) mbedtls_memory_buffer_alloc_verify void

Verifies that all headers in the memory buffer are correct and contain sane values. Helps debug buffer-overflow errors.

Prints out first failure if MBEDTLS_MEMORY_DEBUG is defined. Prints out full header information if MBEDTLS_MEMORY_DEBUG is defined. (Includes stack trace information for each block if MBEDTLS_MEMORY_BACKTRACE is defined as well).

0 if verified, 1 otherwise

int int mbedtls_memory_buffer_alloc_self_test (int verbose) mbedtls_memory_buffer_alloc_self_test int verbose

Checkup routine.

0 if successful, or 1 if a test failed

Buffer-based memory allocator.

    /*
    *CopyrightTheMbedTLSContributors
    *SPDX-License-Identifier:Apache-2.0ORGPL-2.0-or-later
    */
    #ifndefMBEDTLS_MEMORY_BUFFER_ALLOC_H
    #defineMBEDTLS_MEMORY_BUFFER_ALLOC_H

    #include"mbedtls/build_info.h"

    #include<stddef.h>

    #if!defined(MBEDTLS_MEMORY_ALIGN_MULTIPLE)
    #defineMBEDTLS_MEMORY_ALIGN_MULTIPLE4
    #endif

    #defineMBEDTLS_MEMORY_VERIFY_NONE0
    #defineMBEDTLS_MEMORY_VERIFY_ALLOC(1<<0)
    #defineMBEDTLS_MEMORY_VERIFY_FREE(1<<1)
    #defineMBEDTLS_MEMORY_VERIFY_ALWAYS(MBEDTLS_MEMORY_VERIFY_ALLOC|\
    MBEDTLS_MEMORY_VERIFY_FREE)

    #ifdef__cplusplus
    extern"C"{
    #endif

    voidmbedtls_memory_buffer_alloc_init(unsignedchar*buf,size_tlen);

    voidmbedtls_memory_buffer_alloc_free(void);

    voidmbedtls_memory_buffer_set_verify(intverify);

    #ifdefined(MBEDTLS_MEMORY_DEBUG)
    voidmbedtls_memory_buffer_alloc_status(void);

    voidmbedtls_memory_buffer_alloc_count_get(size_t*alloc_count,size_t*free_count);

    voidmbedtls_memory_buffer_alloc_max_get(size_t*max_used,size_t*max_blocks);

    voidmbedtls_memory_buffer_alloc_max_reset(void);

    voidmbedtls_memory_buffer_alloc_cur_get(size_t*cur_used,size_t*cur_blocks);
    #endif/*MBEDTLS_MEMORY_DEBUG*/

    intmbedtls_memory_buffer_alloc_verify(void);

    #ifdefined(MBEDTLS_SELF_TEST)
    intmbedtls_memory_buffer_alloc_self_test(intverbose);
    #endif

    #ifdef__cplusplus
    }
    #endif

    #endif/*memory_buffer_alloc.h*/