void _gcry_secmem_dump_stats () { #if 1 SECMEM_LOCK; if (pool_okay) log_info ("secmem usage: %u/%lu bytes in %u blocks\n", cur_alloced, (unsigned long)pool_size, cur_blocks); SECMEM_UNLOCK; #else memblock_t *mb; int i; SECMEM_LOCK; for (i = 0, mb = (memblock_t *) pool; ptr_into_pool_p (mb); mb = mb_get_next (mb), i++) log_info ("SECMEM: [%s] block: %i; size: %i\n", (mb->flags & MB_FLAG_ACTIVE) ? "used" : "free", i, mb->size); SECMEM_UNLOCK; #endif }
/* Return the block following MB or NULL, if MB is the last block. */ static memblock_t * mb_get_next (memblock_t *mb) { memblock_t *mb_next; mb_next = (memblock_t *) ((char *) mb + BLOCK_HEAD_SIZE + mb->size); if (! ptr_into_pool_p (mb_next)) mb_next = NULL; return mb_next; }
/* Return a new block, which can hold SIZE bytes. */ static memblock_t * mb_get_new (memblock_t *block, size_t size) { memblock_t *mb, *mb_split; for (mb = block; ptr_into_pool_p (mb); mb = mb_get_next (mb)) if (! (mb->flags & MB_FLAG_ACTIVE) && mb->size >= size) { /* Found a free block. */ mb->flags |= MB_FLAG_ACTIVE; if (mb->size - size > BLOCK_HEAD_SIZE) { /* Split block. */ mb_split = (memblock_t *) (((char *) mb) + BLOCK_HEAD_SIZE + size); mb_split->size = mb->size - size - BLOCK_HEAD_SIZE; mb_split->flags = 0; mb->size = size; mb_merge (mb_split); } break; } if (! ptr_into_pool_p (mb)) { gpg_err_set_errno (ENOMEM); mb = NULL; } return mb; }
int m_is_secure( const void *p ) { return pool_okay && ptr_into_pool_p (p); }
/* Return true if P points into the secure memory area. */ int _gcry_private_is_secure (const void *p) { return pool_okay && ptr_into_pool_p (p); }