1
0
mirror of https://github.com/Mbed-TLS/mbedtls.git synced 2025-07-29 11:41:15 +03:00

Migrated the Memory layer to the Platform layer

Deprecated POLARSSL_MEMORY_C and placed placeholder for memory.h to make
sure current code will not break on new version.
This commit is contained in:
Paul Bakker
2014-02-04 17:30:24 +01:00
parent b2f66c9158
commit defc0ca337
9 changed files with 199 additions and 183 deletions

View File

@ -32,7 +32,6 @@ set(src
md2.c
md4.c
md5.c
memory.c
memory_buffer_alloc.c
net.c
oid.c

View File

@ -46,7 +46,7 @@ OBJS= aes.o aesni.o arc4.o \
error.o gcm.o havege.o \
hmac_drbg.o \
md.o md_wrap.o md2.o \
md4.o md5.o memory.o \
md4.o md5.o \
memory_buffer_alloc.o net.o \
oid.o \
padlock.o pbkdf2.o pem.o \

View File

@ -1,63 +0,0 @@
/*
* Memory allocation layer
*
* Copyright (C) 2006-2013, Brainspark B.V.
*
* This file is part of PolarSSL (http://www.polarssl.org)
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
*
* All rights reserved.
*
* 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.
*/
#include "polarssl/config.h"
#if defined(POLARSSL_MEMORY_C)
#include "polarssl/memory.h"
#if !defined(POLARSSL_MEMORY_STDMALLOC)
static void *memory_malloc_uninit( size_t len )
{
((void) len);
return( NULL );
}
#define POLARSSL_MEMORY_STDMALLOC memory_malloc_uninit
#endif /* !POLARSSL_MEMORY_STDMALLOC */
#if !defined(POLARSSL_MEMORY_STDFREE)
static void memory_free_uninit( void *ptr )
{
((void) ptr);
}
#define POLARSSL_MEMORY_STDFREE memory_free_uninit
#endif /* !POLARSSL_MEMORY_STDFREE */
void * (*polarssl_malloc)( size_t ) = POLARSSL_MEMORY_STDMALLOC;
void (*polarssl_free)( void * ) = POLARSSL_MEMORY_STDFREE;
int memory_set_own( void * (*malloc_func)( size_t ),
void (*free_func)( void * ) )
{
polarssl_malloc = malloc_func;
polarssl_free = free_func;
return( 0 );
}
#endif /* POLARSSL_MEMORY_C */

View File

@ -25,9 +25,9 @@
#include "polarssl/config.h"
#if defined(POLARSSL_MEMORY_C) && defined(POLARSSL_MEMORY_BUFFER_ALLOC_C)
#if defined(POLARSSL_MEMORY_BUFFER_ALLOC_C)
#include "polarssl/memory.h"
#include "polarssl/memory_buffer_alloc.h"
#include <string.h>
@ -544,11 +544,10 @@ int memory_buffer_alloc_init( unsigned char *buf, size_t len )
#if defined(POLARSSL_THREADING_C)
polarssl_mutex_init( &heap.mutex );
polarssl_malloc = buffer_alloc_malloc_mutexed;
polarssl_free = buffer_alloc_free_mutexed;
platform_set_malloc_free( buffer_alloc_malloc_mutexed,
buffer_alloc_free_mutexed );
#else
polarssl_malloc = buffer_alloc_malloc;
polarssl_free = buffer_alloc_free;
platform_set_malloc_free( buffer_alloc_malloc, buffer_alloc_free );
#endif
heap.buf = buf;
@ -570,4 +569,4 @@ void memory_buffer_alloc_free()
memset( &heap, 0, sizeof(buffer_alloc_ctx) );
}
#endif /* POLARSSL_MEMORY_C && POLARSSL_MEMORY_BUFFER_ALLOC_C */
#endif /* POLARSSL_MEMORY_BUFFER_ALLOC_C */

View File

@ -29,6 +29,38 @@
#include "polarssl/platform.h"
#if defined(POLARSSL_PLATFORM_MEMORY)
#if !defined(POLARSSL_PLATFORM_STD_MALLOC)
static void *platform_malloc_uninit( size_t len )
{
((void) len);
return( NULL );
}
#define POLARSSL_PLATFORM_STD_MALLOC memory_malloc_uninit
#endif /* !POLARSSL_PLATFORM_STD_MALLOC */
#if !defined(POLARSSL_PLATFORM_STD_FREE)
static void platform_free_uninit( void *ptr )
{
((void) ptr);
}
#define POLARSSL_PLATFORM_STD_FREE memory_free_uninit
#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 */
#if defined(POLARSSL_PLATFORM_PRINTF_ALT)
#if !defined(POLARSSL_PLATFORM_STD_PRINTF)
/*