1181111Sdes/* $OpenBSD: monitor_mm.h,v 1.5 2008/04/29 11:20:31 otto Exp $ */ 298675Sdes 398675Sdes/* 498675Sdes * Copyright 2002 Niels Provos <provos@citi.umich.edu> 598675Sdes * All rights reserved. 698675Sdes * 798675Sdes * Redistribution and use in source and binary forms, with or without 898675Sdes * modification, are permitted provided that the following conditions 998675Sdes * are met: 1098675Sdes * 1. Redistributions of source code must retain the above copyright 1198675Sdes * notice, this list of conditions and the following disclaimer. 1298675Sdes * 2. Redistributions in binary form must reproduce the above copyright 1398675Sdes * notice, this list of conditions and the following disclaimer in the 1498675Sdes * documentation and/or other materials provided with the distribution. 1598675Sdes * 1698675Sdes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 1798675Sdes * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 1898675Sdes * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 1998675Sdes * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 2098675Sdes * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 2198675Sdes * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2298675Sdes * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2398675Sdes * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2498675Sdes * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 2598675Sdes * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2698675Sdes */ 2798675Sdes 2898675Sdes#ifndef _MM_H_ 2998675Sdes#define _MM_H_ 3098675Sdes 3198675Sdesstruct mm_share { 3298675Sdes RB_ENTRY(mm_share) next; 3398675Sdes void *address; 3498675Sdes size_t size; 3598675Sdes}; 3698675Sdes 3798675Sdesstruct mm_master { 3898675Sdes RB_HEAD(mmtree, mm_share) rb_free; 3998675Sdes struct mmtree rb_allocated; 4098675Sdes void *address; 4198675Sdes size_t size; 4298675Sdes 4398675Sdes struct mm_master *mmalloc; /* Used to completely share */ 4498675Sdes}; 4598675Sdes 4698675SdesRB_PROTOTYPE(mmtree, mm_share, next, mm_compare) 4798675Sdes 4898675Sdes#define MM_MINSIZE 128 4998675Sdes 5098675Sdes#define MM_ADDRESS_END(x) (void *)((u_char *)(x)->address + (x)->size) 5198675Sdes 5298675Sdesstruct mm_master *mm_create(struct mm_master *, size_t); 5398675Sdesvoid mm_destroy(struct mm_master *); 5498675Sdes 5598675Sdesvoid mm_share_sync(struct mm_master **, struct mm_master **); 5698675Sdes 5798675Sdesvoid *mm_malloc(struct mm_master *, size_t); 5898675Sdesvoid *mm_xmalloc(struct mm_master *, size_t); 5998675Sdesvoid mm_free(struct mm_master *, void *); 6098675Sdes 6198675Sdesvoid mm_memvalid(struct mm_master *, void *, size_t); 6298675Sdes#endif /* _MM_H_ */ 63