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