Paul Bakker | 747a83a | 2014-02-01 22:50:07 +0100 | [diff] [blame] | 1 | /** |
| 2 | * \file platform.h |
| 3 | * |
Manuel Pégourié-Gonnard | b4fe3cb | 2015-01-22 16:11:05 +0000 | [diff] [blame] | 4 | * \brief mbed TLS Platform abstraction layer |
Paul Bakker | 747a83a | 2014-02-01 22:50:07 +0100 | [diff] [blame] | 5 | * |
Manuel Pégourié-Gonnard | a658a40 | 2015-01-23 09:45:19 +0000 | [diff] [blame] | 6 | * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved |
Paul Bakker | 747a83a | 2014-02-01 22:50:07 +0100 | [diff] [blame] | 7 | * |
Manuel Pégourié-Gonnard | 085ab04 | 2015-01-23 11:06:27 +0000 | [diff] [blame] | 8 | * This file is part of mbed TLS (https://www.polarssl.org) |
Paul Bakker | 747a83a | 2014-02-01 22:50:07 +0100 | [diff] [blame] | 9 | * |
Paul Bakker | 747a83a | 2014-02-01 22:50:07 +0100 | [diff] [blame] | 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License as published by |
| 12 | * the Free Software Foundation; either version 2 of the License, or |
| 13 | * (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License along |
| 21 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 22 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 23 | */ |
| 24 | #ifndef POLARSSL_PLATFORM_H |
| 25 | #define POLARSSL_PLATFORM_H |
| 26 | |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 27 | #if !defined(POLARSSL_CONFIG_FILE) |
Paul Bakker | 747a83a | 2014-02-01 22:50:07 +0100 | [diff] [blame] | 28 | #include "config.h" |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 29 | #else |
| 30 | #include POLARSSL_CONFIG_FILE |
| 31 | #endif |
Paul Bakker | 747a83a | 2014-02-01 22:50:07 +0100 | [diff] [blame] | 32 | |
Manuel Pégourié-Gonnard | 0a155b8 | 2015-01-23 17:28:27 +0000 | [diff] [blame] | 33 | /* Temporary compability hack for to keep the deprecated MEMORY_C working */ |
| 34 | #if defined(POLARSSL_MEMORY_C) && !defined(POLARSSL_PLATFORM_MEMORY) |
| 35 | #define POLARSSL_PLATFORM_MEMORY |
| 36 | #endif |
| 37 | |
Paul Bakker | 747a83a | 2014-02-01 22:50:07 +0100 | [diff] [blame] | 38 | #include <stdio.h> |
| 39 | |
| 40 | #ifdef __cplusplus |
| 41 | extern "C" { |
| 42 | #endif |
| 43 | |
Paul Bakker | 088c5c5 | 2014-04-25 11:11:10 +0200 | [diff] [blame] | 44 | /** |
| 45 | * \name SECTION: Module settings |
| 46 | * |
| 47 | * The configuration options you can set for this module are in this section. |
| 48 | * Either change them in config.h or define them on the compiler command line. |
| 49 | * \{ |
| 50 | */ |
| 51 | |
| 52 | #if !defined(POLARSSL_PLATFORM_NO_STD_FUNCTIONS) |
Paul Bakker | a9066cf | 2014-02-05 15:13:04 +0100 | [diff] [blame] | 53 | #include <stdlib.h> |
Paul Bakker | 088c5c5 | 2014-04-25 11:11:10 +0200 | [diff] [blame] | 54 | #if !defined(POLARSSL_PLATFORM_STD_PRINTF) |
Paul Bakker | 747a83a | 2014-02-01 22:50:07 +0100 | [diff] [blame] | 55 | #define POLARSSL_PLATFORM_STD_PRINTF printf /**< Default printf to use */ |
Paul Bakker | 088c5c5 | 2014-04-25 11:11:10 +0200 | [diff] [blame] | 56 | #endif |
| 57 | #if !defined(POLARSSL_PLATFORM_STD_FPRINTF) |
Paul Bakker | 747a83a | 2014-02-01 22:50:07 +0100 | [diff] [blame] | 58 | #define POLARSSL_PLATFORM_STD_FPRINTF fprintf /**< Default fprintf to use */ |
Paul Bakker | 088c5c5 | 2014-04-25 11:11:10 +0200 | [diff] [blame] | 59 | #endif |
| 60 | #if !defined(POLARSSL_PLATFORM_STD_MALLOC) |
Paul Bakker | defc0ca | 2014-02-04 17:30:24 +0100 | [diff] [blame] | 61 | #define POLARSSL_PLATFORM_STD_MALLOC malloc /**< Default allocator to use */ |
Paul Bakker | 088c5c5 | 2014-04-25 11:11:10 +0200 | [diff] [blame] | 62 | #endif |
| 63 | #if !defined(POLARSSL_PLATFORM_STD_FREE) |
Paul Bakker | defc0ca | 2014-02-04 17:30:24 +0100 | [diff] [blame] | 64 | #define POLARSSL_PLATFORM_STD_FREE free /**< Default free to use */ |
Paul Bakker | 088c5c5 | 2014-04-25 11:11:10 +0200 | [diff] [blame] | 65 | #endif |
| 66 | #else /* POLARSSL_PLATFORM_NO_STD_FUNCTIONS */ |
Manuel Pégourié-Gonnard | eb82a74 | 2014-04-02 13:43:48 +0200 | [diff] [blame] | 67 | #if defined(POLARSSL_PLATFORM_STD_MEM_HDR) |
| 68 | #include POLARSSL_PLATFORM_STD_MEM_HDR |
| 69 | #endif |
Paul Bakker | 088c5c5 | 2014-04-25 11:11:10 +0200 | [diff] [blame] | 70 | #endif /* POLARSSL_PLATFORM_NO_STD_FUNCTIONS */ |
| 71 | |
| 72 | /* \} name SECTION: Module settings */ |
Paul Bakker | 747a83a | 2014-02-01 22:50:07 +0100 | [diff] [blame] | 73 | |
| 74 | /* |
| 75 | * The function pointers for malloc and free |
| 76 | */ |
Paul Bakker | a9066cf | 2014-02-05 15:13:04 +0100 | [diff] [blame] | 77 | #if defined(POLARSSL_PLATFORM_MEMORY) |
Paul Bakker | defc0ca | 2014-02-04 17:30:24 +0100 | [diff] [blame] | 78 | extern void * (*polarssl_malloc)( size_t len ); |
| 79 | extern void (*polarssl_free)( void *ptr ); |
| 80 | |
| 81 | /** |
| 82 | * \brief Set your own memory implementation function pointers |
| 83 | * |
| 84 | * \param malloc_func the malloc function implementation |
| 85 | * \param free_func the free function implementation |
| 86 | * |
| 87 | * \return 0 if successful |
| 88 | */ |
| 89 | int platform_set_malloc_free( void * (*malloc_func)( size_t ), |
| 90 | void (*free_func)( void * ) ); |
Paul Bakker | 9af723c | 2014-05-01 13:03:14 +0200 | [diff] [blame] | 91 | #else /* POLARSSL_PLATFORM_ENTROPY */ |
Paul Bakker | 747a83a | 2014-02-01 22:50:07 +0100 | [diff] [blame] | 92 | #define polarssl_malloc malloc |
| 93 | #define polarssl_free free |
Paul Bakker | 9af723c | 2014-05-01 13:03:14 +0200 | [diff] [blame] | 94 | #endif /* POLARSSL_PLATFORM_ENTROPY */ |
Paul Bakker | 747a83a | 2014-02-01 22:50:07 +0100 | [diff] [blame] | 95 | |
| 96 | /* |
| 97 | * The function pointers for printf |
| 98 | */ |
| 99 | #if defined(POLARSSL_PLATFORM_PRINTF_ALT) |
| 100 | extern int (*polarssl_printf)( const char *format, ... ); |
| 101 | |
| 102 | /** |
| 103 | * \brief Set your own printf function pointer |
| 104 | * |
| 105 | * \param printf_func the printf function implementation |
| 106 | * |
| 107 | * \return 0 |
| 108 | */ |
| 109 | int platform_set_printf( int (*printf_func)( const char *, ... ) ); |
Paul Bakker | 9af723c | 2014-05-01 13:03:14 +0200 | [diff] [blame] | 110 | #else /* POLARSSL_PLATFORM_PRINTF_ALT */ |
Paul Bakker | 747a83a | 2014-02-01 22:50:07 +0100 | [diff] [blame] | 111 | #define polarssl_printf printf |
Paul Bakker | 9af723c | 2014-05-01 13:03:14 +0200 | [diff] [blame] | 112 | #endif /* POLARSSL_PLATFORM_PRINTF_ALT */ |
Paul Bakker | 747a83a | 2014-02-01 22:50:07 +0100 | [diff] [blame] | 113 | |
| 114 | /* |
| 115 | * The function pointers for fprintf |
| 116 | */ |
| 117 | #if defined(POLARSSL_PLATFORM_FPRINTF_ALT) |
| 118 | extern int (*polarssl_fprintf)( FILE *stream, const char *format, ... ); |
| 119 | |
| 120 | int platform_set_fprintf( int (*fprintf_func)( FILE *stream, const char *, |
| 121 | ... ) ); |
| 122 | #else |
| 123 | #define polarssl_fprintf fprintf |
| 124 | #endif |
| 125 | |
| 126 | #ifdef __cplusplus |
| 127 | } |
| 128 | #endif |
| 129 | |
| 130 | #endif /* platform.h */ |