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