-
+ B48416427E71FE46868283490813E4D0A22DA9F4B17EFF706673A9B05380AE2D85EC9B183DB47EAA8AA197B7C7629EB873E63E5F8A66208BF230A794B6967FABmpi/include/memory.h(0 . 0)(1 . 105)
1410 /* memory.h - memory allocation
1411 * Copyright (C) 1998, 1999, 2000, 2001, 2005 Free Software Foundation, Inc.
1412 *
1413 * This file is part of GNUPG.
1414 *
1415 * GNUPG is free software; you can redistribute it and/or modify
1416 * it under the terms of the GNU General Public License as published by
1417 * the Free Software Foundation; either version 3 of the License, or
1418 * (at your option) any later version.
1419 *
1420 * GNUPG is distributed in the hope that it will be useful,
1421 * but WITHOUT ANY WARRANTY; without even the implied warranty of
1422 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1423 * GNU General Public License for more details.
1424 *
1425 * You should have received a copy of the GNU General Public License
1426 * along with this program; if not, see <http://www.gnu.org/licenses/>.
1427 */
1428
1429 #ifndef G10_MEMORY_H
1430 #define G10_MEMORY_H
1431
1432 #ifdef M_DEBUG
1433 #ifndef STR
1434 #define STR(v) #v
1435 #endif
1436 #ifndef __riscos__
1437 #define M_DBGINFO(a) __FUNCTION__ "["__FILE__ ":" STR(a) "]"
1438 #else /* __riscos__ */
1439 #define M_DBGINFO(a) "["__FILE__ ":" STR(a) "]"
1440 #endif /* __riscos__ */
1441 #define xmalloc(n) m_debug_alloc((n), M_DBGINFO( __LINE__ ) )
1442 #define xtrymalloc(n) m_debug_trymalloc ((n), M_DBGINFO( __LINE__ ))
1443 #define xmalloc_clear(n) m_debug_alloc_clear((n), M_DBGINFO(__LINE__) )
1444 #define xmalloc_secure(n) m_debug_alloc_secure(n), M_DBGINFO(__LINE__) )
1445 #define xmalloc_secure_clear(n) m_debug_alloc_secure_clear((n), M_DBGINFO(__LINE__) )
1446 #define xrealloc(n,m) m_debug_realloc((n),(m), M_DBGINFO(__LINE__) )
1447 #define xfree(n) m_debug_free((n), M_DBGINFO(__LINE__) )
1448 #define m_check(n) m_debug_check((n), M_DBGINFO(__LINE__) )
1449 /*#define m_copy(a) m_debug_copy((a), M_DBGINFO(__LINE__) )*/
1450 #define xstrdup(a) m_debug_strdup((a), M_DBGINFO(__LINE__) )
1451 #define xtrystrdup(a) m_debug_trystrdup((a), M_DBGINFO(__LINE__) )
1452
1453 void *m_debug_alloc( size_t n, const char *info );
1454 void *m_debug_trymalloc (size_t n, const char *info);
1455 void *m_debug_alloc_clear( size_t n, const char *info );
1456 void *m_debug_alloc_secure( size_t n, const char *info );
1457 void *m_debug_alloc_secure_clear( size_t n, const char *info );
1458 void *m_debug_realloc( void *a, size_t n, const char *info );
1459 void m_debug_free( void *p, const char *info );
1460 void m_debug_check( const void *a, const char *info );
1461 /*void *m_debug_copy( const void *a, const char *info );*/
1462 char *m_debug_strdup( const char *a, const char *info );
1463 char *m_debug_trystrdup (const char *a, const char *info);
1464
1465 #else
1466 void *xmalloc( size_t n );
1467 void *xtrymalloc (size_t n);
1468 void *xmalloc_clear( size_t n );
1469 void *xmalloc_secure( size_t n );
1470 void *xmalloc_secure_clear( size_t n );
1471 void *xrealloc( void *a, size_t n );
1472 void xfree( void *p );
1473 void m_check( const void *a );
1474 /*void *m_copy( const void *a );*/
1475 char *xstrdup( const char * a);
1476 char *xtrystrdup (const char *a);
1477 #endif
1478
1479 size_t m_size( const void *a );
1480 void m_print_stats(const char *prefix);
1481
1482 /* The follwing functions should be preferred over xmalloc_clear. */
1483 void *xcalloc (size_t n, size_t m);
1484 void *xcalloc_secure (size_t n, size_t m);
1485
1486
1487 /*-- secmem.c --*/
1488 int secmem_init( size_t npool );
1489 void secmem_term( void );
1490 void *secmem_malloc( size_t size );
1491 void *secmexrealloc( void *a, size_t newsize );
1492 void secmem_free( void *a );
1493 int m_is_secure( const void *p );
1494 void secmem_dump_stats(void);
1495 void secmem_set_flags( unsigned flags );
1496 unsigned secmem_get_flags(void);
1497
1498
1499 #define DBG_MEMORY memory_debug_mode
1500 #define DBG_MEMSTAT memory_stat_debug_mode
1501
1502 #ifndef EXTERN_UNLESS_MAIN_MODULE
1503 #if defined (__riscos__) && !defined (INCLUDED_BY_MAIN_MODULE)
1504 #define EXTERN_UNLESS_MAIN_MODULE extern
1505 #else
1506 #define EXTERN_UNLESS_MAIN_MODULE
1507 #endif
1508 #endif
1509 EXTERN_UNLESS_MAIN_MODULE int memory_debug_mode;
1510 EXTERN_UNLESS_MAIN_MODULE int memory_stat_debug_mode;
1511
1512
1513
1514 #endif /*G10_MEMORY_H*/