1998-01-28 16:09:43 +00:00
|
|
|
/* secmem.c - memory allocation from a secure heap
|
2001-04-29 14:08:29 +00:00
|
|
|
* Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc.
|
1998-01-28 16:09:43 +00:00
|
|
|
*
|
1998-12-23 12:41:40 +00:00
|
|
|
* This file is part of GnuPG.
|
1998-01-28 16:09:43 +00:00
|
|
|
*
|
1998-12-23 12:41:40 +00:00
|
|
|
* GnuPG is free software; you can redistribute it and/or modify
|
1998-01-28 16:09:43 +00:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
1998-12-23 12:41:40 +00:00
|
|
|
* GnuPG is distributed in the hope that it will be useful,
|
1998-01-28 16:09:43 +00:00
|
|
|
* 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
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdarg.h>
|
1998-12-29 13:47:31 +00:00
|
|
|
#include <unistd.h>
|
1998-01-28 16:09:43 +00:00
|
|
|
#if defined(HAVE_MLOCK) || defined(HAVE_MMAP)
|
|
|
|
#include <sys/mman.h>
|
|
|
|
#include <sys/types.h>
|
1998-09-14 15:49:56 +00:00
|
|
|
#include <fcntl.h>
|
1999-06-29 19:50:54 +00:00
|
|
|
#ifdef USE_CAPABILITIES
|
|
|
|
#include <sys/capability.h>
|
|
|
|
#endif
|
2001-08-20 19:10:34 +00:00
|
|
|
#ifdef HAVE_PLOCK
|
|
|
|
#include <sys/lock.h>
|
|
|
|
#endif
|
1998-01-28 16:09:43 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "types.h"
|
|
|
|
#include "memory.h"
|
|
|
|
#include "util.h"
|
1998-02-09 17:43:42 +00:00
|
|
|
#include "i18n.h"
|
1998-01-28 16:09:43 +00:00
|
|
|
|
1998-08-05 16:51:59 +00:00
|
|
|
#if defined(MAP_ANON) && !defined(MAP_ANONYMOUS)
|
|
|
|
#define MAP_ANONYMOUS MAP_ANON
|
|
|
|
#endif
|
2001-05-25 07:22:34 +00:00
|
|
|
/* It seems that Slackware 7.1 does not know about EPERM */
|
|
|
|
#if !defined(EPERM) && defined(ENOMEM)
|
|
|
|
#define EPERM ENOMEM
|
|
|
|
#endif
|
|
|
|
|
1998-01-28 16:09:43 +00:00
|
|
|
|
1999-06-26 10:23:06 +00:00
|
|
|
#define DEFAULT_POOLSIZE 16384
|
1998-01-28 16:09:43 +00:00
|
|
|
|
|
|
|
typedef struct memblock_struct MEMBLOCK;
|
|
|
|
struct memblock_struct {
|
|
|
|
unsigned size;
|
|
|
|
union {
|
|
|
|
MEMBLOCK *next;
|
1999-02-26 16:59:48 +00:00
|
|
|
PROPERLY_ALIGNED_TYPE aligned;
|
1998-01-28 16:09:43 +00:00
|
|
|
} u;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void *pool;
|
1999-08-30 18:48:57 +00:00
|
|
|
static volatile int pool_okay; /* may be checked in an atexit function */
|
1999-11-22 10:10:27 +00:00
|
|
|
static volatile int pool_is_mmapped;
|
1998-01-28 16:09:43 +00:00
|
|
|
static size_t poolsize; /* allocated length */
|
|
|
|
static size_t poollen; /* used length */
|
|
|
|
static MEMBLOCK *unused_blocks;
|
|
|
|
static unsigned max_alloced;
|
|
|
|
static unsigned cur_alloced;
|
|
|
|
static unsigned max_blocks;
|
|
|
|
static unsigned cur_blocks;
|
1998-02-02 14:36:06 +00:00
|
|
|
static int disable_secmem;
|
1998-02-11 23:22:09 +00:00
|
|
|
static int show_warning;
|
|
|
|
static int no_warning;
|
1998-09-28 19:25:31 +00:00
|
|
|
static int suspend_warning;
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
1999-02-16 13:16:33 +00:00
|
|
|
print_warn(void)
|
1998-09-28 19:25:31 +00:00
|
|
|
{
|
2002-01-08 19:29:35 +00:00
|
|
|
if (!no_warning)
|
|
|
|
{
|
|
|
|
log_info(_("Warning: using insecure memory!\n"));
|
|
|
|
log_info(_("please see http://www.gnupg.org/faq.html "
|
|
|
|
"for more information\n"));
|
|
|
|
}
|
1998-09-28 19:25:31 +00:00
|
|
|
}
|
|
|
|
|
1998-01-28 16:09:43 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
lock_pool( void *p, size_t n )
|
|
|
|
{
|
1999-06-29 19:50:54 +00:00
|
|
|
#if defined(USE_CAPABILITIES) && defined(HAVE_MLOCK)
|
|
|
|
int err;
|
|
|
|
|
|
|
|
cap_set_proc( cap_from_text("cap_ipc_lock+ep") );
|
|
|
|
err = mlock( p, n );
|
|
|
|
if( err && errno )
|
|
|
|
err = errno;
|
|
|
|
cap_set_proc( cap_from_text("cap_ipc_lock+p") );
|
|
|
|
|
|
|
|
if( err ) {
|
|
|
|
if( errno != EPERM
|
|
|
|
#ifdef EAGAIN /* OpenBSD returns this */
|
|
|
|
&& errno != EAGAIN
|
|
|
|
#endif
|
1999-09-17 10:58:20 +00:00
|
|
|
#ifdef ENOSYS /* Some SCOs return this (function not implemented) */
|
|
|
|
&& errno != ENOSYS
|
|
|
|
#endif
|
2000-10-17 12:41:51 +00:00
|
|
|
#ifdef ENOMEM /* Linux can return this */
|
|
|
|
&& errno != ENOMEM
|
|
|
|
#endif
|
1999-06-29 19:50:54 +00:00
|
|
|
)
|
1999-09-17 10:58:20 +00:00
|
|
|
log_error("can't lock memory: %s\n", strerror(err));
|
1999-06-29 19:50:54 +00:00
|
|
|
show_warning = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
#elif defined(HAVE_MLOCK)
|
1998-01-28 16:09:43 +00:00
|
|
|
uid_t uid;
|
|
|
|
int err;
|
|
|
|
|
1998-09-18 15:24:53 +00:00
|
|
|
uid = getuid();
|
|
|
|
|
|
|
|
#ifdef HAVE_BROKEN_MLOCK
|
2001-08-20 19:10:34 +00:00
|
|
|
/* ick. but at least we get secured memory. about to lock
|
|
|
|
entire data segment. */
|
|
|
|
#ifdef HAVE_PLOCK
|
|
|
|
err = plock( DATLOCK );
|
|
|
|
if( err && errno )
|
|
|
|
err = errno;
|
|
|
|
#else /*!HAVE_PLOCK*/
|
1998-09-28 19:25:31 +00:00
|
|
|
if( uid ) {
|
|
|
|
errno = EPERM;
|
|
|
|
err = errno;
|
|
|
|
}
|
1998-09-18 15:24:53 +00:00
|
|
|
else {
|
|
|
|
err = mlock( p, n );
|
|
|
|
if( err && errno )
|
|
|
|
err = errno;
|
|
|
|
}
|
2001-08-20 19:10:34 +00:00
|
|
|
#endif /*!HAVE_PLOCK*/
|
1998-09-18 15:24:53 +00:00
|
|
|
#else
|
1998-06-26 09:45:36 +00:00
|
|
|
err = mlock( p, n );
|
1998-01-28 16:09:43 +00:00
|
|
|
if( err && errno )
|
|
|
|
err = errno;
|
1998-09-18 15:24:53 +00:00
|
|
|
#endif
|
1998-01-28 16:09:43 +00:00
|
|
|
|
|
|
|
if( uid && !geteuid() ) {
|
2000-06-08 18:08:06 +00:00
|
|
|
/* check that we really dropped the privs.
|
|
|
|
* Note: setuid(0) should always fail */
|
|
|
|
if( setuid( uid ) || getuid() != geteuid() || !setuid(0) )
|
1998-01-28 16:09:43 +00:00
|
|
|
log_fatal("failed to reset uid: %s\n", strerror(errno));
|
|
|
|
}
|
|
|
|
|
|
|
|
if( err ) {
|
1998-02-26 16:56:31 +00:00
|
|
|
if( errno != EPERM
|
|
|
|
#ifdef EAGAIN /* OpenBSD returns this */
|
|
|
|
&& errno != EAGAIN
|
|
|
|
#endif
|
1999-09-17 10:58:20 +00:00
|
|
|
#ifdef ENOSYS /* Some SCOs return this (function not implemented) */
|
|
|
|
&& errno != ENOSYS
|
|
|
|
#endif
|
2000-10-17 12:41:51 +00:00
|
|
|
#ifdef ENOMEM /* Linux can return this */
|
|
|
|
&& errno != ENOMEM
|
|
|
|
#endif
|
1998-02-26 16:56:31 +00:00
|
|
|
)
|
1999-09-17 10:58:20 +00:00
|
|
|
log_error("can't lock memory: %s\n", strerror(err));
|
1998-02-11 23:22:09 +00:00
|
|
|
show_warning = 1;
|
1998-01-28 16:09:43 +00:00
|
|
|
}
|
|
|
|
|
2000-03-07 17:43:06 +00:00
|
|
|
#elif defined ( __QNX__ )
|
|
|
|
/* QNX does not page at all, so the whole secure memory stuff does
|
|
|
|
* not make much sense. However it is still of use because it
|
|
|
|
* wipes out the memory on a free().
|
|
|
|
* Therefore it is sufficient to suppress the warning
|
|
|
|
*/
|
2000-10-23 16:38:27 +00:00
|
|
|
#elif defined (HAVE_DOSISH_SYSTEM)
|
|
|
|
/* It does not make sense to print such a warning, given the fact that
|
|
|
|
* this whole Windows !@#$% and their user base are inherently insecure
|
|
|
|
*/
|
2001-08-20 11:53:05 +00:00
|
|
|
#elif defined (__riscos__)
|
|
|
|
/* no virtual memory on RISC OS, so no pages are swapped to disc,
|
|
|
|
* besides we don't have mmap, so we don't use it! ;-)
|
|
|
|
* But don't complain, as explained above.
|
|
|
|
*/
|
1998-01-28 16:09:43 +00:00
|
|
|
#else
|
1998-02-24 18:50:46 +00:00
|
|
|
log_info("Please note that you don't have secure memory on this system\n");
|
1998-01-28 16:09:43 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
init_pool( size_t n)
|
|
|
|
{
|
1998-09-14 15:49:56 +00:00
|
|
|
size_t pgsize;
|
|
|
|
|
1998-01-28 16:09:43 +00:00
|
|
|
poolsize = n;
|
|
|
|
|
1998-02-02 14:36:06 +00:00
|
|
|
if( disable_secmem )
|
|
|
|
log_bug("secure memory is disabled");
|
|
|
|
|
1998-09-14 15:49:56 +00:00
|
|
|
#ifdef HAVE_GETPAGESIZE
|
|
|
|
pgsize = getpagesize();
|
|
|
|
#else
|
|
|
|
pgsize = 4096;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if HAVE_MMAP
|
|
|
|
poolsize = (poolsize + pgsize -1 ) & ~(pgsize-1);
|
|
|
|
#ifdef MAP_ANONYMOUS
|
|
|
|
pool = mmap( 0, poolsize, PROT_READ|PROT_WRITE,
|
|
|
|
MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
|
|
|
|
#else /* map /dev/zero instead */
|
|
|
|
{ int fd;
|
|
|
|
|
|
|
|
fd = open("/dev/zero", O_RDWR);
|
|
|
|
if( fd == -1 ) {
|
|
|
|
log_error("can't open /dev/zero: %s\n", strerror(errno) );
|
|
|
|
pool = (void*)-1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
pool = mmap( 0, poolsize, PROT_READ|PROT_WRITE,
|
|
|
|
MAP_PRIVATE, fd, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
1998-01-28 16:09:43 +00:00
|
|
|
if( pool == (void*)-1 )
|
1998-10-06 12:10:02 +00:00
|
|
|
log_info("can't mmap pool of %u bytes: %s - using malloc\n",
|
1998-01-28 16:09:43 +00:00
|
|
|
(unsigned)poolsize, strerror(errno));
|
|
|
|
else {
|
|
|
|
pool_is_mmapped = 1;
|
|
|
|
pool_okay = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
if( !pool_okay ) {
|
|
|
|
pool = malloc( poolsize );
|
|
|
|
if( !pool )
|
1998-02-02 14:36:06 +00:00
|
|
|
log_fatal("can't allocate memory pool of %u bytes\n",
|
1998-01-28 16:09:43 +00:00
|
|
|
(unsigned)poolsize);
|
|
|
|
else
|
|
|
|
pool_okay = 1;
|
|
|
|
}
|
|
|
|
lock_pool( pool, poolsize );
|
|
|
|
poollen = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* concatenate unused blocks */
|
|
|
|
static void
|
|
|
|
compress_pool(void)
|
|
|
|
{
|
1999-06-26 10:23:06 +00:00
|
|
|
/* fixme: we really should do this */
|
1998-01-28 16:09:43 +00:00
|
|
|
}
|
|
|
|
|
1998-02-11 23:22:09 +00:00
|
|
|
void
|
|
|
|
secmem_set_flags( unsigned flags )
|
|
|
|
{
|
1998-09-28 19:25:31 +00:00
|
|
|
int was_susp = suspend_warning;
|
|
|
|
|
1998-02-11 23:22:09 +00:00
|
|
|
no_warning = flags & 1;
|
1998-09-28 19:25:31 +00:00
|
|
|
suspend_warning = flags & 2;
|
|
|
|
|
|
|
|
/* and now issue the warning if it is not longer suspended */
|
|
|
|
if( was_susp && !suspend_warning && show_warning ) {
|
|
|
|
show_warning = 0;
|
|
|
|
print_warn();
|
|
|
|
}
|
1998-02-11 23:22:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned
|
|
|
|
secmem_get_flags(void)
|
|
|
|
{
|
1998-09-28 19:25:31 +00:00
|
|
|
unsigned flags;
|
|
|
|
|
|
|
|
flags = no_warning ? 1:0;
|
|
|
|
flags |= suspend_warning ? 2:0;
|
|
|
|
return flags;
|
1998-02-11 23:22:09 +00:00
|
|
|
}
|
1998-01-28 16:09:43 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
secmem_init( size_t n )
|
|
|
|
{
|
1998-07-09 13:37:17 +00:00
|
|
|
if( !n ) {
|
2001-08-20 11:53:05 +00:00
|
|
|
#ifndef __riscos__
|
1999-06-29 19:50:54 +00:00
|
|
|
#ifdef USE_CAPABILITIES
|
|
|
|
/* drop all capabilities */
|
|
|
|
cap_set_proc( cap_from_text("all-eip") );
|
|
|
|
|
|
|
|
#elif !defined(HAVE_DOSISH_SYSTEM)
|
1998-07-09 13:37:17 +00:00
|
|
|
uid_t uid;
|
|
|
|
|
1998-02-02 14:36:06 +00:00
|
|
|
disable_secmem=1;
|
1998-07-09 13:37:17 +00:00
|
|
|
uid = getuid();
|
|
|
|
if( uid != geteuid() ) {
|
2000-06-08 18:08:06 +00:00
|
|
|
if( setuid( uid ) || getuid() != geteuid() || !setuid(0) )
|
1998-07-09 13:37:17 +00:00
|
|
|
log_fatal("failed to drop setuid\n" );
|
|
|
|
}
|
1998-10-06 12:10:02 +00:00
|
|
|
#endif
|
2001-08-20 11:53:05 +00:00
|
|
|
#endif /* !__riscos__ */
|
1998-07-09 13:37:17 +00:00
|
|
|
}
|
1998-02-02 14:36:06 +00:00
|
|
|
else {
|
|
|
|
if( n < DEFAULT_POOLSIZE )
|
|
|
|
n = DEFAULT_POOLSIZE;
|
|
|
|
if( !pool_okay )
|
|
|
|
init_pool(n);
|
|
|
|
else
|
|
|
|
log_error("Oops, secure memory pool already initialized\n");
|
|
|
|
}
|
1998-01-28 16:09:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void *
|
|
|
|
secmem_malloc( size_t size )
|
|
|
|
{
|
|
|
|
MEMBLOCK *mb, *mb2;
|
|
|
|
int compressed=0;
|
|
|
|
|
1999-02-10 16:22:40 +00:00
|
|
|
if( !pool_okay ) {
|
|
|
|
log_info(
|
|
|
|
_("operation is not possible without initialized secure memory\n"));
|
|
|
|
log_info(_("(you may have used the wrong program for this task)\n"));
|
|
|
|
exit(2);
|
|
|
|
}
|
1998-09-28 19:25:31 +00:00
|
|
|
if( show_warning && !suspend_warning ) {
|
1998-02-11 23:22:09 +00:00
|
|
|
show_warning = 0;
|
1998-09-28 19:25:31 +00:00
|
|
|
print_warn();
|
1998-02-11 23:22:09 +00:00
|
|
|
}
|
1998-01-28 16:09:43 +00:00
|
|
|
|
|
|
|
/* blocks are always a multiple of 32 */
|
|
|
|
size += sizeof(MEMBLOCK);
|
|
|
|
size = ((size + 31) / 32) * 32;
|
|
|
|
|
|
|
|
retry:
|
|
|
|
/* try to get it from the used blocks */
|
|
|
|
for(mb = unused_blocks,mb2=NULL; mb; mb2=mb, mb = mb->u.next )
|
|
|
|
if( mb->size >= size ) {
|
|
|
|
if( mb2 )
|
|
|
|
mb2->u.next = mb->u.next;
|
|
|
|
else
|
|
|
|
unused_blocks = mb->u.next;
|
|
|
|
goto leave;
|
|
|
|
}
|
|
|
|
/* allocate a new block */
|
|
|
|
if( (poollen + size <= poolsize) ) {
|
1998-07-29 19:35:05 +00:00
|
|
|
mb = (void*)((char*)pool + poollen);
|
1998-01-28 16:09:43 +00:00
|
|
|
poollen += size;
|
|
|
|
mb->size = size;
|
|
|
|
}
|
|
|
|
else if( !compressed ) {
|
|
|
|
compressed=1;
|
|
|
|
compress_pool();
|
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
leave:
|
|
|
|
cur_alloced += mb->size;
|
|
|
|
cur_blocks++;
|
|
|
|
if( cur_alloced > max_alloced )
|
|
|
|
max_alloced = cur_alloced;
|
|
|
|
if( cur_blocks > max_blocks )
|
|
|
|
max_blocks = cur_blocks;
|
1999-06-26 10:23:06 +00:00
|
|
|
|
1999-02-26 16:59:48 +00:00
|
|
|
return &mb->u.aligned.c;
|
1998-01-28 16:09:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-02-27 17:51:28 +00:00
|
|
|
void *
|
|
|
|
secmem_realloc( void *p, size_t newsize )
|
|
|
|
{
|
|
|
|
MEMBLOCK *mb;
|
|
|
|
size_t size;
|
|
|
|
void *a;
|
|
|
|
|
1999-02-26 16:59:48 +00:00
|
|
|
mb = (MEMBLOCK*)((char*)p - ((size_t) &((MEMBLOCK*)0)->u.aligned.c));
|
1998-02-27 17:51:28 +00:00
|
|
|
size = mb->size;
|
|
|
|
if( newsize < size )
|
|
|
|
return p; /* it is easier not to shrink the memory */
|
|
|
|
a = secmem_malloc( newsize );
|
2000-09-06 12:51:58 +00:00
|
|
|
if ( a ) {
|
|
|
|
memcpy(a, p, size);
|
|
|
|
memset((char*)a+size, 0, newsize-size);
|
|
|
|
secmem_free(p);
|
|
|
|
}
|
1998-02-27 17:51:28 +00:00
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-01-28 16:09:43 +00:00
|
|
|
void
|
|
|
|
secmem_free( void *a )
|
|
|
|
{
|
|
|
|
MEMBLOCK *mb;
|
|
|
|
size_t size;
|
|
|
|
|
|
|
|
if( !a )
|
|
|
|
return;
|
|
|
|
|
1999-02-26 16:59:48 +00:00
|
|
|
mb = (MEMBLOCK*)((char*)a - ((size_t) &((MEMBLOCK*)0)->u.aligned.c));
|
1998-01-28 16:09:43 +00:00
|
|
|
size = mb->size;
|
1999-04-18 08:18:52 +00:00
|
|
|
/* This does not make much sense: probably this memory is held in the
|
|
|
|
* cache. We do it anyway: */
|
1998-01-28 16:09:43 +00:00
|
|
|
memset(mb, 0xff, size );
|
|
|
|
memset(mb, 0xaa, size );
|
|
|
|
memset(mb, 0x55, size );
|
|
|
|
memset(mb, 0x00, size );
|
|
|
|
mb->size = size;
|
|
|
|
mb->u.next = unused_blocks;
|
|
|
|
unused_blocks = mb;
|
|
|
|
cur_blocks--;
|
|
|
|
cur_alloced -= size;
|
|
|
|
}
|
|
|
|
|
1998-02-27 17:51:28 +00:00
|
|
|
int
|
|
|
|
m_is_secure( const void *p )
|
|
|
|
{
|
1998-07-31 16:45:58 +00:00
|
|
|
return p >= pool && p < (void*)((char*)pool+poolsize);
|
1998-02-27 17:51:28 +00:00
|
|
|
}
|
|
|
|
|
1999-09-13 08:56:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
/****************
|
|
|
|
* Warning: This code might be called by an interrupt handler
|
1999-11-22 10:10:27 +00:00
|
|
|
* and frankly, there should really be such a handler,
|
1999-09-13 08:56:45 +00:00
|
|
|
* to make sure that the memory is wiped out.
|
|
|
|
* We hope that the OS wipes out mlocked memory after
|
|
|
|
* receiving a SIGKILL - it really should do so, otherwise
|
|
|
|
* there is no chance to get the secure memory cleaned.
|
|
|
|
*/
|
1998-01-28 16:09:43 +00:00
|
|
|
void
|
|
|
|
secmem_term()
|
|
|
|
{
|
|
|
|
if( !pool_okay )
|
|
|
|
return;
|
|
|
|
|
|
|
|
memset( pool, 0xff, poolsize);
|
|
|
|
memset( pool, 0xaa, poolsize);
|
|
|
|
memset( pool, 0x55, poolsize);
|
|
|
|
memset( pool, 0x00, poolsize);
|
|
|
|
#if HAVE_MMAP
|
|
|
|
if( pool_is_mmapped )
|
|
|
|
munmap( pool, poolsize );
|
|
|
|
#endif
|
|
|
|
pool = NULL;
|
|
|
|
pool_okay = 0;
|
|
|
|
poolsize=0;
|
|
|
|
poollen=0;
|
|
|
|
unused_blocks=NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
secmem_dump_stats()
|
|
|
|
{
|
1998-02-02 14:36:06 +00:00
|
|
|
if( disable_secmem )
|
|
|
|
return;
|
1998-01-28 16:09:43 +00:00
|
|
|
fprintf(stderr,
|
|
|
|
"secmem usage: %u/%u bytes in %u/%u blocks of pool %lu/%lu\n",
|
|
|
|
cur_alloced, max_alloced, cur_blocks, max_blocks,
|
|
|
|
(ulong)poollen, (ulong)poolsize );
|
|
|
|
}
|
|
|
|
|