xref: /illumos-gate/usr/src/contrib/ast/src/lib/libast/astsa/vmalloc.h (revision 472cd20d26008f77084ade4c2048159b98c2b705)
1 /***********************************************************************
2 *                                                                      *
3 *               This software is part of the ast package               *
4 *          Copyright (c) 1985-2012 AT&T Intellectual Property          *
5 *                      and is licensed under the                       *
6 *                 Eclipse Public License, Version 1.0                  *
7 *                    by AT&T Intellectual Property                     *
8 *                                                                      *
9 *                A copy of the License is available at                 *
10 *          http://www.eclipse.org/org/documents/epl-v10.html           *
11 *         (with md5 checksum b35adb5213ca9657e911e9befb180842)         *
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 /*
23  * standalone mini vmalloc interface
24  */
25 
26 #ifndef _VMALLOC_H
27 #define _VMALLOC_H		1
28 
29 #define vmalloc(v,n)		_vm_resize(v,(void*)0,n)
30 #define vmalign(v,n,a)		_vm_resize(v,(void*)0,n)
31 #define vmclose(v)		_vm_close(v)
32 #define vmfree(v,p)
33 #define vmnewof(v,o,t,n,x)	(t*)_vm_resize(v,(void*)o,sizeof(t)*(n)+(x))
34 #define vmopen(a,b,c)		_vm_open()
35 
36 #define VM_CHUNK		(32*1024)
37 #define VM_ALIGN		16
38 
39 typedef struct Vmchunk_s
40 {
41 	struct Vmchunk_s*	next;
42 	char			align[VM_ALIGN - sizeof(struct Vmchunk_s*)];
43 	char			data[VM_CHUNK - VM_ALIGN];
44 } Vmchunk_t;
45 
46 typedef struct Vmalloc_s
47 {
48 	Vmchunk_t		base;
49 	Vmchunk_t*		current;
50 	char*			data;
51 	long			size;
52 	long			last;
53 } Vmalloc_t;
54 
55 extern Vmalloc_t*		Vmregion;
56 
57 extern int			_vm_close(Vmalloc_t*);
58 extern Vmalloc_t*		_vm_open(void);
59 extern void*			_vm_resize(Vmalloc_t*, void*, unsigned long);
60 
61 #endif
62