2002-06-29 13:31:13 +00:00
|
|
|
/* memory.h - memory allocation
|
2005-04-05 17:09:13 +00:00
|
|
|
* Copyright (C) 1998, 1999, 2000, 2001, 2005 Free Software Foundation, Inc.
|
2002-06-29 13:31:13 +00:00
|
|
|
*
|
|
|
|
* This file is part of GNUPG.
|
|
|
|
*
|
|
|
|
* GNUPG is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
2007-10-23 10:48:09 +00:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2002-06-29 13:31:13 +00:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* GNUPG 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
|
2007-10-23 10:48:09 +00:00
|
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
2002-06-29 13:31:13 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef G10_MEMORY_H
|
|
|
|
#define G10_MEMORY_H
|
|
|
|
|
|
|
|
#ifdef M_DEBUG
|
|
|
|
#ifndef STR
|
2003-05-24 16:40:46 +00:00
|
|
|
#define STR(v) #v
|
2002-06-29 13:31:13 +00:00
|
|
|
#endif
|
|
|
|
#ifndef __riscos__
|
2003-05-24 16:40:46 +00:00
|
|
|
#define M_DBGINFO(a) __FUNCTION__ "["__FILE__ ":" STR(a) "]"
|
2002-06-29 13:31:13 +00:00
|
|
|
#else /* __riscos__ */
|
2003-05-24 16:40:46 +00:00
|
|
|
#define M_DBGINFO(a) "["__FILE__ ":" STR(a) "]"
|
2002-06-29 13:31:13 +00:00
|
|
|
#endif /* __riscos__ */
|
2005-07-27 18:10:56 +00:00
|
|
|
#define xmalloc(n) m_debug_alloc((n), M_DBGINFO( __LINE__ ) )
|
2009-07-21 14:30:13 +00:00
|
|
|
#define xtrymalloc(n) m_debug_trymalloc ((n), M_DBGINFO( __LINE__ ))
|
2005-07-27 18:10:56 +00:00
|
|
|
#define xmalloc_clear(n) m_debug_alloc_clear((n), M_DBGINFO(__LINE__) )
|
|
|
|
#define xmalloc_secure(n) m_debug_alloc_secure(n), M_DBGINFO(__LINE__) )
|
|
|
|
#define xmalloc_secure_clear(n) m_debug_alloc_secure_clear((n), M_DBGINFO(__LINE__) )
|
|
|
|
#define xrealloc(n,m) m_debug_realloc((n),(m), M_DBGINFO(__LINE__) )
|
|
|
|
#define xfree(n) m_debug_free((n), M_DBGINFO(__LINE__) )
|
2002-06-29 13:31:13 +00:00
|
|
|
#define m_check(n) m_debug_check((n), M_DBGINFO(__LINE__) )
|
|
|
|
/*#define m_copy(a) m_debug_copy((a), M_DBGINFO(__LINE__) )*/
|
2005-07-27 18:10:56 +00:00
|
|
|
#define xstrdup(a) m_debug_strdup((a), M_DBGINFO(__LINE__) )
|
2009-07-21 14:30:13 +00:00
|
|
|
#define xtrystrdup(a) m_debug_trystrdup((a), M_DBGINFO(__LINE__) )
|
2002-06-29 13:31:13 +00:00
|
|
|
|
|
|
|
void *m_debug_alloc( size_t n, const char *info );
|
2009-07-21 14:30:13 +00:00
|
|
|
void *m_debug_trymalloc (size_t n, const char *info);
|
2002-06-29 13:31:13 +00:00
|
|
|
void *m_debug_alloc_clear( size_t n, const char *info );
|
|
|
|
void *m_debug_alloc_secure( size_t n, const char *info );
|
|
|
|
void *m_debug_alloc_secure_clear( size_t n, const char *info );
|
|
|
|
void *m_debug_realloc( void *a, size_t n, const char *info );
|
|
|
|
void m_debug_free( void *p, const char *info );
|
|
|
|
void m_debug_check( const void *a, const char *info );
|
|
|
|
/*void *m_debug_copy( const void *a, const char *info );*/
|
|
|
|
char *m_debug_strdup( const char *a, const char *info );
|
2009-07-21 14:30:13 +00:00
|
|
|
char *m_debug_trystrdup (const char *a, const char *info);
|
2002-06-29 13:31:13 +00:00
|
|
|
|
|
|
|
#else
|
2005-07-27 18:10:56 +00:00
|
|
|
void *xmalloc( size_t n );
|
2009-07-21 14:30:13 +00:00
|
|
|
void *xtrymalloc (size_t n);
|
2005-07-27 18:10:56 +00:00
|
|
|
void *xmalloc_clear( size_t n );
|
|
|
|
void *xmalloc_secure( size_t n );
|
|
|
|
void *xmalloc_secure_clear( size_t n );
|
|
|
|
void *xrealloc( void *a, size_t n );
|
|
|
|
void xfree( void *p );
|
2002-06-29 13:31:13 +00:00
|
|
|
void m_check( const void *a );
|
|
|
|
/*void *m_copy( const void *a );*/
|
2005-07-27 18:10:56 +00:00
|
|
|
char *xstrdup( const char * a);
|
2009-07-21 14:30:13 +00:00
|
|
|
char *xtrystrdup (const char *a);
|
2002-06-29 13:31:13 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
size_t m_size( const void *a );
|
|
|
|
void m_print_stats(const char *prefix);
|
|
|
|
|
2005-07-27 18:10:56 +00:00
|
|
|
/* The follwing functions should be preferred over xmalloc_clear. */
|
|
|
|
void *xcalloc (size_t n, size_t m);
|
|
|
|
void *xcalloc_secure (size_t n, size_t m);
|
|
|
|
|
|
|
|
|
2002-06-29 13:31:13 +00:00
|
|
|
/*-- secmem.c --*/
|
2004-12-16 05:16:09 +00:00
|
|
|
int secmem_init( size_t npool );
|
2002-06-29 13:31:13 +00:00
|
|
|
void secmem_term( void );
|
|
|
|
void *secmem_malloc( size_t size );
|
2005-07-27 18:10:56 +00:00
|
|
|
void *secmexrealloc( void *a, size_t newsize );
|
2002-06-29 13:31:13 +00:00
|
|
|
void secmem_free( void *a );
|
|
|
|
int m_is_secure( const void *p );
|
|
|
|
void secmem_dump_stats(void);
|
|
|
|
void secmem_set_flags( unsigned flags );
|
|
|
|
unsigned secmem_get_flags(void);
|
|
|
|
|
|
|
|
|
|
|
|
#define DBG_MEMORY memory_debug_mode
|
|
|
|
#define DBG_MEMSTAT memory_stat_debug_mode
|
|
|
|
|
|
|
|
#ifndef EXTERN_UNLESS_MAIN_MODULE
|
2021-08-27 10:17:19 +09:00
|
|
|
#if !defined (INCLUDED_BY_MAIN_MODULE)
|
2003-05-24 16:40:46 +00:00
|
|
|
#define EXTERN_UNLESS_MAIN_MODULE extern
|
|
|
|
#else
|
|
|
|
#define EXTERN_UNLESS_MAIN_MODULE
|
|
|
|
#endif
|
2002-06-29 13:31:13 +00:00
|
|
|
#endif
|
|
|
|
EXTERN_UNLESS_MAIN_MODULE int memory_debug_mode;
|
|
|
|
EXTERN_UNLESS_MAIN_MODULE int memory_stat_debug_mode;
|
|
|
|
|
2003-09-27 19:37:53 +00:00
|
|
|
|
|
|
|
|
2002-06-29 13:31:13 +00:00
|
|
|
#endif /*G10_MEMORY_H*/
|