2014-02-01 22:50:07 +01:00
|
|
|
/*
|
|
|
|
* Platform abstraction layer
|
|
|
|
*
|
2015-01-23 10:45:19 +01:00
|
|
|
* Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
|
2014-02-01 22:50:07 +01:00
|
|
|
*
|
2015-01-28 18:12:07 +01:00
|
|
|
* This file is part of mbed TLS (https://polarssl.org)
|
2014-02-01 22:50:07 +01: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.
|
|
|
|
*/
|
|
|
|
|
2014-04-29 12:39:06 +02:00
|
|
|
#if !defined(POLARSSL_CONFIG_FILE)
|
2014-02-01 22:50:07 +01:00
|
|
|
#include "polarssl/config.h"
|
2014-04-29 12:39:06 +02:00
|
|
|
#else
|
|
|
|
#include POLARSSL_CONFIG_FILE
|
|
|
|
#endif
|
2014-02-01 22:50:07 +01:00
|
|
|
|
|
|
|
#if defined(POLARSSL_PLATFORM_C)
|
|
|
|
|
|
|
|
#include "polarssl/platform.h"
|
|
|
|
|
2014-02-04 17:30:24 +01:00
|
|
|
#if defined(POLARSSL_PLATFORM_MEMORY)
|
|
|
|
#if !defined(POLARSSL_PLATFORM_STD_MALLOC)
|
|
|
|
static void *platform_malloc_uninit( size_t len )
|
|
|
|
{
|
|
|
|
((void) len);
|
|
|
|
return( NULL );
|
|
|
|
}
|
|
|
|
|
2014-04-02 13:20:00 +02:00
|
|
|
#define POLARSSL_PLATFORM_STD_MALLOC platform_malloc_uninit
|
2014-02-04 17:30:24 +01:00
|
|
|
#endif /* !POLARSSL_PLATFORM_STD_MALLOC */
|
|
|
|
|
|
|
|
#if !defined(POLARSSL_PLATFORM_STD_FREE)
|
|
|
|
static void platform_free_uninit( void *ptr )
|
|
|
|
{
|
|
|
|
((void) ptr);
|
|
|
|
}
|
|
|
|
|
2014-04-02 13:20:00 +02:00
|
|
|
#define POLARSSL_PLATFORM_STD_FREE platform_free_uninit
|
2014-02-04 17:30:24 +01:00
|
|
|
#endif /* !POLARSSL_PLATFORM_STD_FREE */
|
|
|
|
|
|
|
|
void * (*polarssl_malloc)( size_t ) = POLARSSL_PLATFORM_STD_MALLOC;
|
|
|
|
void (*polarssl_free)( void * ) = POLARSSL_PLATFORM_STD_FREE;
|
|
|
|
|
|
|
|
int platform_set_malloc_free( void * (*malloc_func)( size_t ),
|
|
|
|
void (*free_func)( void * ) )
|
|
|
|
{
|
|
|
|
polarssl_malloc = malloc_func;
|
|
|
|
polarssl_free = free_func;
|
|
|
|
return( 0 );
|
|
|
|
}
|
|
|
|
#endif /* POLARSSL_PLATFORM_MEMORY */
|
|
|
|
|
2015-01-30 11:47:32 +01:00
|
|
|
#if defined(POLARSSL_PLATFORM_SNPRINTF_ALT)
|
|
|
|
#if !defined(POLARSSL_PLATFORM_STD_SNPRINTF)
|
|
|
|
/*
|
|
|
|
* Make dummy function to prevent NULL pointer dereferences
|
|
|
|
*/
|
|
|
|
static int platform_snprintf_uninit( char * s, size_t n,
|
|
|
|
const char * format, ... )
|
|
|
|
{
|
|
|
|
((void) s);
|
|
|
|
((void) n);
|
|
|
|
((void) format)
|
|
|
|
return( 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
#define POLARSSL_PLATFORM_STD_SNPRINTF platform_snprintf_uninit
|
|
|
|
#endif /* !POLARSSL_PLATFORM_STD_SNPRINTF */
|
|
|
|
|
|
|
|
int (*polarssl_snprintf)( char * s, size_t n,
|
|
|
|
const char * format,
|
|
|
|
... ) = POLARSSL_PLATFORM_STD_SNPRINTF;
|
|
|
|
|
|
|
|
int platform_set_snprintf( int (*snprintf_func)( char * s, size_t n,
|
|
|
|
const char * format,
|
|
|
|
... ) )
|
|
|
|
{
|
|
|
|
polarssl_snprintf = snprintf_func;
|
|
|
|
return( 0 );
|
|
|
|
}
|
|
|
|
#endif /* POLARSSL_PLATFORM_SNPRINTF_ALT */
|
|
|
|
|
2014-02-01 22:50:07 +01:00
|
|
|
#if defined(POLARSSL_PLATFORM_PRINTF_ALT)
|
|
|
|
#if !defined(POLARSSL_PLATFORM_STD_PRINTF)
|
|
|
|
/*
|
|
|
|
* Make dummy function to prevent NULL pointer dereferences
|
|
|
|
*/
|
|
|
|
static int platform_printf_uninit( const char *format, ... )
|
|
|
|
{
|
|
|
|
((void) format);
|
|
|
|
return( 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
#define POLARSSL_PLATFORM_STD_PRINTF platform_printf_uninit
|
|
|
|
#endif /* !POLARSSL_PLATFORM_STD_PRINTF */
|
|
|
|
|
|
|
|
int (*polarssl_printf)( const char *, ... ) = POLARSSL_PLATFORM_STD_PRINTF;
|
|
|
|
|
|
|
|
int platform_set_printf( int (*printf_func)( const char *, ... ) )
|
|
|
|
{
|
|
|
|
polarssl_printf = printf_func;
|
|
|
|
return( 0 );
|
|
|
|
}
|
|
|
|
#endif /* POLARSSL_PLATFORM_PRINTF_ALT */
|
|
|
|
|
|
|
|
#if defined(POLARSSL_PLATFORM_FPRINTF_ALT)
|
|
|
|
#if !defined(POLARSSL_PLATFORM_STD_FPRINTF)
|
|
|
|
/*
|
|
|
|
* Make dummy function to prevent NULL pointer dereferences
|
|
|
|
*/
|
|
|
|
static int platform_fprintf_uninit( FILE *stream, const char *format, ... )
|
|
|
|
{
|
|
|
|
((void) stream);
|
|
|
|
((void) format);
|
|
|
|
return( 0 );
|
|
|
|
}
|
|
|
|
|
2014-04-25 11:18:34 +02:00
|
|
|
#define POLARSSL_PLATFORM_STD_FPRINTF platform_fprintf_uninit
|
2014-02-01 22:50:07 +01:00
|
|
|
#endif /* !POLARSSL_PLATFORM_STD_FPRINTF */
|
|
|
|
|
|
|
|
int (*polarssl_fprintf)( FILE *, const char *, ... ) =
|
|
|
|
POLARSSL_PLATFORM_STD_FPRINTF;
|
|
|
|
|
|
|
|
int platform_set_fprintf( int (*fprintf_func)( FILE *, const char *, ... ) )
|
|
|
|
{
|
|
|
|
polarssl_fprintf = fprintf_func;
|
|
|
|
return( 0 );
|
|
|
|
}
|
|
|
|
#endif /* POLARSSL_PLATFORM_FPRINTF_ALT */
|
|
|
|
|
2015-01-30 13:01:34 +01:00
|
|
|
#if defined(POLARSSL_PLATFORM_EXIT_ALT)
|
|
|
|
#if !defined(POLARSSL_STD_EXIT)
|
|
|
|
/*
|
|
|
|
* Make dummy function to prevent NULL pointer dereferences
|
|
|
|
*/
|
|
|
|
static void platform_exit_uninit( int status )
|
|
|
|
{
|
|
|
|
((void) status);
|
|
|
|
return( 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
#define POLARSSL_STD_EXIT platform_exit_uninit
|
|
|
|
#endif /* !POLARSSL_STD_EXIT */
|
|
|
|
|
|
|
|
int (*polarssl_exit)( int status ) = POLARSSL_STD_EXIT;
|
|
|
|
|
|
|
|
int platform_set_exit( void (*exit_func)( int status ) )
|
|
|
|
{
|
|
|
|
polarssl_exit = exit_func;
|
|
|
|
return( 0 );
|
|
|
|
}
|
|
|
|
#endif /* POLARSSL_PLATFORM_EXIT_ALT */
|
|
|
|
|
2014-02-01 22:50:07 +01:00
|
|
|
#endif /* POLARSSL_PLATFORM_C */
|