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