1da2e3ebdSchin /***********************************************************************
2da2e3ebdSchin *                                                                      *
3da2e3ebdSchin *               This software is part of the ast package               *
4*b30d1939SAndy Fiddaman *          Copyright (c) 1985-2012 AT&T Intellectual Property          *
5da2e3ebdSchin *                      and is licensed under the                       *
6*b30d1939SAndy Fiddaman *                 Eclipse Public License, Version 1.0                  *
77c2fbfb3SApril Chin *                    by AT&T Intellectual Property                     *
8da2e3ebdSchin *                                                                      *
9da2e3ebdSchin *                A copy of the License is available at                 *
10*b30d1939SAndy Fiddaman *          http://www.eclipse.org/org/documents/epl-v10.html           *
11*b30d1939SAndy Fiddaman *         (with md5 checksum b35adb5213ca9657e911e9befb180842)         *
12da2e3ebdSchin *                                                                      *
13da2e3ebdSchin *              Information and Software Systems Research               *
14da2e3ebdSchin *                            AT&T Research                             *
15da2e3ebdSchin *                           Florham Park NJ                            *
16da2e3ebdSchin *                                                                      *
17da2e3ebdSchin *                 Glenn Fowler <gsf@research.att.com>                  *
18da2e3ebdSchin *                  David Korn <dgk@research.att.com>                   *
19da2e3ebdSchin *                   Phong Vo <kpv@research.att.com>                    *
20da2e3ebdSchin *                                                                      *
21da2e3ebdSchin ***********************************************************************/
22da2e3ebdSchin /*
23*b30d1939SAndy Fiddaman  * standalone mini vmalloc interface
24da2e3ebdSchin  */
25da2e3ebdSchin 
26*b30d1939SAndy Fiddaman #ifndef _VMALLOC_H
27*b30d1939SAndy Fiddaman #define _VMALLOC_H		1
28da2e3ebdSchin 
29*b30d1939SAndy Fiddaman #define vmalloc(v,n)		_vm_resize(v,(void*)0,n)
30*b30d1939SAndy Fiddaman #define vmalign(v,n,a)		_vm_resize(v,(void*)0,n)
31*b30d1939SAndy Fiddaman #define vmclose(v)		_vm_close(v)
32*b30d1939SAndy Fiddaman #define vmfree(v,p)
33*b30d1939SAndy Fiddaman #define vmnewof(v,o,t,n,x)	(t*)_vm_resize(v,(void*)o,sizeof(t)*(n)+(x))
34*b30d1939SAndy Fiddaman #define vmopen(a,b,c)		_vm_open()
35da2e3ebdSchin 
36*b30d1939SAndy Fiddaman #define VM_CHUNK		(32*1024)
37*b30d1939SAndy Fiddaman #define VM_ALIGN		16
38da2e3ebdSchin 
39*b30d1939SAndy Fiddaman typedef struct Vmchunk_s
40da2e3ebdSchin {
41*b30d1939SAndy Fiddaman 	struct Vmchunk_s*	next;
42*b30d1939SAndy Fiddaman 	char			align[VM_ALIGN - sizeof(struct Vmchunk_s*)];
43*b30d1939SAndy Fiddaman 	char			data[VM_CHUNK - VM_ALIGN];
44*b30d1939SAndy Fiddaman } Vmchunk_t;
45da2e3ebdSchin 
46*b30d1939SAndy Fiddaman typedef struct Vmalloc_s
47da2e3ebdSchin {
48*b30d1939SAndy Fiddaman 	Vmchunk_t		base;
49*b30d1939SAndy Fiddaman 	Vmchunk_t*		current;
50*b30d1939SAndy Fiddaman 	char*			data;
51*b30d1939SAndy Fiddaman 	long			size;
52*b30d1939SAndy Fiddaman 	long			last;
53*b30d1939SAndy Fiddaman } Vmalloc_t;
54da2e3ebdSchin 
55*b30d1939SAndy Fiddaman extern Vmalloc_t*		Vmregion;
56*b30d1939SAndy Fiddaman 
57*b30d1939SAndy Fiddaman extern int			_vm_close(Vmalloc_t*);
58*b30d1939SAndy Fiddaman extern Vmalloc_t*		_vm_open(void);
59*b30d1939SAndy Fiddaman extern void*			_vm_resize(Vmalloc_t*, void*, unsigned long);
60da2e3ebdSchin 
61*b30d1939SAndy Fiddaman #endif
62