PolarSSL v1.3.1
memory.c
Go to the documentation of this file.
1 /*
2  * Memory allocation layer
3  *
4  * Copyright (C) 2006-2013, Brainspark B.V.
5  *
6  * This file is part of PolarSSL (http://www.polarssl.org)
7  * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
8  *
9  * All rights reserved.
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License along
22  * with this program; if not, write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24  */
25 
26 #include "polarssl/config.h"
27 
28 #if defined(POLARSSL_MEMORY_C)
29 
30 #include "polarssl/memory.h"
31 
32 #if !defined(POLARSSL_MEMORY_STDMALLOC)
33 static void *memory_malloc_uninit( size_t len )
34 {
35  ((void) len);
36  return( NULL );
37 }
38 
39 #define POLARSSL_MEMORY_STDMALLOC memory_malloc_uninit
40 #endif /* !POLARSSL_MEMORY_STDMALLOC */
41 
42 #if !defined(POLARSSL_MEMORY_STDFREE)
43 static void memory_free_uninit( void *ptr )
44 {
45  ((void) ptr);
46 }
47 
48 #define POLARSSL_MEMORY_STDFREE memory_free_uninit
49 #endif /* !POLARSSL_MEMORY_STDFREE */
50 
51 void * (*polarssl_malloc)( size_t ) = POLARSSL_MEMORY_STDMALLOC;
52 void (*polarssl_free)( void * ) = POLARSSL_MEMORY_STDFREE;
53 
54 int memory_set_own( void * (*malloc_func)( size_t ),
55  void (*free_func)( void * ) )
56 {
57  polarssl_malloc = malloc_func;
58  polarssl_free = free_func;
59 
60  return( 0 );
61 }
62 
63 #endif /* POLARSSL_MEMORY_C */
Memory allocation layer.
void *(* polarssl_malloc)(size_t len)
Configuration options (set of defines)
#define POLARSSL_MEMORY_STDFREE
Default free to use, can be undefined.
Definition: memory.h:38
void(* polarssl_free)(void *ptr)
#define POLARSSL_MEMORY_STDMALLOC
Default allocator to use, can be undefined.
Definition: memory.h:37
int memory_set_own(void *(*malloc_func)(size_t), void(*free_func)(void *))
Set your own memory implementation function pointers.