/* -*-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)
*
/*----- 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).
*
# include <sys/mman.h>
#endif
+#include <mLib/arena.h>
#include <mLib/dstr.h>
#include <mLib/sub.h>
#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@ --- *
/* --- Preliminaries --- */
+ lm->a.ops = &l_ops;
lm->err = 0;
/* --- Try making a secure locked passphrase buffer --- *
/* -*-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
*
/*----- 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).
*
#include <stddef.h>
+#include <mLib/arena.h>
#include <mLib/dstr.h>
/*----- Data structures ---------------------------------------------------*/
/* --- 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 */
int err; char *emsg; /* Error indicators */
} lmem;
+/* --- Locked memory arena --- */
+
+typedef struct lmem_arena {
+ arena a;
+ lmem l;
+} lmem_arena;
+
/*----- Functions provided ------------------------------------------------*/
/* --- @l_init@ --- *
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