Paul Bakker | 747a83a | 2014-02-01 22:50:07 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Platform abstraction layer |
| 3 | * |
Manuel Pégourié-Gonnard | a658a40 | 2015-01-23 09:45:19 +0000 | [diff] [blame] | 4 | * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved |
Paul Bakker | 747a83a | 2014-02-01 22:50:07 +0100 | [diff] [blame] | 5 | * |
Manuel Pégourié-Gonnard | 860b516 | 2015-01-28 17:12:07 +0000 | [diff] [blame] | 6 | * This file is part of mbed TLS (https://polarssl.org) |
Paul Bakker | 747a83a | 2014-02-01 22:50:07 +0100 | [diff] [blame] | 7 | * |
Paul Bakker | 747a83a | 2014-02-01 22:50:07 +0100 | [diff] [blame] | 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License along |
| 19 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 20 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 21 | */ |
| 22 | |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 23 | #if !defined(POLARSSL_CONFIG_FILE) |
Paul Bakker | 747a83a | 2014-02-01 22:50:07 +0100 | [diff] [blame] | 24 | #include "polarssl/config.h" |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 25 | #else |
| 26 | #include POLARSSL_CONFIG_FILE |
| 27 | #endif |
Paul Bakker | 747a83a | 2014-02-01 22:50:07 +0100 | [diff] [blame] | 28 | |
| 29 | #if defined(POLARSSL_PLATFORM_C) |
| 30 | |
| 31 | #include "polarssl/platform.h" |
| 32 | |
Paul Bakker | defc0ca | 2014-02-04 17:30:24 +0100 | [diff] [blame] | 33 | #if defined(POLARSSL_PLATFORM_MEMORY) |
| 34 | #if !defined(POLARSSL_PLATFORM_STD_MALLOC) |
| 35 | static void *platform_malloc_uninit( size_t len ) |
| 36 | { |
| 37 | ((void) len); |
| 38 | return( NULL ); |
| 39 | } |
| 40 | |
Manuel Pégourié-Gonnard | 74bc68a | 2014-04-02 13:20:00 +0200 | [diff] [blame] | 41 | #define POLARSSL_PLATFORM_STD_MALLOC platform_malloc_uninit |
Paul Bakker | defc0ca | 2014-02-04 17:30:24 +0100 | [diff] [blame] | 42 | #endif /* !POLARSSL_PLATFORM_STD_MALLOC */ |
| 43 | |
| 44 | #if !defined(POLARSSL_PLATFORM_STD_FREE) |
| 45 | static void platform_free_uninit( void *ptr ) |
| 46 | { |
| 47 | ((void) ptr); |
| 48 | } |
| 49 | |
Manuel Pégourié-Gonnard | 74bc68a | 2014-04-02 13:20:00 +0200 | [diff] [blame] | 50 | #define POLARSSL_PLATFORM_STD_FREE platform_free_uninit |
Paul Bakker | defc0ca | 2014-02-04 17:30:24 +0100 | [diff] [blame] | 51 | #endif /* !POLARSSL_PLATFORM_STD_FREE */ |
| 52 | |
| 53 | void * (*polarssl_malloc)( size_t ) = POLARSSL_PLATFORM_STD_MALLOC; |
| 54 | void (*polarssl_free)( void * ) = POLARSSL_PLATFORM_STD_FREE; |
| 55 | |
| 56 | int platform_set_malloc_free( void * (*malloc_func)( size_t ), |
| 57 | void (*free_func)( void * ) ) |
| 58 | { |
| 59 | polarssl_malloc = malloc_func; |
| 60 | polarssl_free = free_func; |
| 61 | return( 0 ); |
| 62 | } |
| 63 | #endif /* POLARSSL_PLATFORM_MEMORY */ |
| 64 | |
Paul Bakker | 747a83a | 2014-02-01 22:50:07 +0100 | [diff] [blame] | 65 | #if defined(POLARSSL_PLATFORM_PRINTF_ALT) |
| 66 | #if !defined(POLARSSL_PLATFORM_STD_PRINTF) |
| 67 | /* |
| 68 | * Make dummy function to prevent NULL pointer dereferences |
| 69 | */ |
| 70 | static int platform_printf_uninit( const char *format, ... ) |
| 71 | { |
| 72 | ((void) format); |
| 73 | return( 0 ); |
| 74 | } |
| 75 | |
| 76 | #define POLARSSL_PLATFORM_STD_PRINTF platform_printf_uninit |
| 77 | #endif /* !POLARSSL_PLATFORM_STD_PRINTF */ |
| 78 | |
| 79 | int (*polarssl_printf)( const char *, ... ) = POLARSSL_PLATFORM_STD_PRINTF; |
| 80 | |
| 81 | int platform_set_printf( int (*printf_func)( const char *, ... ) ) |
| 82 | { |
| 83 | polarssl_printf = printf_func; |
| 84 | return( 0 ); |
| 85 | } |
| 86 | #endif /* POLARSSL_PLATFORM_PRINTF_ALT */ |
| 87 | |
| 88 | #if defined(POLARSSL_PLATFORM_FPRINTF_ALT) |
| 89 | #if !defined(POLARSSL_PLATFORM_STD_FPRINTF) |
| 90 | /* |
| 91 | * Make dummy function to prevent NULL pointer dereferences |
| 92 | */ |
| 93 | static int platform_fprintf_uninit( FILE *stream, const char *format, ... ) |
| 94 | { |
| 95 | ((void) stream); |
| 96 | ((void) format); |
| 97 | return( 0 ); |
| 98 | } |
| 99 | |
Paul Bakker | 10a9dd3 | 2014-04-25 11:18:34 +0200 | [diff] [blame] | 100 | #define POLARSSL_PLATFORM_STD_FPRINTF platform_fprintf_uninit |
Paul Bakker | 747a83a | 2014-02-01 22:50:07 +0100 | [diff] [blame] | 101 | #endif /* !POLARSSL_PLATFORM_STD_FPRINTF */ |
| 102 | |
| 103 | int (*polarssl_fprintf)( FILE *, const char *, ... ) = |
| 104 | POLARSSL_PLATFORM_STD_FPRINTF; |
| 105 | |
| 106 | int platform_set_fprintf( int (*fprintf_func)( FILE *, const char *, ... ) ) |
| 107 | { |
| 108 | polarssl_fprintf = fprintf_func; |
| 109 | return( 0 ); |
| 110 | } |
| 111 | #endif /* POLARSSL_PLATFORM_FPRINTF_ALT */ |
| 112 | |
| 113 | #endif /* POLARSSL_PLATFORM_C */ |