da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin/***********************************************************************
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* This software is part of the ast package *
3e14f97f673e8a630f076077de35afdd43dc1587Roger A. Faulkner* Copyright (c) 1985-2010 AT&T Intellectual Property *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* and is licensed under the *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* Common Public License, Version 1.0 *
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin* by AT&T Intellectual Property *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* A copy of the License is available at *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* http://www.opensource.org/licenses/cpl1.0.txt *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* Information and Software Systems Research *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* AT&T Research *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* Florham Park NJ *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* Glenn Fowler <gsf@research.att.com> *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* David Korn <dgk@research.att.com> *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* Phong Vo <kpv@research.att.com> *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin***********************************************************************/
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#ifndef _VMALLOC_H
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define _VMALLOC_H 1
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin/* Public header file for the virtual malloc package.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin**
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin** Written by Kiem-Phong Vo, kpv@research.att.com, 01/16/94.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin*/
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
3e14f97f673e8a630f076077de35afdd43dc1587Roger A. Faulkner#define VMALLOC_VERSION 20100101L
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#if _PACKAGE_ast
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#include <ast_std.h>
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#else
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#include <ast_common.h>
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#endif
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chintypedef struct _vmalloc_s Vmalloc_t;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chintypedef struct _vmstat_s Vmstat_t;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chintypedef struct _vmdisc_s Vmdisc_t;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chintypedef struct _vmethod_s Vmethod_t;
3e14f97f673e8a630f076077de35afdd43dc1587Roger A. Faulknertypedef struct _vmdata_s Vmdata_t;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chintypedef Void_t* (*Vmemory_f)_ARG_((Vmalloc_t*, Void_t*, size_t, size_t, Vmdisc_t*));
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chintypedef int (*Vmexcept_f)_ARG_((Vmalloc_t*, int, Void_t*, Vmdisc_t*));
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstruct _vmstat_s
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin{ int n_busy; /* number of busy blocks */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin int n_free; /* number of free blocks */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin size_t s_busy; /* total amount of busy space */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin size_t s_free; /* total amount of free space */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin size_t m_busy; /* largest busy piece */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin size_t m_free; /* largest free piece */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin int n_seg; /* number of segments */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin size_t extent; /* total size of region */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin};
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstruct _vmdisc_s
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin{ Vmemory_f memoryf; /* memory manipulator */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin Vmexcept_f exceptf; /* exception handler */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin size_t round; /* rounding requirement */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin};
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstruct _vmethod_s
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin{ Void_t* (*allocf)_ARG_((Vmalloc_t*,size_t));
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin Void_t* (*resizef)_ARG_((Vmalloc_t*,Void_t*,size_t,int));
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin int (*freef)_ARG_((Vmalloc_t*,Void_t*));
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin long (*addrf)_ARG_((Vmalloc_t*,Void_t*));
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin long (*sizef)_ARG_((Vmalloc_t*,Void_t*));
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin int (*compactf)_ARG_((Vmalloc_t*));
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin Void_t* (*alignf)_ARG_((Vmalloc_t*,size_t,size_t));
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin unsigned short meth;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin};
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstruct _vmalloc_s
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin{ Vmethod_t meth; /* method for allocation */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin char* file; /* file name */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin int line; /* line number */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin Void_t* func; /* calling function */
3e14f97f673e8a630f076077de35afdd43dc1587Roger A. Faulkner Vmdisc_t* disc; /* discipline to get space */
3e14f97f673e8a630f076077de35afdd43dc1587Roger A. Faulkner Vmdata_t* data; /* the real region data */
3e14f97f673e8a630f076077de35afdd43dc1587Roger A. Faulkner Vmalloc_t* next; /* linked list of regions */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#ifdef _VM_PRIVATE_
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin _VM_PRIVATE_
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#endif
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin};
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#undef VM_FLAGS /* solaris sys kernel clash */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define VM_TRUST 0000001 /* forgo some security checks */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define VM_TRACE 0000002 /* generate trace */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define VM_DBCHECK 0000004 /* check for boundary overwrite */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define VM_DBABORT 0000010 /* abort on any warning */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define VM_FLAGS 0000017 /* user-settable flags */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define VM_MTBEST 0000100 /* Vmbest method */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define VM_MTPOOL 0000200 /* Vmpool method */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define VM_MTLAST 0000400 /* Vmlast method */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define VM_MTDEBUG 0001000 /* Vmdebug method */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define VM_MTPROFILE 0002000 /* Vmdebug method */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define VM_METHODS 0003700 /* available allocation methods */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define VM_RSCOPY 0000001 /* copy old contents */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define VM_RSMOVE 0000002 /* old contents is moveable */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define VM_RSZERO 0000004 /* clear new space */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin/* exception types */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define VM_OPEN 0 /* region being opened */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define VM_CLOSE 1 /* announce being closed */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define VM_NOMEM 2 /* can't obtain memory */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define VM_BADADDR 3 /* bad addr in vmfree/vmresize */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define VM_DISC 4 /* discipline being changed */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define VM_ALLOC 5 /* announcement from vmalloc() */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define VM_FREE 6 /* announcement from vmfree() */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define VM_RESIZE 7 /* announcement from vmresize() */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin_BEGIN_EXTERNS_ /* public data */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#if _BLD_vmalloc && defined(__EXPORT__)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define extern extern __EXPORT__
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#endif
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#if !_BLD_vmalloc && defined(__IMPORT__)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define extern extern __IMPORT__
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#endif
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern Vmethod_t* Vmbest; /* best allocation */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern Vmethod_t* Vmlast; /* last-block allocation */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern Vmethod_t* Vmpool; /* pool allocation */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern Vmethod_t* Vmdebug; /* allocation with debugging */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern Vmethod_t* Vmprofile; /* profiling memory usage */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern Vmdisc_t* Vmdcheap; /* heap discipline */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern Vmdisc_t* Vmdcsbrk; /* sbrk discipline */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern Vmalloc_t* Vmheap; /* heap region */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern Vmalloc_t* Vmregion; /* malloc region */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#undef extern
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin_END_EXTERNS_
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin_BEGIN_EXTERNS_ /* public functions */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#if _BLD_vmalloc && defined(__EXPORT__)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define extern __EXPORT__
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#endif
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern Vmalloc_t* vmopen _ARG_(( Vmdisc_t*, Vmethod_t*, int ));
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern int vmclose _ARG_(( Vmalloc_t* ));
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern int vmclear _ARG_(( Vmalloc_t* ));
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern int vmcompact _ARG_(( Vmalloc_t* ));
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern Vmdisc_t* vmdisc _ARG_(( Vmalloc_t*, Vmdisc_t* ));
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern Vmalloc_t* vmmopen _ARG_(( char*, Void_t*, size_t ));
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern Void_t* vmmset _ARG_((Vmalloc_t*, int, Void_t*, int));
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern Void_t* vmalloc _ARG_(( Vmalloc_t*, size_t ));
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern Void_t* vmalign _ARG_(( Vmalloc_t*, size_t, size_t ));
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern Void_t* vmresize _ARG_(( Vmalloc_t*, Void_t*, size_t, int ));
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern Void_t* vmgetmem _ARG_(( Vmalloc_t*, Void_t*, size_t ));
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern int vmfree _ARG_(( Vmalloc_t*, Void_t* ));
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern long vmaddr _ARG_(( Vmalloc_t*, Void_t* ));
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern long vmsize _ARG_(( Vmalloc_t*, Void_t* ));
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern Vmalloc_t* vmregion _ARG_(( Void_t* ));
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern Void_t* vmsegment _ARG_(( Vmalloc_t*, Void_t* ));
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern int vmset _ARG_(( Vmalloc_t*, int, int ));
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern Void_t* vmdbwatch _ARG_(( Void_t* ));
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern int vmdbcheck _ARG_(( Vmalloc_t* ));
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern int vmdebug _ARG_(( int ));
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern int vmprofile _ARG_(( Vmalloc_t*, int ));
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern int vmtrace _ARG_(( int ));
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern int vmtrbusy _ARG_((Vmalloc_t*));
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern int vmstat _ARG_((Vmalloc_t*, Vmstat_t*));
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern int vmwalk _ARG_((Vmalloc_t*,
3e14f97f673e8a630f076077de35afdd43dc1587Roger A. Faulkner int(*)(Vmalloc_t*,Void_t*,size_t,Vmdisc_t*,Void_t*),
3e14f97f673e8a630f076077de35afdd43dc1587Roger A. Faulkner Void_t*));
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern char* vmstrdup _ARG_((Vmalloc_t*, const char*));
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#if !defined(_BLD_vmalloc) && !defined(_AST_STD_H) && \
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin !defined(__stdlib_h) && !defined(__STDLIB_H) && \
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin !defined(_STDLIB_INCLUDED) && !defined(_INC_STDLIB)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern Void_t* malloc _ARG_(( size_t ));
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern Void_t* realloc _ARG_(( Void_t*, size_t ));
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern void free _ARG_(( Void_t* ));
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern void cfree _ARG_(( Void_t* ));
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern Void_t* calloc _ARG_(( size_t, size_t ));
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern Void_t* memalign _ARG_(( size_t, size_t ));
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinextern Void_t* valloc _ARG_(( size_t ));
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#endif
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#undef extern
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin_END_EXTERNS_
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin/* to coerce any value to a Vmalloc_t*, make ANSI happy */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define _VM_(vm) ((Vmalloc_t*)(vm))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin/* enable recording of where a call originates from */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#ifdef VMFL
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#if defined(__FILE__)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define _VMFILE_(vm) (_VM_(vm)->file = (char*)__FILE__)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#else
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define _VMFILE_(vm) (_VM_(vm)->file = 0)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#endif
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#if defined(__LINE__)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define _VMLINE_(vm) (_VM_(vm)->line = __LINE__)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#else
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define _VMLINE_(vm) (_VM_(vm)->line = 0)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#endif
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#if defined(__FUNCTION__)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define _VMFUNC_(vm) (_VM_(vm)->func = (Void_t*)__FUNCTION__)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#else
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define _VMFUNC_(vm) (_VM_(vm)->func = 0)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#endif
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define _VMFL_(vm) (_VMFILE_(vm), _VMLINE_(vm), _VMFUNC_(vm))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define vmalloc(vm,sz) (_VMFL_(vm), \
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin (*(_VM_(vm)->meth.allocf))((vm),(sz)) )
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define vmresize(vm,d,sz,type) (_VMFL_(vm), \
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin (*(_VM_(vm)->meth.resizef))\
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin ((vm),(Void_t*)(d),(sz),(type)) )
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define vmfree(vm,d) (_VMFL_(vm), \
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin (*(_VM_(vm)->meth.freef))((vm),(Void_t*)(d)) )
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define vmalign(vm,sz,align) (_VMFL_(vm), \
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin (*(_VM_(vm)->meth.alignf))((vm),(sz),(align)) )
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#undef malloc
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#undef realloc
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#undef calloc
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#undef free
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#undef memalign
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#undef valloc
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#if _map_malloc
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define malloc(s) (_VMFL_(Vmregion), _ast_malloc((size_t)(s)) )
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define realloc(d,s) (_VMFL_(Vmregion), _ast_realloc((Void_t*)(d),(size_t)(s)) )
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define calloc(n,s) (_VMFL_(Vmregion), _ast_calloc((size_t)n, (size_t)(s)) )
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define free(d) (_VMFL_(Vmregion), _ast_free((Void_t*)(d)) )
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define memalign(a,s) (_VMFL_(Vmregion), _ast_memalign((size_t)(a),(size_t)(s)) )
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define valloc(s) (_VMFL_(Vmregion), _ast_valloc((size_t)(s) )
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#else
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#if !_std_malloc
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#if __STD_C || defined(__STDPP__) || defined(__GNUC__)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define malloc(s) ( _VMFL_(Vmregion), (malloc)((size_t)(s)) )
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define realloc(d,s) ( _VMFL_(Vmregion), (realloc)((Void_t*)(d),(size_t)(s)) )
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define calloc(n,s) ( _VMFL_(Vmregion), (calloc)((size_t)n, (size_t)(s)) )
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define free(d) ( _VMFL_(Vmregion), (free)((Void_t*)(d)) )
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define memalign(a,s) ( _VMFL_(Vmregion), (memalign)((size_t)(a),(size_t)(s)) )
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define valloc(s) ( _VMFL_(Vmregion), (valloc)((size_t)(s)) )
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#ifndef strdup
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define strdup(s) ( _VMFL_(Vmregion), (strdup)((char*)(s)) )
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#endif
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#else
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define _VMNM_(a,b,c,d,e,f) a/**/b/**/c/**/d/**/e/**/f
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define malloc(s) ( _VMFL_(Vmregion), _VMNM_(mallo,/,*,*,/,c)\
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin ( (size_t)(s)) )
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define realloc(d,s) ( _VMFL_(Vmregion), _VMNM_(reallo,/,*,*,/,c)\
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin ( (Void_t*)(d),(size_t)(s)) )
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define calloc(n,s) ( _VMFL_(Vmregion), _VMNM_(callo,/,*,*,/,c)\
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin ( (size_t)n, (size_t)(s)) )
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define free(d) ( _VMFL_(Vmregion), _VMNM_(fre,/,*,*,/,e)((Void_t*)(d)) )
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define memalign(a,s) ( _VMFL_(Vmregion), _VMNM_(memalig,/,*,*,/,n)\
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin ( (size_t)(a),(size_t)(s)) )
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define valloc(s) ( _VMFL_(Vmregion), _VMNM_(vallo,/,*,*,/,c)\
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin ( (size_t)(s)) )
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#ifndef strdup
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define strdup(s) ( _VMFL_(Vmregion), _VMNM_(strdu,/,*,*,/,p)\
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin ((char*)(s)) )
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#endif
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#endif /*__STD_C || defined(__STDPP__) || defined(__GNUC__)*/
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define cfree(d) free(d)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#endif /* !_std_malloc */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#endif /* _map_malloc */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#endif /*VMFL*/
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin/* non-debugging/profiling allocation calls */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#ifndef vmalloc
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define vmalloc(vm,sz) (*(_VM_(vm)->meth.allocf))((vm),(sz))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#endif
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#ifndef vmresize
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define vmresize(vm,d,sz,type) (*(_VM_(vm)->meth.resizef))\
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin ((vm),(Void_t*)(d),(sz),(type))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#endif
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#ifndef vmfree
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define vmfree(vm,d) (*(_VM_(vm)->meth.freef))((vm),(Void_t*)(d))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#endif
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#ifndef vmalign
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define vmalign(vm,sz,align) (*(_VM_(vm)->meth.alignf))((vm),(sz),(align))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#endif
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define vmaddr(vm,addr) (*(_VM_(vm)->meth.addrf))((vm),(Void_t*)(addr))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define vmsize(vm,addr) (*(_VM_(vm)->meth.sizef))((vm),(Void_t*)(addr))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define vmcompact(vm) (*(_VM_(vm)->meth.compactf))((vm))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define vmoldof(v,p,t,n,x) (t*)vmresize((v), (p), sizeof(t)*(n)+(x), \
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin (VM_RSMOVE) )
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define vmnewof(v,p,t,n,x) (t*)vmresize((v), (p), sizeof(t)*(n)+(x), \
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin (VM_RSMOVE|VM_RSCOPY|VM_RSZERO) )
3e14f97f673e8a630f076077de35afdd43dc1587Roger A. Faulkner#define vmdata(vm) ((Void_t*)(_VM_(vm)->data))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#endif /* _VMALLOC_H */