dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / lib / libast / i386 / include / ast / vmalloc.h
blobf13cc58879788db885c031724dbfef1c51cb3bdb
1 /***********************************************************************
2 * *
3 * This software is part of the ast package *
4 * Copyright (c) 1985-2010 AT&T Intellectual Property *
5 * and is licensed under the *
6 * Common Public License, Version 1.0 *
7 * by AT&T Intellectual Property *
8 * *
9 * A copy of the License is available at *
10 * http://www.opensource.org/licenses/cpl1.0.txt *
11 * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
12 * *
13 * Information and Software Systems Research *
14 * AT&T Research *
15 * Florham Park NJ *
16 * *
17 * Glenn Fowler <gsf@research.att.com> *
18 * David Korn <dgk@research.att.com> *
19 * Phong Vo <kpv@research.att.com> *
20 * *
21 ***********************************************************************/
22 #ifndef _VMALLOC_H
23 #define _VMALLOC_H 1
25 /* Public header file for the virtual malloc package.
27 ** Written by Kiem-Phong Vo, kpv@research.att.com, 01/16/94.
30 #define VMALLOC_VERSION 20100101L
32 #if _PACKAGE_ast
33 #include <ast_std.h>
34 #else
35 #include <ast_common.h>
36 #endif
38 typedef struct _vmalloc_s Vmalloc_t;
39 typedef struct _vmstat_s Vmstat_t;
40 typedef struct _vmdisc_s Vmdisc_t;
41 typedef struct _vmethod_s Vmethod_t;
42 typedef struct _vmdata_s Vmdata_t;
43 typedef Void_t* (*Vmemory_f)_ARG_((Vmalloc_t*, Void_t*, size_t, size_t, Vmdisc_t*));
44 typedef int (*Vmexcept_f)_ARG_((Vmalloc_t*, int, Void_t*, Vmdisc_t*));
46 struct _vmstat_s
47 { int n_busy; /* number of busy blocks */
48 int n_free; /* number of free blocks */
49 size_t s_busy; /* total amount of busy space */
50 size_t s_free; /* total amount of free space */
51 size_t m_busy; /* largest busy piece */
52 size_t m_free; /* largest free piece */
53 int n_seg; /* number of segments */
54 size_t extent; /* total size of region */
57 struct _vmdisc_s
58 { Vmemory_f memoryf; /* memory manipulator */
59 Vmexcept_f exceptf; /* exception handler */
60 size_t round; /* rounding requirement */
63 struct _vmethod_s
64 { Void_t* (*allocf)_ARG_((Vmalloc_t*,size_t));
65 Void_t* (*resizef)_ARG_((Vmalloc_t*,Void_t*,size_t,int));
66 int (*freef)_ARG_((Vmalloc_t*,Void_t*));
67 long (*addrf)_ARG_((Vmalloc_t*,Void_t*));
68 long (*sizef)_ARG_((Vmalloc_t*,Void_t*));
69 int (*compactf)_ARG_((Vmalloc_t*));
70 Void_t* (*alignf)_ARG_((Vmalloc_t*,size_t,size_t));
71 unsigned short meth;
74 struct _vmalloc_s
75 { Vmethod_t meth; /* method for allocation */
76 char* file; /* file name */
77 int line; /* line number */
78 Void_t* func; /* calling function */
79 Vmdisc_t* disc; /* discipline to get space */
80 Vmdata_t* data; /* the real region data */
81 Vmalloc_t* next; /* linked list of regions */
82 #ifdef _VM_PRIVATE_
83 _VM_PRIVATE_
84 #endif
87 #undef VM_FLAGS /* solaris sys kernel clash */
89 #define VM_TRUST 0000001 /* forgo some security checks */
90 #define VM_TRACE 0000002 /* generate trace */
91 #define VM_DBCHECK 0000004 /* check for boundary overwrite */
92 #define VM_DBABORT 0000010 /* abort on any warning */
93 #define VM_FLAGS 0000017 /* user-settable flags */
95 #define VM_MTBEST 0000100 /* Vmbest method */
96 #define VM_MTPOOL 0000200 /* Vmpool method */
97 #define VM_MTLAST 0000400 /* Vmlast method */
98 #define VM_MTDEBUG 0001000 /* Vmdebug method */
99 #define VM_MTPROFILE 0002000 /* Vmdebug method */
100 #define VM_METHODS 0003700 /* available allocation methods */
102 #define VM_RSCOPY 0000001 /* copy old contents */
103 #define VM_RSMOVE 0000002 /* old contents is moveable */
104 #define VM_RSZERO 0000004 /* clear new space */
106 /* exception types */
107 #define VM_OPEN 0 /* region being opened */
108 #define VM_CLOSE 1 /* announce being closed */
109 #define VM_NOMEM 2 /* can't obtain memory */
110 #define VM_BADADDR 3 /* bad addr in vmfree/vmresize */
111 #define VM_DISC 4 /* discipline being changed */
112 #define VM_ALLOC 5 /* announcement from vmalloc() */
113 #define VM_FREE 6 /* announcement from vmfree() */
114 #define VM_RESIZE 7 /* announcement from vmresize() */
116 _BEGIN_EXTERNS_ /* public data */
117 #if _BLD_vmalloc && defined(__EXPORT__)
118 #define extern extern __EXPORT__
119 #endif
120 #if !_BLD_vmalloc && defined(__IMPORT__)
121 #define extern extern __IMPORT__
122 #endif
124 extern Vmethod_t* Vmbest; /* best allocation */
125 extern Vmethod_t* Vmlast; /* last-block allocation */
126 extern Vmethod_t* Vmpool; /* pool allocation */
127 extern Vmethod_t* Vmdebug; /* allocation with debugging */
128 extern Vmethod_t* Vmprofile; /* profiling memory usage */
130 extern Vmdisc_t* Vmdcheap; /* heap discipline */
131 extern Vmdisc_t* Vmdcsbrk; /* sbrk discipline */
133 extern Vmalloc_t* Vmheap; /* heap region */
134 extern Vmalloc_t* Vmregion; /* malloc region */
136 #undef extern
137 _END_EXTERNS_
139 _BEGIN_EXTERNS_ /* public functions */
140 #if _BLD_vmalloc && defined(__EXPORT__)
141 #define extern __EXPORT__
142 #endif
144 extern Vmalloc_t* vmopen _ARG_(( Vmdisc_t*, Vmethod_t*, int ));
145 extern int vmclose _ARG_(( Vmalloc_t* ));
146 extern int vmclear _ARG_(( Vmalloc_t* ));
147 extern int vmcompact _ARG_(( Vmalloc_t* ));
149 extern Vmdisc_t* vmdisc _ARG_(( Vmalloc_t*, Vmdisc_t* ));
151 extern Vmalloc_t* vmmopen _ARG_(( char*, Void_t*, size_t ));
152 extern Void_t* vmmset _ARG_((Vmalloc_t*, int, Void_t*, int));
154 extern Void_t* vmalloc _ARG_(( Vmalloc_t*, size_t ));
155 extern Void_t* vmalign _ARG_(( Vmalloc_t*, size_t, size_t ));
156 extern Void_t* vmresize _ARG_(( Vmalloc_t*, Void_t*, size_t, int ));
157 extern Void_t* vmgetmem _ARG_(( Vmalloc_t*, Void_t*, size_t ));
158 extern int vmfree _ARG_(( Vmalloc_t*, Void_t* ));
160 extern long vmaddr _ARG_(( Vmalloc_t*, Void_t* ));
161 extern long vmsize _ARG_(( Vmalloc_t*, Void_t* ));
163 extern Vmalloc_t* vmregion _ARG_(( Void_t* ));
164 extern Void_t* vmsegment _ARG_(( Vmalloc_t*, Void_t* ));
165 extern int vmset _ARG_(( Vmalloc_t*, int, int ));
167 extern Void_t* vmdbwatch _ARG_(( Void_t* ));
168 extern int vmdbcheck _ARG_(( Vmalloc_t* ));
169 extern int vmdebug _ARG_(( int ));
171 extern int vmprofile _ARG_(( Vmalloc_t*, int ));
173 extern int vmtrace _ARG_(( int ));
174 extern int vmtrbusy _ARG_((Vmalloc_t*));
176 extern int vmstat _ARG_((Vmalloc_t*, Vmstat_t*));
178 extern int vmwalk _ARG_((Vmalloc_t*,
179 int(*)(Vmalloc_t*,Void_t*,size_t,Vmdisc_t*,Void_t*),
180 Void_t*));
181 extern char* vmstrdup _ARG_((Vmalloc_t*, const char*));
183 #if !defined(_BLD_vmalloc) && !defined(_AST_STD_H) && \
184 !defined(__stdlib_h) && !defined(__STDLIB_H) && \
185 !defined(_STDLIB_INCLUDED) && !defined(_INC_STDLIB)
186 extern Void_t* malloc _ARG_(( size_t ));
187 extern Void_t* realloc _ARG_(( Void_t*, size_t ));
188 extern void free _ARG_(( Void_t* ));
189 extern void cfree _ARG_(( Void_t* ));
190 extern Void_t* calloc _ARG_(( size_t, size_t ));
191 extern Void_t* memalign _ARG_(( size_t, size_t ));
192 extern Void_t* valloc _ARG_(( size_t ));
193 #endif
195 #undef extern
196 _END_EXTERNS_
198 /* to coerce any value to a Vmalloc_t*, make ANSI happy */
199 #define _VM_(vm) ((Vmalloc_t*)(vm))
201 /* enable recording of where a call originates from */
202 #ifdef VMFL
204 #if defined(__FILE__)
205 #define _VMFILE_(vm) (_VM_(vm)->file = (char*)__FILE__)
206 #else
207 #define _VMFILE_(vm) (_VM_(vm)->file = 0)
208 #endif
210 #if defined(__LINE__)
211 #define _VMLINE_(vm) (_VM_(vm)->line = __LINE__)
212 #else
213 #define _VMLINE_(vm) (_VM_(vm)->line = 0)
214 #endif
216 #if defined(__FUNCTION__)
217 #define _VMFUNC_(vm) (_VM_(vm)->func = (Void_t*)__FUNCTION__)
218 #else
219 #define _VMFUNC_(vm) (_VM_(vm)->func = 0)
220 #endif
222 #define _VMFL_(vm) (_VMFILE_(vm), _VMLINE_(vm), _VMFUNC_(vm))
224 #define vmalloc(vm,sz) (_VMFL_(vm), \
225 (*(_VM_(vm)->meth.allocf))((vm),(sz)) )
226 #define vmresize(vm,d,sz,type) (_VMFL_(vm), \
227 (*(_VM_(vm)->meth.resizef))\
228 ((vm),(Void_t*)(d),(sz),(type)) )
229 #define vmfree(vm,d) (_VMFL_(vm), \
230 (*(_VM_(vm)->meth.freef))((vm),(Void_t*)(d)) )
231 #define vmalign(vm,sz,align) (_VMFL_(vm), \
232 (*(_VM_(vm)->meth.alignf))((vm),(sz),(align)) )
234 #undef malloc
235 #undef realloc
236 #undef calloc
237 #undef free
238 #undef memalign
239 #undef valloc
241 #if _map_malloc
243 #define malloc(s) (_VMFL_(Vmregion), _ast_malloc((size_t)(s)) )
244 #define realloc(d,s) (_VMFL_(Vmregion), _ast_realloc((Void_t*)(d),(size_t)(s)) )
245 #define calloc(n,s) (_VMFL_(Vmregion), _ast_calloc((size_t)n, (size_t)(s)) )
246 #define free(d) (_VMFL_(Vmregion), _ast_free((Void_t*)(d)) )
247 #define memalign(a,s) (_VMFL_(Vmregion), _ast_memalign((size_t)(a),(size_t)(s)) )
248 #define valloc(s) (_VMFL_(Vmregion), _ast_valloc((size_t)(s) )
250 #else
252 #if !_std_malloc
254 #if __STD_C || defined(__STDPP__) || defined(__GNUC__)
255 #define malloc(s) ( _VMFL_(Vmregion), (malloc)((size_t)(s)) )
256 #define realloc(d,s) ( _VMFL_(Vmregion), (realloc)((Void_t*)(d),(size_t)(s)) )
257 #define calloc(n,s) ( _VMFL_(Vmregion), (calloc)((size_t)n, (size_t)(s)) )
258 #define free(d) ( _VMFL_(Vmregion), (free)((Void_t*)(d)) )
259 #define memalign(a,s) ( _VMFL_(Vmregion), (memalign)((size_t)(a),(size_t)(s)) )
260 #define valloc(s) ( _VMFL_(Vmregion), (valloc)((size_t)(s)) )
261 #ifndef strdup
262 #define strdup(s) ( _VMFL_(Vmregion), (strdup)((char*)(s)) )
263 #endif
265 #else
267 #define _VMNM_(a,b,c,d,e,f) a/**/b/**/c/**/d/**/e/**/f
268 #define malloc(s) ( _VMFL_(Vmregion), _VMNM_(mallo,/,*,*,/,c)\
269 ( (size_t)(s)) )
270 #define realloc(d,s) ( _VMFL_(Vmregion), _VMNM_(reallo,/,*,*,/,c)\
271 ( (Void_t*)(d),(size_t)(s)) )
272 #define calloc(n,s) ( _VMFL_(Vmregion), _VMNM_(callo,/,*,*,/,c)\
273 ( (size_t)n, (size_t)(s)) )
274 #define free(d) ( _VMFL_(Vmregion), _VMNM_(fre,/,*,*,/,e)((Void_t*)(d)) )
275 #define memalign(a,s) ( _VMFL_(Vmregion), _VMNM_(memalig,/,*,*,/,n)\
276 ( (size_t)(a),(size_t)(s)) )
277 #define valloc(s) ( _VMFL_(Vmregion), _VMNM_(vallo,/,*,*,/,c)\
278 ( (size_t)(s)) )
279 #ifndef strdup
280 #define strdup(s) ( _VMFL_(Vmregion), _VMNM_(strdu,/,*,*,/,p)\
281 ((char*)(s)) )
282 #endif
284 #endif /*__STD_C || defined(__STDPP__) || defined(__GNUC__)*/
286 #define cfree(d) free(d)
288 #endif /* !_std_malloc */
290 #endif /* _map_malloc */
292 #endif /*VMFL*/
294 /* non-debugging/profiling allocation calls */
295 #ifndef vmalloc
296 #define vmalloc(vm,sz) (*(_VM_(vm)->meth.allocf))((vm),(sz))
297 #endif
299 #ifndef vmresize
300 #define vmresize(vm,d,sz,type) (*(_VM_(vm)->meth.resizef))\
301 ((vm),(Void_t*)(d),(sz),(type))
302 #endif
304 #ifndef vmfree
305 #define vmfree(vm,d) (*(_VM_(vm)->meth.freef))((vm),(Void_t*)(d))
306 #endif
308 #ifndef vmalign
309 #define vmalign(vm,sz,align) (*(_VM_(vm)->meth.alignf))((vm),(sz),(align))
310 #endif
312 #define vmaddr(vm,addr) (*(_VM_(vm)->meth.addrf))((vm),(Void_t*)(addr))
313 #define vmsize(vm,addr) (*(_VM_(vm)->meth.sizef))((vm),(Void_t*)(addr))
314 #define vmcompact(vm) (*(_VM_(vm)->meth.compactf))((vm))
315 #define vmoldof(v,p,t,n,x) (t*)vmresize((v), (p), sizeof(t)*(n)+(x), \
316 (VM_RSMOVE) )
317 #define vmnewof(v,p,t,n,x) (t*)vmresize((v), (p), sizeof(t)*(n)+(x), \
318 (VM_RSMOVE|VM_RSCOPY|VM_RSZERO) )
319 #define vmdata(vm) ((Void_t*)(_VM_(vm)->data))
321 #endif /* _VMALLOC_H */