blob: 9e79b64dfb0faa28fbfaf79361f17521c36d68e3 [file] [log] [blame]
Paul Bakker747a83a2014-02-01 22:50:07 +01001/**
2 * \file platform.h
3 *
Manuel Pégourié-Gonnardb4fe3cb2015-01-22 16:11:05 +00004 * \brief mbed TLS Platform abstraction layer
Paul Bakker747a83a2014-02-01 22:50:07 +01005 *
Manuel Pégourié-Gonnarda658a402015-01-23 09:45:19 +00006 * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
Paul Bakker747a83a2014-02-01 22:50:07 +01007 *
Manuel Pégourié-Gonnard085ab042015-01-23 11:06:27 +00008 * This file is part of mbed TLS (https://www.polarssl.org)
Paul Bakker747a83a2014-02-01 22:50:07 +01009 *
Paul Bakker747a83a2014-02-01 22:50:07 +010010 * 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é-Gonnardcef4ad22014-04-29 12:39:06 +020027#if !defined(POLARSSL_CONFIG_FILE)
Paul Bakker747a83a2014-02-01 22:50:07 +010028#include "config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020029#else
30#include POLARSSL_CONFIG_FILE
31#endif
Paul Bakker747a83a2014-02-01 22:50:07 +010032
Paul Bakker747a83a2014-02-01 22:50:07 +010033#include <stdio.h>
34
35#ifdef __cplusplus
36extern "C" {
37#endif
38
Paul Bakker088c5c52014-04-25 11:11:10 +020039/**
40 * \name SECTION: Module settings
41 *
42 * The configuration options you can set for this module are in this section.
43 * Either change them in config.h or define them on the compiler command line.
44 * \{
45 */
46
47#if !defined(POLARSSL_PLATFORM_NO_STD_FUNCTIONS)
Paul Bakkera9066cf2014-02-05 15:13:04 +010048#include <stdlib.h>
Paul Bakker088c5c52014-04-25 11:11:10 +020049#if !defined(POLARSSL_PLATFORM_STD_PRINTF)
Paul Bakker747a83a2014-02-01 22:50:07 +010050#define POLARSSL_PLATFORM_STD_PRINTF printf /**< Default printf to use */
Paul Bakker088c5c52014-04-25 11:11:10 +020051#endif
52#if !defined(POLARSSL_PLATFORM_STD_FPRINTF)
Paul Bakker747a83a2014-02-01 22:50:07 +010053#define POLARSSL_PLATFORM_STD_FPRINTF fprintf /**< Default fprintf to use */
Paul Bakker088c5c52014-04-25 11:11:10 +020054#endif
55#if !defined(POLARSSL_PLATFORM_STD_MALLOC)
Paul Bakkerdefc0ca2014-02-04 17:30:24 +010056#define POLARSSL_PLATFORM_STD_MALLOC malloc /**< Default allocator to use */
Paul Bakker088c5c52014-04-25 11:11:10 +020057#endif
58#if !defined(POLARSSL_PLATFORM_STD_FREE)
Paul Bakkerdefc0ca2014-02-04 17:30:24 +010059#define POLARSSL_PLATFORM_STD_FREE free /**< Default free to use */
Paul Bakker088c5c52014-04-25 11:11:10 +020060#endif
61#else /* POLARSSL_PLATFORM_NO_STD_FUNCTIONS */
Manuel Pégourié-Gonnardeb82a742014-04-02 13:43:48 +020062#if defined(POLARSSL_PLATFORM_STD_MEM_HDR)
63#include POLARSSL_PLATFORM_STD_MEM_HDR
64#endif
Paul Bakker088c5c52014-04-25 11:11:10 +020065#endif /* POLARSSL_PLATFORM_NO_STD_FUNCTIONS */
66
67/* \} name SECTION: Module settings */
Paul Bakker747a83a2014-02-01 22:50:07 +010068
69/*
70 * The function pointers for malloc and free
71 */
Paul Bakkera9066cf2014-02-05 15:13:04 +010072#if defined(POLARSSL_PLATFORM_MEMORY)
Paul Bakkerdefc0ca2014-02-04 17:30:24 +010073extern void * (*polarssl_malloc)( size_t len );
74extern void (*polarssl_free)( void *ptr );
75
76/**
77 * \brief Set your own memory implementation function pointers
78 *
79 * \param malloc_func the malloc function implementation
80 * \param free_func the free function implementation
81 *
82 * \return 0 if successful
83 */
84int platform_set_malloc_free( void * (*malloc_func)( size_t ),
85 void (*free_func)( void * ) );
Paul Bakker9af723c2014-05-01 13:03:14 +020086#else /* POLARSSL_PLATFORM_ENTROPY */
Paul Bakker747a83a2014-02-01 22:50:07 +010087#define polarssl_malloc malloc
88#define polarssl_free free
Paul Bakker9af723c2014-05-01 13:03:14 +020089#endif /* POLARSSL_PLATFORM_ENTROPY */
Paul Bakker747a83a2014-02-01 22:50:07 +010090
91/*
92 * The function pointers for printf
93 */
94#if defined(POLARSSL_PLATFORM_PRINTF_ALT)
95extern int (*polarssl_printf)( const char *format, ... );
96
97/**
98 * \brief Set your own printf function pointer
99 *
100 * \param printf_func the printf function implementation
101 *
102 * \return 0
103 */
104int platform_set_printf( int (*printf_func)( const char *, ... ) );
Paul Bakker9af723c2014-05-01 13:03:14 +0200105#else /* POLARSSL_PLATFORM_PRINTF_ALT */
Paul Bakker747a83a2014-02-01 22:50:07 +0100106#define polarssl_printf printf
Paul Bakker9af723c2014-05-01 13:03:14 +0200107#endif /* POLARSSL_PLATFORM_PRINTF_ALT */
Paul Bakker747a83a2014-02-01 22:50:07 +0100108
109/*
110 * The function pointers for fprintf
111 */
112#if defined(POLARSSL_PLATFORM_FPRINTF_ALT)
113extern int (*polarssl_fprintf)( FILE *stream, const char *format, ... );
114
115int platform_set_fprintf( int (*fprintf_func)( FILE *stream, const char *,
116 ... ) );
117#else
118#define polarssl_fprintf fprintf
119#endif
120
121#ifdef __cplusplus
122}
123#endif
124
125#endif /* platform.h */