monitor_mm.h revision 98675
139287Ssos/*	$OpenBSD: monitor_mm.h,v 1.2 2002/03/26 03:24:01 stevesk Exp $	*/
239643Syokota
339287Ssos/*
439287Ssos * Copyright 2002 Niels Provos <provos@citi.umich.edu>
539287Ssos * All rights reserved.
639287Ssos *
739287Ssos * Redistribution and use in source and binary forms, with or without
839287Ssos * modification, are permitted provided that the following conditions
939643Syokota * are met:
1039643Syokota * 1. Redistributions of source code must retain the above copyright
1139287Ssos *    notice, this list of conditions and the following disclaimer.
1239287Ssos * 2. Redistributions in binary form must reproduce the above copyright
1339287Ssos *    notice, this list of conditions and the following disclaimer in the
1439287Ssos *    documentation and/or other materials provided with the distribution.
1539643Syokota *
1639643Syokota * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1739643Syokota * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1839643Syokota * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1939643Syokota * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
2039643Syokota * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2139643Syokota * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2239643Syokota * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2339643Syokota * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2439643Syokota * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2539287Ssos * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2639287Ssos */
27115703Sobrien
28115703Sobrien#ifndef _MM_H_
29115703Sobrien#define _MM_H_
3042504Syokota#include <sys/tree.h>
3166710Sjhb
3239287Ssosstruct mm_share {
3356836Speter	RB_ENTRY(mm_share) next;
3439287Ssos	void *address;
3539287Ssos	size_t size;
3639287Ssos};
3739287Ssos
3842179Syokotastruct mm_master {
3939287Ssos	RB_HEAD(mmtree, mm_share) rb_free;
4048104Syokota	struct mmtree rb_allocated;
4148104Syokota	void *address;
4239287Ssos	size_t size;
4348104Syokota
4448104Syokota	struct mm_master *mmalloc;	/* Used to completely share */
45130312Sjhb
4639287Ssos	int write;		/* used to writing to other party */
4739287Ssos	int read;		/* used for reading from other party */
48197383Sdelphij};
49197025Sdelphij
5039287SsosRB_PROTOTYPE(mmtree, mm_share, next, mm_compare)
5142504Syokota
5242504Syokota#define MM_MINSIZE		128
5339287Ssos
5442504Syokota#define MM_ADDRESS_END(x)	(void *)((u_char *)(x)->address + (x)->size)
5542504Syokota
56197383Sdelphijstruct mm_master *mm_create(struct mm_master *, size_t);
57197025Sdelphijvoid mm_destroy(struct mm_master *);
58117710Srobert
59117710Srobertvoid mm_share_sync(struct mm_master **, struct mm_master **);
6042504Syokota
6142611Syokotavoid *mm_malloc(struct mm_master *, size_t);
6242504Syokotavoid *mm_xmalloc(struct mm_master *, size_t);
6342504Syokotavoid mm_free(struct mm_master *, void *);
6439287Ssos
6539287Ssosvoid mm_memvalid(struct mm_master *, void *, size_t);
6639287Ssos#endif /* _MM_H_ */
6739287Ssos