2014-02-01 21:50:07 +00:00
|
|
|
/**
|
|
|
|
* \file platform.h
|
|
|
|
*
|
2015-01-22 16:11:05 +00:00
|
|
|
* \brief mbed TLS Platform abstraction layer
|
2014-02-01 21:50:07 +00:00
|
|
|
*
|
2015-01-23 09:45:19 +00:00
|
|
|
* Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
|
2014-02-01 21:50:07 +00:00
|
|
|
*
|
2015-01-23 11:06:27 +00:00
|
|
|
* This file is part of mbed TLS (https://www.polarssl.org)
|
2014-02-01 21:50:07 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
#ifndef POLARSSL_PLATFORM_H
|
|
|
|
#define POLARSSL_PLATFORM_H
|
|
|
|
|
2014-04-29 10:39:06 +00:00
|
|
|
#if !defined(POLARSSL_CONFIG_FILE)
|
2014-02-01 21:50:07 +00:00
|
|
|
#include "config.h"
|
2014-04-29 10:39:06 +00:00
|
|
|
#else
|
|
|
|
#include POLARSSL_CONFIG_FILE
|
|
|
|
#endif
|
2014-02-01 21:50:07 +00:00
|
|
|
|
2015-01-23 17:28:27 +00:00
|
|
|
/* Temporary compability hack for to keep the deprecated MEMORY_C working */
|
|
|
|
#if defined(POLARSSL_MEMORY_C) && !defined(POLARSSL_PLATFORM_MEMORY)
|
|
|
|
#define POLARSSL_PLATFORM_MEMORY
|
|
|
|
#endif
|
|
|
|
|
2014-02-01 21:50:07 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2014-04-25 09:11:10 +00:00
|
|
|
/**
|
|
|
|
* \name SECTION: Module settings
|
|
|
|
*
|
|
|
|
* The configuration options you can set for this module are in this section.
|
|
|
|
* Either change them in config.h or define them on the compiler command line.
|
|
|
|
* \{
|
|
|
|
*/
|
|
|
|
|
|
|
|
#if !defined(POLARSSL_PLATFORM_NO_STD_FUNCTIONS)
|
2014-02-05 14:13:04 +00:00
|
|
|
#include <stdlib.h>
|
2014-04-25 09:11:10 +00:00
|
|
|
#if !defined(POLARSSL_PLATFORM_STD_PRINTF)
|
2014-02-01 21:50:07 +00:00
|
|
|
#define POLARSSL_PLATFORM_STD_PRINTF printf /**< Default printf to use */
|
2014-04-25 09:11:10 +00:00
|
|
|
#endif
|
|
|
|
#if !defined(POLARSSL_PLATFORM_STD_FPRINTF)
|
2014-02-01 21:50:07 +00:00
|
|
|
#define POLARSSL_PLATFORM_STD_FPRINTF fprintf /**< Default fprintf to use */
|
2014-04-25 09:11:10 +00:00
|
|
|
#endif
|
|
|
|
#if !defined(POLARSSL_PLATFORM_STD_MALLOC)
|
2014-02-04 16:30:24 +00:00
|
|
|
#define POLARSSL_PLATFORM_STD_MALLOC malloc /**< Default allocator to use */
|
2014-04-25 09:11:10 +00:00
|
|
|
#endif
|
|
|
|
#if !defined(POLARSSL_PLATFORM_STD_FREE)
|
2014-02-04 16:30:24 +00:00
|
|
|
#define POLARSSL_PLATFORM_STD_FREE free /**< Default free to use */
|
2014-04-25 09:11:10 +00:00
|
|
|
#endif
|
|
|
|
#else /* POLARSSL_PLATFORM_NO_STD_FUNCTIONS */
|
2014-04-02 11:43:48 +00:00
|
|
|
#if defined(POLARSSL_PLATFORM_STD_MEM_HDR)
|
|
|
|
#include POLARSSL_PLATFORM_STD_MEM_HDR
|
|
|
|
#endif
|
2014-04-25 09:11:10 +00:00
|
|
|
#endif /* POLARSSL_PLATFORM_NO_STD_FUNCTIONS */
|
|
|
|
|
|
|
|
/* \} name SECTION: Module settings */
|
2014-02-01 21:50:07 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The function pointers for malloc and free
|
|
|
|
*/
|
2014-02-05 14:13:04 +00:00
|
|
|
#if defined(POLARSSL_PLATFORM_MEMORY)
|
2014-02-04 16:30:24 +00:00
|
|
|
extern void * (*polarssl_malloc)( size_t len );
|
|
|
|
extern void (*polarssl_free)( void *ptr );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Set your own memory implementation function pointers
|
|
|
|
*
|
|
|
|
* \param malloc_func the malloc function implementation
|
|
|
|
* \param free_func the free function implementation
|
|
|
|
*
|
|
|
|
* \return 0 if successful
|
|
|
|
*/
|
|
|
|
int platform_set_malloc_free( void * (*malloc_func)( size_t ),
|
|
|
|
void (*free_func)( void * ) );
|
2014-05-01 11:03:14 +00:00
|
|
|
#else /* POLARSSL_PLATFORM_ENTROPY */
|
2014-02-01 21:50:07 +00:00
|
|
|
#define polarssl_malloc malloc
|
|
|
|
#define polarssl_free free
|
2014-05-01 11:03:14 +00:00
|
|
|
#endif /* POLARSSL_PLATFORM_ENTROPY */
|
2014-02-01 21:50:07 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The function pointers for printf
|
|
|
|
*/
|
|
|
|
#if defined(POLARSSL_PLATFORM_PRINTF_ALT)
|
|
|
|
extern int (*polarssl_printf)( const char *format, ... );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Set your own printf function pointer
|
|
|
|
*
|
|
|
|
* \param printf_func the printf function implementation
|
|
|
|
*
|
|
|
|
* \return 0
|
|
|
|
*/
|
|
|
|
int platform_set_printf( int (*printf_func)( const char *, ... ) );
|
2014-05-01 11:03:14 +00:00
|
|
|
#else /* POLARSSL_PLATFORM_PRINTF_ALT */
|
2014-02-01 21:50:07 +00:00
|
|
|
#define polarssl_printf printf
|
2014-05-01 11:03:14 +00:00
|
|
|
#endif /* POLARSSL_PLATFORM_PRINTF_ALT */
|
2014-02-01 21:50:07 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The function pointers for fprintf
|
|
|
|
*/
|
|
|
|
#if defined(POLARSSL_PLATFORM_FPRINTF_ALT)
|
|
|
|
extern int (*polarssl_fprintf)( FILE *stream, const char *format, ... );
|
|
|
|
|
|
|
|
int platform_set_fprintf( int (*fprintf_func)( FILE *stream, const char *,
|
|
|
|
... ) );
|
|
|
|
#else
|
|
|
|
#define polarssl_fprintf fprintf
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* platform.h */
|