mbed client lightswitch demo
Dependencies: mbed Socket lwip-eth lwip-sys lwip
Fork of mbed-client-classic-example-lwip by
mbedtls/mbedtls/memory_buffer_alloc.h@11:cada08fc8a70, 2016-06-09 (annotated)
- Committer:
- mbedAustin
- Date:
- Thu Jun 09 17:08:36 2016 +0000
- Revision:
- 11:cada08fc8a70
Commit for public Consumption
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| mbedAustin | 11:cada08fc8a70 | 1 | /** |
| mbedAustin | 11:cada08fc8a70 | 2 | * \file memory_buffer_alloc.h |
| mbedAustin | 11:cada08fc8a70 | 3 | * |
| mbedAustin | 11:cada08fc8a70 | 4 | * \brief Buffer-based memory allocator |
| mbedAustin | 11:cada08fc8a70 | 5 | * |
| mbedAustin | 11:cada08fc8a70 | 6 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved |
| mbedAustin | 11:cada08fc8a70 | 7 | * SPDX-License-Identifier: Apache-2.0 |
| mbedAustin | 11:cada08fc8a70 | 8 | * |
| mbedAustin | 11:cada08fc8a70 | 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| mbedAustin | 11:cada08fc8a70 | 10 | * not use this file except in compliance with the License. |
| mbedAustin | 11:cada08fc8a70 | 11 | * You may obtain a copy of the License at |
| mbedAustin | 11:cada08fc8a70 | 12 | * |
| mbedAustin | 11:cada08fc8a70 | 13 | * http://www.apache.org/licenses/LICENSE-2.0 |
| mbedAustin | 11:cada08fc8a70 | 14 | * |
| mbedAustin | 11:cada08fc8a70 | 15 | * Unless required by applicable law or agreed to in writing, software |
| mbedAustin | 11:cada08fc8a70 | 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| mbedAustin | 11:cada08fc8a70 | 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| mbedAustin | 11:cada08fc8a70 | 18 | * See the License for the specific language governing permissions and |
| mbedAustin | 11:cada08fc8a70 | 19 | * limitations under the License. |
| mbedAustin | 11:cada08fc8a70 | 20 | * |
| mbedAustin | 11:cada08fc8a70 | 21 | * This file is part of mbed TLS (https://tls.mbed.org) |
| mbedAustin | 11:cada08fc8a70 | 22 | */ |
| mbedAustin | 11:cada08fc8a70 | 23 | #ifndef MBEDTLS_MEMORY_BUFFER_ALLOC_H |
| mbedAustin | 11:cada08fc8a70 | 24 | #define MBEDTLS_MEMORY_BUFFER_ALLOC_H |
| mbedAustin | 11:cada08fc8a70 | 25 | |
| mbedAustin | 11:cada08fc8a70 | 26 | #if !defined(MBEDTLS_CONFIG_FILE) |
| mbedAustin | 11:cada08fc8a70 | 27 | #include "config.h" |
| mbedAustin | 11:cada08fc8a70 | 28 | #else |
| mbedAustin | 11:cada08fc8a70 | 29 | #include MBEDTLS_CONFIG_FILE |
| mbedAustin | 11:cada08fc8a70 | 30 | #endif |
| mbedAustin | 11:cada08fc8a70 | 31 | |
| mbedAustin | 11:cada08fc8a70 | 32 | #include <stddef.h> |
| mbedAustin | 11:cada08fc8a70 | 33 | |
| mbedAustin | 11:cada08fc8a70 | 34 | /** |
| mbedAustin | 11:cada08fc8a70 | 35 | * \name SECTION: Module settings |
| mbedAustin | 11:cada08fc8a70 | 36 | * |
| mbedAustin | 11:cada08fc8a70 | 37 | * The configuration options you can set for this module are in this section. |
| mbedAustin | 11:cada08fc8a70 | 38 | * Either change them in config.h or define them on the compiler command line. |
| mbedAustin | 11:cada08fc8a70 | 39 | * \{ |
| mbedAustin | 11:cada08fc8a70 | 40 | */ |
| mbedAustin | 11:cada08fc8a70 | 41 | |
| mbedAustin | 11:cada08fc8a70 | 42 | #if !defined(MBEDTLS_MEMORY_ALIGN_MULTIPLE) |
| mbedAustin | 11:cada08fc8a70 | 43 | #define MBEDTLS_MEMORY_ALIGN_MULTIPLE 4 /**< Align on multiples of this value */ |
| mbedAustin | 11:cada08fc8a70 | 44 | #endif |
| mbedAustin | 11:cada08fc8a70 | 45 | |
| mbedAustin | 11:cada08fc8a70 | 46 | /* \} name SECTION: Module settings */ |
| mbedAustin | 11:cada08fc8a70 | 47 | |
| mbedAustin | 11:cada08fc8a70 | 48 | #define MBEDTLS_MEMORY_VERIFY_NONE 0 |
| mbedAustin | 11:cada08fc8a70 | 49 | #define MBEDTLS_MEMORY_VERIFY_ALLOC (1 << 0) |
| mbedAustin | 11:cada08fc8a70 | 50 | #define MBEDTLS_MEMORY_VERIFY_FREE (1 << 1) |
| mbedAustin | 11:cada08fc8a70 | 51 | #define MBEDTLS_MEMORY_VERIFY_ALWAYS (MBEDTLS_MEMORY_VERIFY_ALLOC | MBEDTLS_MEMORY_VERIFY_FREE) |
| mbedAustin | 11:cada08fc8a70 | 52 | |
| mbedAustin | 11:cada08fc8a70 | 53 | #ifdef __cplusplus |
| mbedAustin | 11:cada08fc8a70 | 54 | extern "C" { |
| mbedAustin | 11:cada08fc8a70 | 55 | #endif |
| mbedAustin | 11:cada08fc8a70 | 56 | |
| mbedAustin | 11:cada08fc8a70 | 57 | /** |
| mbedAustin | 11:cada08fc8a70 | 58 | * \brief Initialize use of stack-based memory allocator. |
| mbedAustin | 11:cada08fc8a70 | 59 | * The stack-based allocator does memory management inside the |
| mbedAustin | 11:cada08fc8a70 | 60 | * presented buffer and does not call calloc() and free(). |
| mbedAustin | 11:cada08fc8a70 | 61 | * It sets the global mbedtls_calloc() and mbedtls_free() pointers |
| mbedAustin | 11:cada08fc8a70 | 62 | * to its own functions. |
| mbedAustin | 11:cada08fc8a70 | 63 | * (Provided mbedtls_calloc() and mbedtls_free() are thread-safe if |
| mbedAustin | 11:cada08fc8a70 | 64 | * MBEDTLS_THREADING_C is defined) |
| mbedAustin | 11:cada08fc8a70 | 65 | * |
| mbedAustin | 11:cada08fc8a70 | 66 | * \note This code is not optimized and provides a straight-forward |
| mbedAustin | 11:cada08fc8a70 | 67 | * implementation of a stack-based memory allocator. |
| mbedAustin | 11:cada08fc8a70 | 68 | * |
| mbedAustin | 11:cada08fc8a70 | 69 | * \param buf buffer to use as heap |
| mbedAustin | 11:cada08fc8a70 | 70 | * \param len size of the buffer |
| mbedAustin | 11:cada08fc8a70 | 71 | */ |
| mbedAustin | 11:cada08fc8a70 | 72 | void mbedtls_memory_buffer_alloc_init( unsigned char *buf, size_t len ); |
| mbedAustin | 11:cada08fc8a70 | 73 | |
| mbedAustin | 11:cada08fc8a70 | 74 | /** |
| mbedAustin | 11:cada08fc8a70 | 75 | * \brief Free the mutex for thread-safety and clear remaining memory |
| mbedAustin | 11:cada08fc8a70 | 76 | */ |
| mbedAustin | 11:cada08fc8a70 | 77 | void mbedtls_memory_buffer_alloc_free( void ); |
| mbedAustin | 11:cada08fc8a70 | 78 | |
| mbedAustin | 11:cada08fc8a70 | 79 | /** |
| mbedAustin | 11:cada08fc8a70 | 80 | * \brief Determine when the allocator should automatically verify the state |
| mbedAustin | 11:cada08fc8a70 | 81 | * of the entire chain of headers / meta-data. |
| mbedAustin | 11:cada08fc8a70 | 82 | * (Default: MBEDTLS_MEMORY_VERIFY_NONE) |
| mbedAustin | 11:cada08fc8a70 | 83 | * |
| mbedAustin | 11:cada08fc8a70 | 84 | * \param verify One of MBEDTLS_MEMORY_VERIFY_NONE, MBEDTLS_MEMORY_VERIFY_ALLOC, |
| mbedAustin | 11:cada08fc8a70 | 85 | * MBEDTLS_MEMORY_VERIFY_FREE or MBEDTLS_MEMORY_VERIFY_ALWAYS |
| mbedAustin | 11:cada08fc8a70 | 86 | */ |
| mbedAustin | 11:cada08fc8a70 | 87 | void mbedtls_memory_buffer_set_verify( int verify ); |
| mbedAustin | 11:cada08fc8a70 | 88 | |
| mbedAustin | 11:cada08fc8a70 | 89 | #if defined(MBEDTLS_MEMORY_DEBUG) |
| mbedAustin | 11:cada08fc8a70 | 90 | /** |
| mbedAustin | 11:cada08fc8a70 | 91 | * \brief Print out the status of the allocated memory (primarily for use |
| mbedAustin | 11:cada08fc8a70 | 92 | * after a program should have de-allocated all memory) |
| mbedAustin | 11:cada08fc8a70 | 93 | * Prints out a list of 'still allocated' blocks and their stack |
| mbedAustin | 11:cada08fc8a70 | 94 | * trace if MBEDTLS_MEMORY_BACKTRACE is defined. |
| mbedAustin | 11:cada08fc8a70 | 95 | */ |
| mbedAustin | 11:cada08fc8a70 | 96 | void mbedtls_memory_buffer_alloc_status( void ); |
| mbedAustin | 11:cada08fc8a70 | 97 | |
| mbedAustin | 11:cada08fc8a70 | 98 | /** |
| mbedAustin | 11:cada08fc8a70 | 99 | * \brief Get the peak heap usage so far |
| mbedAustin | 11:cada08fc8a70 | 100 | * |
| mbedAustin | 11:cada08fc8a70 | 101 | * \param max_used Peak number of bytes reauested by the application |
| mbedAustin | 11:cada08fc8a70 | 102 | * \param max_blocks Peak number of blocks reauested by the application |
| mbedAustin | 11:cada08fc8a70 | 103 | */ |
| mbedAustin | 11:cada08fc8a70 | 104 | void mbedtls_memory_buffer_alloc_max_get( size_t *max_used, size_t *max_blocks ); |
| mbedAustin | 11:cada08fc8a70 | 105 | |
| mbedAustin | 11:cada08fc8a70 | 106 | /** |
| mbedAustin | 11:cada08fc8a70 | 107 | * \brief Reset peak statistics |
| mbedAustin | 11:cada08fc8a70 | 108 | */ |
| mbedAustin | 11:cada08fc8a70 | 109 | void mbedtls_memory_buffer_alloc_max_reset( void ); |
| mbedAustin | 11:cada08fc8a70 | 110 | |
| mbedAustin | 11:cada08fc8a70 | 111 | /** |
| mbedAustin | 11:cada08fc8a70 | 112 | * \brief Get the current heap usage |
| mbedAustin | 11:cada08fc8a70 | 113 | * |
| mbedAustin | 11:cada08fc8a70 | 114 | * \param cur_used Number of bytes reauested by the application |
| mbedAustin | 11:cada08fc8a70 | 115 | * \param cur_blocks Number of blocks reauested by the application |
| mbedAustin | 11:cada08fc8a70 | 116 | */ |
| mbedAustin | 11:cada08fc8a70 | 117 | void mbedtls_memory_buffer_alloc_cur_get( size_t *cur_used, size_t *cur_blocks ); |
| mbedAustin | 11:cada08fc8a70 | 118 | #endif /* MBEDTLS_MEMORY_DEBUG */ |
| mbedAustin | 11:cada08fc8a70 | 119 | |
| mbedAustin | 11:cada08fc8a70 | 120 | /** |
| mbedAustin | 11:cada08fc8a70 | 121 | * \brief Verifies that all headers in the memory buffer are correct |
| mbedAustin | 11:cada08fc8a70 | 122 | * and contain sane values. Helps debug buffer-overflow errors. |
| mbedAustin | 11:cada08fc8a70 | 123 | * |
| mbedAustin | 11:cada08fc8a70 | 124 | * Prints out first failure if MBEDTLS_MEMORY_DEBUG is defined. |
| mbedAustin | 11:cada08fc8a70 | 125 | * Prints out full header information if MBEDTLS_MEMORY_DEBUG |
| mbedAustin | 11:cada08fc8a70 | 126 | * is defined. (Includes stack trace information for each block if |
| mbedAustin | 11:cada08fc8a70 | 127 | * MBEDTLS_MEMORY_BACKTRACE is defined as well). |
| mbedAustin | 11:cada08fc8a70 | 128 | * |
| mbedAustin | 11:cada08fc8a70 | 129 | * \return 0 if verified, 1 otherwise |
| mbedAustin | 11:cada08fc8a70 | 130 | */ |
| mbedAustin | 11:cada08fc8a70 | 131 | int mbedtls_memory_buffer_alloc_verify( void ); |
| mbedAustin | 11:cada08fc8a70 | 132 | |
| mbedAustin | 11:cada08fc8a70 | 133 | #if defined(MBEDTLS_SELF_TEST) |
| mbedAustin | 11:cada08fc8a70 | 134 | /** |
| mbedAustin | 11:cada08fc8a70 | 135 | * \brief Checkup routine |
| mbedAustin | 11:cada08fc8a70 | 136 | * |
| mbedAustin | 11:cada08fc8a70 | 137 | * \return 0 if successful, or 1 if a test failed |
| mbedAustin | 11:cada08fc8a70 | 138 | */ |
| mbedAustin | 11:cada08fc8a70 | 139 | int mbedtls_memory_buffer_alloc_self_test( int verbose ); |
| mbedAustin | 11:cada08fc8a70 | 140 | #endif |
| mbedAustin | 11:cada08fc8a70 | 141 | |
| mbedAustin | 11:cada08fc8a70 | 142 | #ifdef __cplusplus |
| mbedAustin | 11:cada08fc8a70 | 143 | } |
| mbedAustin | 11:cada08fc8a70 | 144 | #endif |
| mbedAustin | 11:cada08fc8a70 | 145 | |
| mbedAustin | 11:cada08fc8a70 | 146 | #endif /* memory_buffer_alloc.h */ |
Austin Blackstone
