mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-03-31 19:20:26 +00:00
sm: track calloc/free in mbedtls
This commit is contained in:
parent
891bb64a19
commit
6643eff824
13
3rd-party/mbedtls/include/mbedtls/config.h
vendored
13
3rd-party/mbedtls/include/mbedtls/config.h
vendored
@ -32,6 +32,13 @@
|
||||
#define _CRT_SECURE_NO_DEPRECATE 1
|
||||
#endif
|
||||
|
||||
#define MBEDTLS_PLATFORM_STD_CALLOC btstack_calloc
|
||||
#define MBEDTLS_PLATFORM_STD_FREE btstack_free
|
||||
|
||||
#include <stddef.h>
|
||||
void * btstack_calloc(size_t count, size_t size);
|
||||
void btstack_free(void * data);
|
||||
|
||||
/**
|
||||
* \name SECTION: System support
|
||||
*
|
||||
@ -73,7 +80,7 @@
|
||||
*
|
||||
* Comment if your system does not support time functions
|
||||
*/
|
||||
#define MBEDTLS_HAVE_TIME
|
||||
// #define MBEDTLS_HAVE_TIME
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_HAVE_TIME_DATE
|
||||
@ -85,7 +92,7 @@
|
||||
*
|
||||
* Comment if your system does not have a correct clock.
|
||||
*/
|
||||
#define MBEDTLS_HAVE_TIME_DATE
|
||||
// #define MBEDTLS_HAVE_TIME_DATE
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_PLATFORM_MEMORY
|
||||
@ -109,7 +116,7 @@
|
||||
*
|
||||
* Enable this layer to allow use of alternative memory allocators.
|
||||
*/
|
||||
//#define MBEDTLS_PLATFORM_MEMORY
|
||||
#define MBEDTLS_PLATFORM_MEMORY
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
|
||||
|
193
3rd-party/mbedtls/library/platform.c
vendored
Normal file
193
3rd-party/mbedtls/library/platform.c
vendored
Normal file
@ -0,0 +1,193 @@
|
||||
/*
|
||||
* Platform abstraction layer
|
||||
*
|
||||
* Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* This file is part of mbed TLS (https://tls.mbed.org)
|
||||
*/
|
||||
|
||||
#if !defined(MBEDTLS_CONFIG_FILE)
|
||||
#include "mbedtls/config.h"
|
||||
#else
|
||||
#include MBEDTLS_CONFIG_FILE
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
|
||||
#include "mbedtls/platform.h"
|
||||
|
||||
#if defined(MBEDTLS_PLATFORM_MEMORY)
|
||||
#if !defined(MBEDTLS_PLATFORM_STD_CALLOC)
|
||||
static void *platform_calloc_uninit( size_t n, size_t size )
|
||||
{
|
||||
((void) n);
|
||||
((void) size);
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
#define MBEDTLS_PLATFORM_STD_CALLOC platform_calloc_uninit
|
||||
#endif /* !MBEDTLS_PLATFORM_STD_CALLOC */
|
||||
|
||||
#if !defined(MBEDTLS_PLATFORM_STD_FREE)
|
||||
static void platform_free_uninit( void *ptr )
|
||||
{
|
||||
((void) ptr);
|
||||
}
|
||||
|
||||
#define MBEDTLS_PLATFORM_STD_FREE platform_free_uninit
|
||||
#endif /* !MBEDTLS_PLATFORM_STD_FREE */
|
||||
|
||||
void * (*mbedtls_calloc)( size_t, size_t ) = MBEDTLS_PLATFORM_STD_CALLOC;
|
||||
void (*mbedtls_free)( void * ) = MBEDTLS_PLATFORM_STD_FREE;
|
||||
|
||||
int mbedtls_platform_set_calloc_free( void * (*calloc_func)( size_t, size_t ),
|
||||
void (*free_func)( void * ) )
|
||||
{
|
||||
mbedtls_calloc = calloc_func;
|
||||
mbedtls_free = free_func;
|
||||
return( 0 );
|
||||
}
|
||||
#endif /* MBEDTLS_PLATFORM_MEMORY */
|
||||
|
||||
#if defined(_WIN32)
|
||||
#include <stdarg.h>
|
||||
int mbedtls_platform_win32_snprintf( char *s, size_t n, const char *fmt, ... )
|
||||
{
|
||||
int ret;
|
||||
va_list argp;
|
||||
|
||||
/* Avoid calling the invalid parameter handler by checking ourselves */
|
||||
if( s == NULL || n == 0 || fmt == NULL )
|
||||
return( -1 );
|
||||
|
||||
va_start( argp, fmt );
|
||||
#if defined(_TRUNCATE)
|
||||
ret = _vsnprintf_s( s, n, _TRUNCATE, fmt, argp );
|
||||
#else
|
||||
ret = _vsnprintf( s, n, fmt, argp );
|
||||
if( ret < 0 || (size_t) ret == n )
|
||||
{
|
||||
s[n-1] = '\0';
|
||||
ret = -1;
|
||||
}
|
||||
#endif
|
||||
va_end( argp );
|
||||
|
||||
return( ret );
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_PLATFORM_SNPRINTF_ALT)
|
||||
#if !defined(MBEDTLS_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 MBEDTLS_PLATFORM_STD_SNPRINTF platform_snprintf_uninit
|
||||
#endif /* !MBEDTLS_PLATFORM_STD_SNPRINTF */
|
||||
|
||||
int (*mbedtls_snprintf)( char * s, size_t n,
|
||||
const char * format,
|
||||
... ) = MBEDTLS_PLATFORM_STD_SNPRINTF;
|
||||
|
||||
int mbedtls_platform_set_snprintf( int (*snprintf_func)( char * s, size_t n,
|
||||
const char * format,
|
||||
... ) )
|
||||
{
|
||||
mbedtls_snprintf = snprintf_func;
|
||||
return( 0 );
|
||||
}
|
||||
#endif /* MBEDTLS_PLATFORM_SNPRINTF_ALT */
|
||||
|
||||
#if defined(MBEDTLS_PLATFORM_PRINTF_ALT)
|
||||
#if !defined(MBEDTLS_PLATFORM_STD_PRINTF)
|
||||
/*
|
||||
* Make dummy function to prevent NULL pointer dereferences
|
||||
*/
|
||||
static int platform_printf_uninit( const char *format, ... )
|
||||
{
|
||||
((void) format);
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
#define MBEDTLS_PLATFORM_STD_PRINTF platform_printf_uninit
|
||||
#endif /* !MBEDTLS_PLATFORM_STD_PRINTF */
|
||||
|
||||
int (*mbedtls_printf)( const char *, ... ) = MBEDTLS_PLATFORM_STD_PRINTF;
|
||||
|
||||
int mbedtls_platform_set_printf( int (*printf_func)( const char *, ... ) )
|
||||
{
|
||||
mbedtls_printf = printf_func;
|
||||
return( 0 );
|
||||
}
|
||||
#endif /* MBEDTLS_PLATFORM_PRINTF_ALT */
|
||||
|
||||
#if defined(MBEDTLS_PLATFORM_FPRINTF_ALT)
|
||||
#if !defined(MBEDTLS_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 );
|
||||
}
|
||||
|
||||
#define MBEDTLS_PLATFORM_STD_FPRINTF platform_fprintf_uninit
|
||||
#endif /* !MBEDTLS_PLATFORM_STD_FPRINTF */
|
||||
|
||||
int (*mbedtls_fprintf)( FILE *, const char *, ... ) =
|
||||
MBEDTLS_PLATFORM_STD_FPRINTF;
|
||||
|
||||
int mbedtls_platform_set_fprintf( int (*fprintf_func)( FILE *, const char *, ... ) )
|
||||
{
|
||||
mbedtls_fprintf = fprintf_func;
|
||||
return( 0 );
|
||||
}
|
||||
#endif /* MBEDTLS_PLATFORM_FPRINTF_ALT */
|
||||
|
||||
#if defined(MBEDTLS_PLATFORM_EXIT_ALT)
|
||||
#if !defined(MBEDTLS_PLATFORM_STD_EXIT)
|
||||
/*
|
||||
* Make dummy function to prevent NULL pointer dereferences
|
||||
*/
|
||||
static void platform_exit_uninit( int status )
|
||||
{
|
||||
((void) status);
|
||||
}
|
||||
|
||||
#define MBEDTLS_PLATFORM_STD_EXIT platform_exit_uninit
|
||||
#endif /* !MBEDTLS_PLATFORM_STD_EXIT */
|
||||
|
||||
void (*mbedtls_exit)( int status ) = MBEDTLS_PLATFORM_STD_EXIT;
|
||||
|
||||
int mbedtls_platform_set_exit( void (*exit_func)( int status ) )
|
||||
{
|
||||
mbedtls_exit = exit_func;
|
||||
return( 0 );
|
||||
}
|
||||
#endif /* MBEDTLS_PLATFORM_EXIT_ALT */
|
||||
|
||||
#endif /* MBEDTLS_PLATFORM_C */
|
@ -63,6 +63,7 @@ MBEDTLS = \
|
||||
bignum.c \
|
||||
ecp.c \
|
||||
ecp_curves.c \
|
||||
platform.c \
|
||||
|
||||
EXAMPLES = \
|
||||
ancs_client_demo \
|
||||
|
@ -71,6 +71,15 @@
|
||||
#include "mbedtls/ecp.h"
|
||||
#endif
|
||||
|
||||
void * btstack_calloc(size_t count, size_t size){
|
||||
void * result = calloc(count, size);
|
||||
printf("btstack_calloc(%zu, %zu) -> res %p\n", count, size, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
void btstack_free(void * data){
|
||||
printf("btstack_free(%p)\n", data);
|
||||
}
|
||||
//
|
||||
// SM internal types and globals
|
||||
//
|
||||
|
Loading…
x
Reference in New Issue
Block a user