From 47d5f7c2e72bdc2cc06414e1c07b27760974e2ca Mon Sep 17 00:00:00 2001 From: mdw Date: Sat, 17 Jun 2000 11:29:38 +0000 Subject: [PATCH] Add arena support. --- lmem.c | 15 ++++++++++++++- lmem.h | 27 ++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/lmem.c b/lmem.c index e443aa6..a56108a 100644 --- a/lmem.c +++ b/lmem.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: lmem.c,v 1.1 1999/12/22 16:02:52 mdw Exp $ + * $Id: lmem.c,v 1.2 2000/06/17 11:29:20 mdw Exp $ * * Locked memory allocation (Unix-specific) * @@ -30,6 +30,9 @@ /*----- Revision history --------------------------------------------------* * * $Log: lmem.c,v $ + * Revision 1.2 2000/06/17 11:29:20 mdw + * Add arena support. + * * Revision 1.1 1999/12/22 16:02:52 mdw * Interface to allocating `locked' memory (which isn't paged out). * @@ -52,11 +55,20 @@ # include #endif +#include #include #include #include "lmem.h" +/*----- Arena operations --------------------------------------------------*/ + +static void *aalloc(arena *a, size_t sz) { return l_alloc((lmem *)a, sz); } +static void afree(arena *a, void *p) { l_free((lmem *)a, p); } +static void apurge(arena *a) { l_purge((lmem *)a); } + +static arena_ops l_ops = { aalloc, arena_fakerealloc, afree, apurge }; + /*----- Main code ---------------------------------------------------------*/ /* --- @l_init@ --- * @@ -83,6 +95,7 @@ int l_init(lmem *lm, size_t sz) /* --- Preliminaries --- */ + lm->a.ops = &l_ops; lm->err = 0; /* --- Try making a secure locked passphrase buffer --- * diff --git a/lmem.h b/lmem.h index 8546dcf..8f24903 100644 --- a/lmem.h +++ b/lmem.h @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: lmem.h,v 1.1 1999/12/22 16:02:52 mdw Exp $ + * $Id: lmem.h,v 1.2 2000/06/17 11:29:38 mdw Exp $ * * Locked memory allocation * @@ -30,6 +30,9 @@ /*----- Revision history --------------------------------------------------* * * $Log: lmem.h,v $ + * Revision 1.2 2000/06/17 11:29:38 mdw + * Add arena support. + * * Revision 1.1 1999/12/22 16:02:52 mdw * Interface to allocating `locked' memory (which isn't paged out). * @@ -46,6 +49,7 @@ #include +#include #include /*----- Data structures ---------------------------------------------------*/ @@ -72,6 +76,7 @@ enum { /* --- Locked memory buffer state --- */ typedef struct lmem { + arena a; /* Arena header block */ char *p; /* Pointer to locked buffer */ l_node *l; /* Pointer to block list */ size_t sz; /* Size of locked buffer */ @@ -79,6 +84,13 @@ typedef struct lmem { int err; char *emsg; /* Error indicators */ } lmem; +/* --- Locked memory arena --- */ + +typedef struct lmem_arena { + arena a; + lmem l; +} lmem_arena; + /*----- Functions provided ------------------------------------------------*/ /* --- @l_init@ --- * @@ -151,6 +163,19 @@ 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