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: stable/11/stand/libsa/zalloc_defs.h 329132 2018-02-11 19:51:29Z kevans $ 3039665Smsmith */ 3139665Smsmith 3239665Smsmith/* 3339665Smsmith * DEFS.H 3439665Smsmith */ 3539665Smsmith 3639665Smsmith#define USEGUARD /* use stard/end guard bytes */ 3739665Smsmith#define USEENDGUARD 3839665Smsmith#define DMALLOCDEBUG /* add debugging code to gather stats */ 3939665Smsmith#define ZALLOCDEBUG 4039665Smsmith 41223904Skevlo#include <sys/stdint.h> 4239665Smsmith#include "stand.h" 4339665Smsmith#include "zalloc_mem.h" 4439665Smsmith 4539665Smsmith#define Library extern 4639665Smsmith 4739665Smsmith/* 4839665Smsmith * block extension for sbrk() 4939665Smsmith */ 5039665Smsmith 5140458Smsmith#define BLKEXTEND (4 * 1024) 5239665Smsmith#define BLKEXTENDMASK (BLKEXTEND - 1) 5339665Smsmith 5439665Smsmith/* 55261530Sian * Required malloc alignment. 5639665Smsmith * 57261530Sian * Embedded platforms using the u-boot API drivers require that all I/O buffers 58261530Sian * be on a cache line sized boundary. The worst case size for that is 64 bytes. 59261530Sian * For other platforms, 16 bytes works fine. The alignment also must be at 60261530Sian * least sizeof(struct MemNode); this is asserted in zalloc.c. 6139665Smsmith */ 6239665Smsmith 63261530Sian#if defined(__arm__) || defined(__mips__) || defined(__powerpc__) 64261530Sian#define MALLOCALIGN 64 65261530Sian#else 66261530Sian#define MALLOCALIGN 16 67261530Sian#endif 68261530Sian#define MALLOCALIGN_MASK (MALLOCALIGN - 1) 69261530Sian 7039665Smsmithtypedef struct Guard { 7139665Smsmith size_t ga_Bytes; 7239665Smsmith size_t ga_Magic; /* must be at least 32 bits */ 7339665Smsmith} Guard; 7439665Smsmith 7539665Smsmith#define GAMAGIC 0x55FF44FD 76100394Speter#define GAFREE 0x5F54F4DF 7739665Smsmith 7839665Smsmith#include "zalloc_protos.h" 79