3 * $Id: lmem.h,v 1.1 1999/12/22 16:02:52 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.1 1999/12/22 16:02:52 mdw
34 * Interface to allocating `locked' memory (which isn't paged out).
38 #ifndef CATACOMB_LMEM_H
39 #define CATACOMB_LMEM_H
45 /*----- Header files ------------------------------------------------------*/
49 #include <mLib/dstr.h>
51 /*----- Data structures ---------------------------------------------------*/
53 /* --- Block list --- *
55 * The block list is kept in normal memory, to avoid wasting precious locked
56 * memory. Entries are sorted into ascending address order to make
57 * coalescing free blocks easier. All blocks, free or not, are included in
61 typedef struct l_node
{
62 struct l_node
*next
; /* Next free block in chain */
63 char *p
; /* Pointer to the block */
64 size_t sz
; /* Size of the block */
65 unsigned f
; /* Various flags */
72 /* --- Locked memory buffer state --- */
75 char *p
; /* Pointer to locked buffer */
76 l_node
*l
; /* Pointer to block list */
77 size_t sz
; /* Size of locked buffer */
78 size_t free
; /* Size of free area */
79 int err
; char *emsg
; /* Error indicators */
82 /*----- Functions provided ------------------------------------------------*/
86 * Arguments: @lmem *lm@ = pointer to locked memory descriptor
87 * @size_t sz@ = size of locked memory area requested
89 * Returns: Zero if everything is fine, @+1@ if some insecure memory was
90 * allocated, and @-1@ if everything went horribly wrong.
92 * Use: Initializes the locked memory manager. This function is safe
93 * to call in a privileged program; privileges should usually be
94 * dropped after allocating the locked memory block.
96 * You must call @sub_init@ before allocating locked memory
100 extern int l_init(lmem */
*lm*/
, size_t /*sz*/);
102 /* --- @l_alloc@ --- *
104 * Arguments: @lmem *lm@ = pointer to locked memory descriptor
105 * @size_t sz@ = size requested
107 * Returns: Pointer to allocated memory.
109 * Use: Allocates @sz@ bytes of locked memory.
112 extern void *l_alloc(lmem */
*lm*/
, size_t /*sz*/);
114 /* --- @l_free@ --- *
116 * Arguments: @lmem *lm@ = pointer to locked memory descriptor
117 * @void *p@ = pointer to block
121 * Use: Releases a block of locked memory.
124 extern void l_free(lmem */
*lm*/
, void */
*p*/
);
126 /* --- @l_purge@ --- *
128 * Arguments: @lmem *lm@ = pointer to locked memory descriptor
132 * Use: Purges all the free blocks in the buffer, and clears all of
133 * the locked memory. Memory is not freed back to the system.
136 extern void l_purge(lmem */
*lm*/
);
138 /* --- @l_report@ --- *
140 * Arguments: @lmem *lm@ = pointer to locked memory descriptor
141 * @dstr *d@ = string to write the error message on
143 * Returns: Zero if the buffer is fine, @+1@ if there was a problem
144 * getting locked memory but insecure stuff could be allocated,
145 * and @-1@ if not even insecure memory could be found.
147 * Use: Returns a user-digestable explanation for the state of a
148 * locked memory buffer. If the return code is zero, no message
149 * is emitted to the string @d@.
152 extern int l_report(lmem */
*lm*/
, dstr */
*d*/
);
154 /*----- That's all, folks -------------------------------------------------*/