79 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			79 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
| /**
 | |
|  * \file memory_buffer_alloc.h
 | |
|  *
 | |
|  * \brief Buffer-based memory allocator
 | |
|  *
 | |
|  *  Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
 | |
|  *  SPDX-License-Identifier: Apache-2.0
 | |
|  *
 | |
|  *  Licensed under the Apache License, Version 2.0 (the "License"); you may
 | |
|  *  not use this file except in compliance with the License.
 | |
|  *  You may obtain a copy of the License at
 | |
|  *
 | |
|  *  http://www.apache.org/licenses/LICENSE-2.0
 | |
|  *
 | |
|  *  Unless required by applicable law or agreed to in writing, software
 | |
|  *  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 | |
|  *  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | |
|  *  See the License for the specific language governing permissions and
 | |
|  *  limitations under the License.
 | |
|  *
 | |
|  *  This file is part of mbed TLS (https://tls.mbed.org)
 | |
|  */
 | |
| #ifndef MEMORY_BUFFER_ALLOC_H
 | |
| #define MEMORY_BUFFER_ALLOC_H
 | |
| 
 | |
| #include <stddef.h>
 | |
| /**
 | |
|  * \name SECTION: Module settings
 | |
|  *
 | |
|  * The configuration options you can set for this module are in this section.
 | |
|  * Either change them in config.h or define them on the compiler command line.
 | |
|  * \{
 | |
|  */
 | |
| 
 | |
| #define MBEDTLS_MEMORY_ALIGN_MULTIPLE       4 /**< Align on multiples of this value */
 | |
| 
 | |
| /* \} name SECTION: Module settings */
 | |
| 
 | |
| #define MBEDTLS_MEMORY_VERIFY_NONE         0
 | |
| #define MBEDTLS_MEMORY_VERIFY_ALLOC        (1 << 0)
 | |
| #define MBEDTLS_MEMORY_VERIFY_FREE         (1 << 1)
 | |
| #define MBEDTLS_MEMORY_VERIFY_ALWAYS       (MBEDTLS_MEMORY_VERIFY_ALLOC | MBEDTLS_MEMORY_VERIFY_FREE)
 | |
| 
 | |
| #ifdef __cplusplus
 | |
| extern "C" {
 | |
| #endif
 | |
| 
 | |
| /**
 | |
|  * \brief   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)
 | |
|  *
 | |
|  * \note    This code is not optimized and provides a straight-forward
 | |
|  *          implementation of a stack-based memory allocator.
 | |
|  *
 | |
|  * \param buf   buffer to use as heap
 | |
|  * \param len   size of the buffer
 | |
|  */
 | |
| void memory_buffer_alloc_init( unsigned char *buf, size_t len );
 | |
| 
 | |
| /**
 | |
|  * \brief   Free the mutex for thread-safety and clear remaining memory
 | |
|  */
 | |
| void memory_buffer_alloc_free( void );
 | |
| 
 | |
| void *buffer_alloc_malloc(size_t size);
 | |
| 
 | |
| void buffer_alloc_free( void *ptr );
 | |
| 
 | |
| #ifdef __cplusplus
 | |
| }
 | |
| #endif
 | |
| 
 | |
| #endif /* memory_buffer_alloc.h */
 |