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