raw
ch1_mpi                 1 /* memory.h - memory allocation
ch1_mpi 2 * Modified by No Such Labs. (C) 2015. See README.
ch1_mpi 3 *
ch1_mpi 4 * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10,
ch1_mpi 5 * SHA256(gnupg-1.4.10.tar.gz):
ch1_mpi 6 * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a
ch1_mpi 7 * (C) 1994-2005 Free Software Foundation, Inc.
ch1_mpi 8 *
ch1_mpi 9 * This program is free software: you can redistribute it and/or modify
ch1_mpi 10 * it under the terms of the GNU General Public License as published by
ch1_mpi 11 * the Free Software Foundation, either version 3 of the License, or
ch1_mpi 12 * (at your option) any later version.
ch1_mpi 13 *
ch1_mpi 14 * This program is distributed in the hope that it will be useful,
ch1_mpi 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ch1_mpi 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ch1_mpi 17 * GNU General Public License for more details.
ch1_mpi 18 *
ch1_mpi 19 * You should have received a copy of the GNU General Public License
ch1_mpi 20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
ch1_mpi 21 */
ch1_mpi 22
ch1_mpi 23 #ifndef G10_MEMORY_H
ch1_mpi 24 #define G10_MEMORY_H
ch1_mpi 25
ch1_mpi 26 #ifdef M_DEBUG
ch1_mpi 27
ch1_mpi 28 #ifndef STR
ch1_mpi 29 #define STR(v) #v
ch1_mpi 30 #endif
ch1_mpi 31
ch1_mpi 32 #define M_DBGINFO(a) __FUNCTION__ "["__FILE__ ":" STR(a) "]"
ch1_mpi 33
ch1_mpi 34 #define xmalloc(n) m_debug_alloc((n), M_DBGINFO( __LINE__ ) )
ch1_mpi 35 #define xtrymalloc(n) m_debug_trymalloc ((n), M_DBGINFO( __LINE__ ))
ch1_mpi 36 #define xmalloc_clear(n) m_debug_alloc_clear((n), M_DBGINFO(__LINE__) )
ch1_mpi 37 #define xmalloc_secure(n) m_debug_alloc_secure(n), M_DBGINFO(__LINE__) )
ch1_mpi 38 #define xmalloc_secure_clear(n) m_debug_alloc_secure_clear((n), M_DBGINFO(__LINE__) )
ch1_mpi 39 #define xrealloc(n,m) m_debug_realloc((n),(m), M_DBGINFO(__LINE__) )
ch1_mpi 40 #define xfree(n) m_debug_free((n), M_DBGINFO(__LINE__) )
ch1_mpi 41 #define m_check(n) m_debug_check((n), M_DBGINFO(__LINE__) )
ch1_mpi 42 /*#define m_copy(a) m_debug_copy((a), M_DBGINFO(__LINE__) )*/
ch1_mpi 43 #define xstrdup(a) m_debug_strdup((a), M_DBGINFO(__LINE__) )
ch1_mpi 44 #define xtrystrdup(a) m_debug_trystrdup((a), M_DBGINFO(__LINE__) )
ch1_mpi 45
ch1_mpi 46 void *m_debug_alloc( size_t n, const char *info );
ch1_mpi 47 void *m_debug_trymalloc (size_t n, const char *info);
ch1_mpi 48 void *m_debug_alloc_clear( size_t n, const char *info );
ch1_mpi 49 void *m_debug_alloc_secure( size_t n, const char *info );
ch1_mpi 50 void *m_debug_alloc_secure_clear( size_t n, const char *info );
ch1_mpi 51 void *m_debug_realloc( void *a, size_t n, const char *info );
ch1_mpi 52 void m_debug_free( void *p, const char *info );
ch1_mpi 53 void m_debug_check( const void *a, const char *info );
ch1_mpi 54 /*void *m_debug_copy( const void *a, const char *info );*/
ch1_mpi 55 char *m_debug_strdup( const char *a, const char *info );
ch1_mpi 56 char *m_debug_trystrdup (const char *a, const char *info);
ch1_mpi 57
ch1_mpi 58 #else
ch1_mpi 59 void *xmalloc( size_t n );
ch1_mpi 60 void *xtrymalloc (size_t n);
ch1_mpi 61 void *xmalloc_clear( size_t n );
ch1_mpi 62 void *xmalloc_secure( size_t n );
ch1_mpi 63 void *xmalloc_secure_clear( size_t n );
ch1_mpi 64 void *xrealloc( void *a, size_t n );
ch1_mpi 65 void xfree( void *p );
ch1_mpi 66 void m_check( const void *a );
ch1_mpi 67 /*void *m_copy( const void *a );*/
ch1_mpi 68 char *xstrdup( const char * a);
ch1_mpi 69 char *xtrystrdup (const char *a);
ch1_mpi 70 #endif
ch1_mpi 71
ch1_mpi 72 size_t m_size( const void *a );
ch1_mpi 73 void m_print_stats(const char *prefix);
ch1_mpi 74
ch1_mpi 75 /* The follwing functions should be preferred over xmalloc_clear. */
ch1_mpi 76 void *xcalloc (size_t n, size_t m);
ch1_mpi 77 void *xcalloc_secure (size_t n, size_t m);
ch1_mpi 78
ch1_mpi 79
ch1_mpi 80 /*-- secmem.c --*/
ch1_mpi 81 int secmem_init( size_t npool );
ch1_mpi 82 void secmem_term( void );
ch1_mpi 83 void *secmem_malloc( size_t size );
ch1_mpi 84 void *secmexrealloc( void *a, size_t newsize );
ch1_mpi 85 void secmem_free( void *a );
ch1_mpi 86 int m_is_secure( const void *p );
ch1_mpi 87 void secmem_dump_stats(void);
ch1_mpi 88 void secmem_set_flags( unsigned flags );
ch1_mpi 89 unsigned secmem_get_flags(void);
ch1_mpi 90
ch1_mpi 91
ch1_mpi 92 #define DBG_MEMORY memory_debug_mode
ch1_mpi 93 #define DBG_MEMSTAT memory_stat_debug_mode
ch1_mpi 94
ch1_mpi 95 #ifndef EXTERN_UNLESS_MAIN_MODULE
ch1_mpi 96 #define EXTERN_UNLESS_MAIN_MODULE
ch1_mpi 97 #endif
ch1_mpi 98 EXTERN_UNLESS_MAIN_MODULE int memory_debug_mode;
ch1_mpi 99 EXTERN_UNLESS_MAIN_MODULE int memory_stat_debug_mode;
ch1_mpi 100
ch1_mpi 101
ch1_mpi 102
ch1_mpi 103 #endif /*G10_MEMORY_H*/