1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
|
/*____________________________________________________________________________
Copyright (C) 1997 Network Associates Inc. and affiliated companies.
All rights reserved.
Contains the definition of the PGPMemoryMgr object.
$Id: pgpMemoryMgr.h,v 1.21 1999/05/07 01:55:45 heller Exp $
____________________________________________________________________________*/
#ifndef Included_pgpMemoryMgr_h /* [ */
#define Included_pgpMemoryMgr_h
#include "pgpBase.h"
/*____________________________________________________________________________
Mini-tutorial:
A PGPMemoryMgr is an object which implements memory management, including
allocation, reallocation, deallocation, and secure versions of the same.
*** Using it ***
A typical sequence of calls is as follows:
PGPNewMemoryMgr
...
PGPNewData or PGPNewSecureData
PGPFreeData
...
PGPFreeMemoryMgr
Typically, a program will create one PGPMemoryMgr per thread at
thread creation time and use that memory mgr until the thread dies.
Generally, an individual PGPMemoryMgr instance is not thread-safe;
you must either synchronize or use one PGPMemoryMgr per thread.
*** Custom Allocators ***
Default allocators are supplied, but the client can create a custom
PGPMemoryMgr using PGPNewMemoryMgrCustom() which uses client-supplied
routines.
Custom routines need only concern themselves with the actual
allocation and deallocation.
The following should be kept in mind for user supplied routines:
- they can ignore the allocation flags passed
- leaks, memory clearing, etc is done by the PGPMemoryMgr
- secure allocator must set 'isNonPageable' to TRUE only if the
memory really can't be paged.
- the user value is not interpreted by the PGPMemoryMgr. Typically,
it would be a pointer to some data the allocation routines use
to store state.
*** Secure memory allocation ***
Blocks can be allocated as "Secure" blocks. Secure blocks are guaranteed
to be wiped when they are deallocated. Additionally, if the operating
system and the current conditions allow, the block will be allocated
in non-pageable memory. You can determine the attributes of a block using
PGPGetMemoryMgrDataInfo().
*** Leaks tracking ***
Leaks tracking is implemented when debugging is on,
but currently reporting is limited to reporting the number of leaks
outstanding when the PGPMemoryMgr is disposed.
*** Debugging ***
For debugging purposes, blocks may be larger in debug mode to accomodate
various schemes to detect stray pointers, etc.
____________________________________________________________________________*/
#if PRAGMA_ALIGN_SUPPORTED
#pragma options align=mac68k
#endif
enum
{
kPGPMemoryMgrFlags_None = 0,
kPGPMemoryMgrFlags_Clear = 1
};
typedef PGPFlags PGPMemoryMgrFlags;
typedef struct PGPMemoryMgr PGPMemoryMgr;
typedef PGPMemoryMgr * PGPMemoryMgrRef;
#define kInvalidPGPMemoryMgrRef ((PGPMemoryMgrRef) NULL)
#define PGPMemoryMgrRefIsValid(ref) ((ref) != kInvalidPGPMemoryMgrRef)
typedef void *(*PGPMemoryMgrAllocationProc)( PGPMemoryMgrRef mgr,
PGPUserValue userValue,
PGPSize requestSize, PGPMemoryMgrFlags flags );
/* realloc not be implemented using PGPNewData() */
typedef PGPError (*PGPMemoryMgrReallocationProc)( PGPMemoryMgrRef mgr,
PGPUserValue userValue,
void **allocation, PGPSize newAllocationSize,
PGPMemoryMgrFlags flags, PGPSize existingSize );
typedef PGPError (*PGPMemoryMgrDeallocationProc)( PGPMemoryMgrRef mgr,
PGPUserValue userValue,
void *allocation, PGPSize allocationSize );
typedef void *(*PGPMemoryMgrSecureAllocationProc)( PGPMemoryMgrRef mgr,
PGPUserValue userValue,
PGPSize requestSize, PGPMemoryMgrFlags flags,
PGPBoolean *isNonPageable );
/* deallocation proc need not clear the memory upon deallocation since
PGPFreeData() does it automatically */
typedef PGPError (*PGPMemoryMgrSecureDeallocationProc)( PGPMemoryMgrRef mgr,
PGPUserValue userValue,
void *allocation, PGPSize allocationSize,
PGPBoolean wasLocked );
typedef struct PGPNewMemoryMgrStruct
{
/* sizeofStruct must be inited to sizeof( PGPNewMemoryMgrStruct ) */
PGPUInt32 sizeofStruct;
PGPFlags reservedFlags;
PGPMemoryMgrAllocationProc allocProc;
PGPMemoryMgrReallocationProc reallocProc;
PGPMemoryMgrDeallocationProc deallocProc;
PGPMemoryMgrSecureAllocationProc secureAllocProc;
void * reserved; /* MUST be zeroed */
PGPMemoryMgrSecureDeallocationProc secureDeallocProc;
PGPUserValue customValue;
void * pad[ 8 ]; /* MUST be zeroed */
} PGPNewMemoryMgrStruct;
PGP_BEGIN_C_DECLARATIONS
#if PRAGMA_IMPORT_SUPPORTED
#pragma import on
#endif
/*____________________________________________________________________________
Memory Mgr routines
____________________________________________________________________________*/
PGPBoolean PGPMemoryMgrIsValid( PGPMemoryMgrRef mgr );
#define PGPValidateMemoryMgr( mgr ) \
PGPValidateParam( PGPMemoryMgrIsValid( mgr ) )
PGPError PGPNewMemoryMgr( PGPFlags reserved,
PGPMemoryMgrRef *newMemoryMgr );
PGPError PGPNewMemoryMgrCustom( PGPNewMemoryMgrStruct const * custom,
PGPMemoryMgrRef *newMemoryMgr );
PGPError PGPFreeMemoryMgr( PGPMemoryMgrRef mgr );
PGPError PGPGetMemoryMgrCustomValue( PGPMemoryMgrRef mgr,
PGPUserValue *customValue );
PGPError PGPSetMemoryMgrCustomValue( PGPMemoryMgrRef mgr,
PGPUserValue customValue );
/* allocate a block of the specified size */
void * PGPNewData( PGPMemoryMgrRef mgr,
PGPSize requestSize, PGPMemoryMgrFlags flags );
/* allocate a block of the specified size in non-pageable memory */
/* *isSecure is TRUE if the block definitely can't be paged */
void * PGPNewSecureData( PGPMemoryMgrRef mgr,
PGPSize requestSize, PGPMemoryMgrFlags flags );
/* properly reallocs secure or non-secure blocks */
/* WARNING: the block may move, even if its size is being reduced */
PGPError PGPReallocData( PGPMemoryMgrRef mgr,
void **allocation, PGPSize newAllocationSize,
PGPMemoryMgrFlags flags );
/* properly frees secure or non-secure blocks */
PGPError PGPFreeData( void *allocation );
/*____________________________________________________________________________
Block Info:
kPGPMemoryMgrBlockInfo_Valid it's a valid block
kPGPMemoryMgrBlockInfo_Secure block is a secure allocation
kPGPMemoryMgrBlockInfo_NonPageable block cannot be paged by VM
Secure blocks are always wiped before being disposed,
but may or may not be pageable, depending on the OS facilities. Some
OSs may not provide the ability to make blocks non-pageable.
You should check these flags if the information matters to you.
____________________________________________________________________________*/
#define kPGPMemoryMgrBlockInfo_Valid ( ((PGPFlags)1) << 0 )
#define kPGPMemoryMgrBlockInfo_Secure ( ((PGPFlags)1) << 1 )
#define kPGPMemoryMgrBlockInfo_NonPageable ( ((PGPFlags)1) << 2 )
PGPFlags PGPGetMemoryMgrDataInfo( void *allocation );
/*____________________________________________________________________________
Default memory manager routines:
____________________________________________________________________________*/
PGPMemoryMgrRef PGPGetDefaultMemoryMgr(void);
PGPError PGPSetDefaultMemoryMgr(PGPMemoryMgrRef memoryMgr);
#if PRAGMA_IMPORT_SUPPORTED
#pragma import reset
#endif
PGP_END_C_DECLARATIONS
#if PRAGMA_ALIGN_SUPPORTED
#pragma options align=reset
#endif
#endif /* ] Included_pgpMemoryMgr_h */
/*__Editor_settings____
Local Variables:
tab-width: 4
End:
vi: ts=4 sw=4
vim: si
_____________________*/
|