diff options
author | Werner Koch <wk@gnupg.org> | 2018-12-12 08:34:10 +0100 |
---|---|---|
committer | Werner Koch <wk@gnupg.org> | 2018-12-12 08:43:48 +0100 |
commit | 876f7280e8604bc99ddda0526339ec5ec6b23c4b (patch) | |
tree | a8ea9eecc124015101a091eadfaf597e40425eb2 /src/secmem.c | |
parent | 66d2b7fc17258f1424f4ca4adb1096e48b818bd0 (diff) | |
download | libgcrypt-876f7280e8604bc99ddda0526339ec5ec6b23c4b.tar.gz |
secmem: Prepare for easier debugging.
* src/secmem.c (_gcry_secmem_dump_stats): Factor code out to ...
(secmem_dump_stats_internal): new.
--
This allows to insert call to the dump function during debug sessions
inside of the allocators or call secmem_dump_stats_internal from gdb.
Signed-off-by: Werner Koch <wk@gnupg.org>
Diffstat (limited to 'src/secmem.c')
-rw-r--r-- | src/secmem.c | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/src/secmem.c b/src/secmem.c index b6f07c54..b36c44f6 100644 --- a/src/secmem.c +++ b/src/secmem.c @@ -118,6 +118,13 @@ GPGRT_LOCK_DEFINE (secmem_lock); #define ADDR_TO_BLOCK(addr) \ (memblock_t *) (void *) ((char *) addr - BLOCK_HEAD_SIZE) +/* Prototypes. */ +static void secmem_dump_stats_internal (int extended); + + +/* + * Functions + */ /* Memory barrier */ static inline void @@ -657,11 +664,18 @@ _gcry_secmem_malloc_internal (size_t size, int xhint) return &mb->aligned.c; } - /* If we are called from xmalloc style function resort to the + /* If we are called from xmalloc style functions resort to the * overflow pools to return memory. We don't do this in FIPS mode, - * though. */ + * though. If the auto-expand option is active we do the expanding + * also for the standard malloc functions. + * + * The idea of using them by default only for the xmalloc function + * is so that a user can control whether memory will be allocated in + * the initial created mlock protected secmem area or may also be + * allocated from the overflow pools. */ if ((xhint || auto_expand) && !fips_mode ()) { + /* Check whether we can allocate from the overflow pools. */ for (pool = pool->next; pool; pool = pool->next) { mb = mb_get_new (pool, (memblock_t *) pool->mem, size); @@ -900,12 +914,19 @@ _gcry_secmem_term () void _gcry_secmem_dump_stats (int extended) { + SECMEM_LOCK; + secmem_dump_stats_internal (extended); + SECMEM_UNLOCK; +} + + +static void +secmem_dump_stats_internal (int extended) +{ pooldesc_t *pool; memblock_t *mb; int i, poolno; - SECMEM_LOCK; - for (pool = &mainpool, poolno = 0; pool; pool = pool->next, poolno++) { if (!extended) @@ -928,5 +949,4 @@ _gcry_secmem_dump_stats (int extended) mb->size); } } - SECMEM_UNLOCK; } |