/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1985-2012 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* David Korn <dgk@research.att.com> *
* Phong Vo <kpv@research.att.com> *
* *
***********************************************************************/
#ifndef _VMHDR_H
#ifndef _BLD_vmalloc
#endif
/* Common types, and macros for vmalloc functions.
**
** Written by Kiem-Phong Vo, kpv@research.att.com, 01/16/94.
*/
#ifdef __STDC__
#else
#if __cplusplus || c_plusplus
#else
#define __STD_C 0
#endif /*__cplusplus*/
#endif /*__STDC__*/
#endif /*__STD_C*/
#if _PACKAGE_ast
#if !_UWIN
#endif
#include <ast.h>
#if _npt_getpagesize
#endif
#if _npt_sbrk
#endif
#else
#include <ast_common.h>
#if !_UWIN
#endif
#endif /*_PACKAGE_ast*/
#include <aso.h> /* atomic scalor operations */
#include <setjmp.h> /* use the type jmp_buf for alignment */
/* extra information needed about methods to get memory from the system */
#if defined(_WIN32)
#endif
#endif
typedef unsigned char Vmuchar_t;
typedef unsigned long Vmulong_t;
#define NIL(t) ((t)0)
#define reg register
#if __STD_C
#define NOTUSED(x) (void)(x)
#else
#endif
/* convert an address to an integral value */
/* Round x up to a multiple of y. ROUND2 does powers-of-2 and ROUNDX does others */
/* compute a value that is a common multiple of x and y */
#define MULTIPLE(x,y) ((x)%(y) == 0 ? (x) : (y)%(x) == 0 ? (y) : (y)*(x))
#if _UWIN
#include <ast_windows.h>
#endif
#ifndef DEBUG
#ifdef _BLD_DEBUG
#endif /*_BLD_DEBUG*/
#endif /*DEBUG*/
#if DEBUG
extern void _vmmessage _ARG_((const char*, long, const char*, long));
#else
#define ABORT() (0)
#define ASSERT(p)
#define CHECK() (0)
#define COUNT(n)
#define MESSAGE(s) (0)
#endif /*DEBUG*/
#if _lib_getpagesize
#else
#endif
/* Blocks are allocated such that their sizes are 0%(BITS+1)
** This frees up enough low order bits to store state information
*/
/* lock and unlock regions during concurrent accesses */
/* local calls */
/* ALIGN is chosen so that a block can store all primitive types.
** It should also be a multiple of ALIGNB==(BITS+1) so the size field
** of Block_t will always be 0%(BITS+1) as noted above.
** Of paramount importance is the ALIGNA macro below. If the local compile
** environment is strange enough that the below method does not calculate
** ALIGNA right, then the code below should be commented out and ALIGNA
** redefined to the appropriate requirement.
*/
union _align_u
{ char c, *cp;
int i, *ip;
long l, *lp;
void(* fn)();
};
struct _a_s
{ char c;
union _align_u a;
};
struct _align_s
};
/* make sure that the head of a block is a multiple of ALIGN */
struct _head_s
{ union
} seg;
union
} size;
};
union _head_u
};
/* now make sure that the body of a block is a multiple of ALIGN */
struct _body_s
};
union _body_u
};
/* After all the songs and dances, we should now have:
** sizeof(Head_t)%ALIGN == 0
** sizeof(Body_t)%ALIGN == 0
** and sizeof(Block_t) = sizeof(Head_t)+sizeof(Body_t)
*/
struct _block_s
};
/* requirements for smallest block type */
struct _tiny_s
};
/* small block types kept in separate caches for quick allocation */
};
#include "vmalloc.h"
#if !_PACKAGE_ast
/* we don't use these here and they interfere with some local names */
#endif
/* segment structure */
struct _seg_s
};
/* starting block of a segment */
/* short-hands for block data */
/* functions to manipulate link lists of elts of the same size */
/* delete a block from a link list or the free tree.
** The test in the below macro is worth scratching your head a bit.
** Even though tiny blocks (size < BODYSIZE) are kept in separate lists,
** only the TINIEST ones require TLEFT(b) for the back link. Since this
** destroys the SEG(b) pointer, it must be carefully restored in bestsearch().
** Other tiny blocks have enough space to use the usual LEFT(b).
** In this case, I have also carefully arranged so that RIGHT(b) and
** SELF(b) can be overlapped and the test ISLINK() will go through.
*/
/* see if a block is the wilderness block */
/* The lay-out of a Vmprofile block is this:
** seg_ size ----data---- _pf_ size
** _________ ____________ _________
** seg_, size: header required by Vmbest.
** data: actual data block.
** _pf_: pointer to the corresponding Pfobj_t struct
** size: the true size of the block.
** So each block requires an extra Head_t.
*/
/* The lay-out of a block allocated by Vmdebug is this:
** seg_ size file size seg_ magi ----data---- --magi-- magi line
** --------- --------- --------- ------------ -------- ---------
** seg_,size: header required by Vmbest management.
** file: the file where it was created.
** size: the true byte count of the block
** seg_: should be the same as the previous seg_.
** This allows the function vmregion() to work.
** magi: magic bytes to detect overwrites.
** data: the actual data block.
** magi: more magic bytes.
** line: the line number in the file where it was created.
** So for each allocated block, we'll need 3 extra Head_t.
*/
/* convenient macros for accessing the above fields */
/* set file and line number, note that DBLN > 0 so that DBISBAD will work */
/* set and test the state of known to be corrupted */
/* compute the bounds of the magic areas */
/* external symbols for use inside vmalloc only */
typedef struct _vmextern_s
unsigned int vm_lock;
int vm_assert;
int vm_options;
} Vmextern_t;
extern void _vmoptions _ARG_((void));
extern Vmextern_t _Vmextern;
#if _PACKAGE_ast
#if _npt_getpagesize
extern int getpagesize _ARG_((void));
#endif
#if _npt_sbrk
#endif
#else
#if _hdr_unistd
#include <unistd.h>
#else
extern int getpagesize _ARG_((void));
#endif
#if !__STDC__ && !_hdr_stdlib
#else
#include <stdlib.h>
#include <string.h>
#endif
/* for vmexit.c */
#endif /*_PACKAGE_ast*/
/* for vmdcsbrk.c */
#if !_typ_ssize_t
typedef int ssize_t;
#endif
#endif /* _VMHDR_H */