From 37038e63935ecfbb2c6a401fa519ce4d10dec0c2 Mon Sep 17 00:00:00 2001 From: mdw Date: Sat, 29 Jul 2000 21:58:15 +0000 Subject: [PATCH] (l_destroy): New function for destroying locked memory blocks. --- lmem.c | 36 ++++++++++++++++++++++++++++++++++-- lmem.h | 39 +++++++++++++++++++-------------------- 2 files changed, 53 insertions(+), 22 deletions(-) diff --git a/lmem.c b/lmem.c index a56108a..8a21a6f 100644 --- a/lmem.c +++ b/lmem.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: lmem.c,v 1.2 2000/06/17 11:29:20 mdw Exp $ + * $Id: lmem.c,v 1.3 2000/07/29 21:58:15 mdw Exp $ * * Locked memory allocation (Unix-specific) * @@ -30,6 +30,9 @@ /*----- Revision history --------------------------------------------------* * * $Log: lmem.c,v $ + * Revision 1.3 2000/07/29 21:58:15 mdw + * (l_destroy): New function for destroying locked memory blocks. + * * Revision 1.2 2000/06/17 11:29:20 mdw * Add arena support. * @@ -97,6 +100,7 @@ int l_init(lmem *lm, size_t sz) lm->a.ops = &l_ops; lm->err = 0; + lm->f = 0; /* --- Try making a secure locked passphrase buffer --- * * @@ -133,7 +137,8 @@ int l_init(lmem *lm, size_t sz) lm->err = errno; munmap(p, sz); p = 0; - } + } else + lm->f |= LF_LOCKED; #endif @@ -295,6 +300,33 @@ void l_purge(lmem *lm) lm->free = l->sz; } +/* --- @l_destroy@ --- * + * + * Arguments: @lmem *lm@ = pointer to locked memory descriptor + * + * Returns: --- + * + * Use: Disposes of a locked memory arena permanently. + */ + +void l_destroy(lmem *lm) +{ + l_node *l; + + l = lm->l; + while (l) { + l_node *ll = l->next; + DESTROY(l); + l = ll; + } + memset(lm->p, 0, lm->sz); + + if (lm->f & LF_LOCKED) + munmap(lm->p, lm->sz); + else + free(lm->p); +} + /* --- @l_report@ --- * * * Arguments: @lmem *lm@ = pointer to locked memory descriptor diff --git a/lmem.h b/lmem.h index 8f24903..36204c6 100644 --- a/lmem.h +++ b/lmem.h @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: lmem.h,v 1.2 2000/06/17 11:29:38 mdw Exp $ + * $Id: lmem.h,v 1.3 2000/07/29 21:58:15 mdw Exp $ * * Locked memory allocation * @@ -30,6 +30,9 @@ /*----- Revision history --------------------------------------------------* * * $Log: lmem.h,v $ + * Revision 1.3 2000/07/29 21:58:15 mdw + * (l_destroy): New function for destroying locked memory blocks. + * * Revision 1.2 2000/06/17 11:29:38 mdw * Add arena support. * @@ -77,6 +80,7 @@ enum { typedef struct lmem { arena a; /* Arena header block */ + unsigned f; /* Various flags */ char *p; /* Pointer to locked buffer */ l_node *l; /* Pointer to block list */ size_t sz; /* Size of locked buffer */ @@ -84,12 +88,9 @@ typedef struct lmem { int err; char *emsg; /* Error indicators */ } lmem; -/* --- Locked memory arena --- */ - -typedef struct lmem_arena { - arena a; - lmem l; -} lmem_arena; +enum { + LF_LOCKED = 1 +}; /*----- Functions provided ------------------------------------------------*/ @@ -147,6 +148,17 @@ extern void l_free(lmem */*lm*/, void */*p*/); extern void l_purge(lmem */*lm*/); +/* --- @l_destroy@ --- * + * + * Arguments: @lmem *lm@ = pointer to locked memory descriptor + * + * Returns: --- + * + * Use: Disposes of a locked memory arena permanently. + */ + +extern void l_destroy(lmem */*lm*/); + /* --- @l_report@ --- * * * Arguments: @lmem *lm@ = pointer to locked memory descriptor @@ -163,19 +175,6 @@ extern void l_purge(lmem */*lm*/); extern int l_report(lmem */*lm*/, dstr */*d*/); -/*----- Arena management --------------------------------------------------*/ - -/* --- @l_arena@ --- * - * - * Arguments: @lmem_arena *l@ = pointer to arena block - * - * Returns: --- - * - * Use: Initializes a locked-memory arena. - */ - -extern void l_arena(lmem_arena */*l*/); - /*----- That's all, folks -------------------------------------------------*/ #ifdef __cplusplus -- 2.11.0