zalloc_defs.h revision 100394
139665Smsmith/*
239665Smsmith * This module derived from code donated to the FreeBSD Project by
339665Smsmith * Matthew Dillon <dillon@backplane.com>
439665Smsmith *
539665Smsmith * Copyright (c) 1998 The FreeBSD Project
639665Smsmith * All rights reserved.
739665Smsmith *
839665Smsmith * Redistribution and use in source and binary forms, with or without
939665Smsmith * modification, are permitted provided that the following conditions
1039665Smsmith * are met:
1139665Smsmith * 1. Redistributions of source code must retain the above copyright
1239665Smsmith *    notice, this list of conditions and the following disclaimer.
1339665Smsmith * 2. Redistributions in binary form must reproduce the above copyright
1439665Smsmith *    notice, this list of conditions and the following disclaimer in the
1539665Smsmith *    documentation and/or other materials provided with the distribution.
1639665Smsmith *
1739665Smsmith * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1839665Smsmith * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1939665Smsmith * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2039665Smsmith * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2139665Smsmith * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2239665Smsmith * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2339665Smsmith * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2439665Smsmith * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2539665Smsmith * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2639665Smsmith * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2739665Smsmith * SUCH DAMAGE.
2839665Smsmith *
2950476Speter * $FreeBSD: head/lib/libstand/zalloc_defs.h 100394 2002-07-20 04:18:20Z peter $
3039665Smsmith */
3139665Smsmith
3239665Smsmith/*
3339665Smsmith * DEFS.H
3439665Smsmith */
3539665Smsmith
3639665Smsmith#define USEGUARD		/* use stard/end guard bytes */
3768545Sbenno#if !defined(__powerpc__)
3839665Smsmith#define USEENDGUARD
3968545Sbenno#endif
4039665Smsmith#define DMALLOCDEBUG		/* add debugging code to gather stats */
4139665Smsmith#define ZALLOCDEBUG
4239665Smsmith
4339665Smsmith#include <string.h>
4439665Smsmith#include "stand.h"
4539665Smsmith
4639672Sdfr#ifdef __i386__
4739665Smsmithtypedef unsigned int iaddr_t;	/* unsigned int same size as pointer	*/
4839665Smsmithtypedef int saddr_t;		/* signed int same size as pointer	*/
4939672Sdfr#endif
5039672Sdfr#ifdef __alpha__
5139672Sdfrtypedef unsigned long iaddr_t;	/* unsigned int same size as pointer	*/
5239672Sdfrtypedef long saddr_t;		/* signed int same size as pointer	*/
5339672Sdfr#endif
5466929Sobrien#ifdef __powerpc__
5566929Sobrientypedef unsigned int iaddr_t;	/* unsigned int same size as pointer	*/
5666929Sobrientypedef int saddr_t;		/* signed int same size as pointer	*/
5766929Sobrien#endif
5873887Sdfr#ifdef __ia64__
5973887Sdfrtypedef unsigned long iaddr_t;	/* unsigned int same size as pointer	*/
6073887Sdfrtypedef long saddr_t;		/* signed int same size as pointer	*/
6173887Sdfr#endif
6284993Srobert#ifdef __sparc64__
6384993Sroberttypedef unsigned long iaddr_t;	/* unsigned long same size as pointer	*/
6484993Sroberttypedef long saddr_t;		/* signed long same size as pointer	*/
6584993Srobert#endif
6639665Smsmith
6739665Smsmith#include "zalloc_mem.h"
6839665Smsmith
6939665Smsmith#define Prototype extern
7039665Smsmith#define Library extern
7139665Smsmith
7239665Smsmith#ifndef NULL
7339665Smsmith#define NULL	((void *)0)
7439665Smsmith#endif
7539665Smsmith
7639665Smsmith/*
7739665Smsmith * block extension for sbrk()
7839665Smsmith */
7939665Smsmith
8040458Smsmith#define BLKEXTEND	(4 * 1024)
8139665Smsmith#define BLKEXTENDMASK	(BLKEXTEND - 1)
8239665Smsmith
8339665Smsmith/*
8439665Smsmith * required malloc alignment.  Use sizeof(long double) for architecture
8539665Smsmith * independance.
8639665Smsmith *
8739665Smsmith * Note: if we implement a more sophisticated realloc, we should ensure that
8839665Smsmith * MALLOCALIGN is at least as large as MemNode.
8939665Smsmith */
9039665Smsmith
9139665Smsmithtypedef struct Guard {
9239665Smsmith    size_t	ga_Bytes;
9339665Smsmith    size_t	ga_Magic;	/* must be at least 32 bits */
9439665Smsmith} Guard;
9539665Smsmith
9639665Smsmith#define MATYPE		long double
9739665Smsmith#define MALLOCALIGN	((sizeof(MATYPE) > sizeof(Guard)) ? sizeof(MATYPE) : sizeof(Guard))
9839665Smsmith#define GAMAGIC		0x55FF44FD
99100394Speter#define GAFREE		0x5F54F4DF
10039665Smsmith
10139665Smsmith#include "zalloc_protos.h"
10239665Smsmith
103