3 * $Id: lmem.h,v 1.3 2000/07/29 21:58:15 mdw Exp $
5 * Locked memory allocation
7 * (c) 1999 Straylight/Edgeware
10 /*----- Licensing notice --------------------------------------------------*
12 * This file is part of Catacomb.
14 * Catacomb is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU Library General Public License as
16 * published by the Free Software Foundation; either version 2 of the
17 * License, or (at your option) any later version.
19 * Catacomb is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Library General Public License for more details.
24 * You should have received a copy of the GNU Library General Public
25 * License along with Catacomb; if not, write to the Free
26 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
30 /*----- Revision history --------------------------------------------------*
33 * Revision 1.3 2000/07/29 21:58:15 mdw
34 * (l_destroy): New function for destroying locked memory blocks.
36 * Revision 1.2 2000/06/17 11:29:38 mdw
39 * Revision 1.1 1999/12/22 16:02:52 mdw
40 * Interface to allocating `locked' memory (which isn't paged out).
44 #ifndef CATACOMB_LMEM_H
45 #define CATACOMB_LMEM_H
51 /*----- Header files ------------------------------------------------------*/
55 #include <mLib/arena.h>
56 #include <mLib/dstr.h>
58 /*----- Data structures ---------------------------------------------------*/
60 /* --- Block list --- *
62 * The block list is kept in normal memory, to avoid wasting precious locked
63 * memory. Entries are sorted into ascending address order to make
64 * coalescing free blocks easier. All blocks, free or not, are included in
68 typedef struct l_node
{
69 struct l_node
*next
; /* Next free block in chain */
70 char *p
; /* Pointer to the block */
71 size_t sz
; /* Size of the block */
72 unsigned f
; /* Various flags */
79 /* --- Locked memory buffer state --- */
82 arena a
; /* Arena header block */
83 unsigned f
; /* Various flags */
84 char *p
; /* Pointer to locked buffer */
85 l_node
*l
; /* Pointer to block list */
86 size_t sz
; /* Size of locked buffer */
87 size_t free
; /* Size of free area */
88 int err
; char *emsg
; /* Error indicators */
95 /*----- Functions provided ------------------------------------------------*/
99 * Arguments: @lmem *lm@ = pointer to locked memory descriptor
100 * @size_t sz@ = size of locked memory area requested
102 * Returns: Zero if everything is fine, @+1@ if some insecure memory was
103 * allocated, and @-1@ if everything went horribly wrong.
105 * Use: Initializes the locked memory manager. This function is safe
106 * to call in a privileged program; privileges should usually be
107 * dropped after allocating the locked memory block.
109 * You must call @sub_init@ before allocating locked memory
113 extern int l_init(lmem */
*lm*/
, size_t /*sz*/);
115 /* --- @l_alloc@ --- *
117 * Arguments: @lmem *lm@ = pointer to locked memory descriptor
118 * @size_t sz@ = size requested
120 * Returns: Pointer to allocated memory.
122 * Use: Allocates @sz@ bytes of locked memory.
125 extern void *l_alloc(lmem */
*lm*/
, size_t /*sz*/);
127 /* --- @l_free@ --- *
129 * Arguments: @lmem *lm@ = pointer to locked memory descriptor
130 * @void *p@ = pointer to block
134 * Use: Releases a block of locked memory.
137 extern void l_free(lmem */
*lm*/
, void */
*p*/
);
139 /* --- @l_purge@ --- *
141 * Arguments: @lmem *lm@ = pointer to locked memory descriptor
145 * Use: Purges all the free blocks in the buffer, and clears all of
146 * the locked memory. Memory is not freed back to the system.
149 extern void l_purge(lmem */
*lm*/
);
151 /* --- @l_destroy@ --- *
153 * Arguments: @lmem *lm@ = pointer to locked memory descriptor
157 * Use: Disposes of a locked memory arena permanently.
160 extern void l_destroy(lmem */
*lm*/
);
162 /* --- @l_report@ --- *
164 * Arguments: @lmem *lm@ = pointer to locked memory descriptor
165 * @dstr *d@ = string to write the error message on
167 * Returns: Zero if the buffer is fine, @+1@ if there was a problem
168 * getting locked memory but insecure stuff could be allocated,
169 * and @-1@ if not even insecure memory could be found.
171 * Use: Returns a user-digestable explanation for the state of a
172 * locked memory buffer. If the return code is zero, no message
173 * is emitted to the string @d@.
176 extern int l_report(lmem */
*lm*/
, dstr */
*d*/
);
178 /*----- That's all, folks -------------------------------------------------*/