Home | History | Annotate | Line # | Download | only in omapip
      1 /*	$NetBSD: alloc.h,v 1.3 2022/04/03 01:10:59 christos Exp $	*/
      2 
      3 /* alloc.h
      4 
      5    Definitions for the object management API protocol memory allocation... */
      6 
      7 /*
      8  * Copyright (C) 2004-2022 Internet Systems Consortium, Inc. ("ISC")
      9  * Copyright (c) 1996-2003 by Internet Software Consortium
     10  *
     11  * This Source Code Form is subject to the terms of the Mozilla Public
     12  * License, v. 2.0. If a copy of the MPL was not distributed with this
     13  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
     14  *
     15  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
     16  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
     17  * MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR
     18  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
     19  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
     20  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
     21  * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
     22  *
     23  *   Internet Systems Consortium, Inc.
     24  *   PO Box 360
     25  *   Newmarket, NH 03857 USA
     26  *   <info (at) isc.org>
     27  *   https://www.isc.org/
     28  *
     29  */
     30 
     31 isc_result_t omapi_buffer_new (omapi_buffer_t **, const char *, int);
     32 isc_result_t omapi_buffer_reference (omapi_buffer_t **,
     33 				     omapi_buffer_t *, const char *, int);
     34 isc_result_t omapi_buffer_dereference (omapi_buffer_t **, const char *, int);
     35 
     36 #if defined (DEBUG_MEMORY_LEAKAGE) || defined (DEBUG_MALLOC_POOL) || \
     37 		defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)
     38 #define DMDOFFSET (sizeof (struct dmalloc_preamble))
     39 #define DMLFSIZE 16
     40 #define DMUFSIZE 16
     41 #define DMDSIZE (DMDOFFSET + DMLFSIZE + DMUFSIZE)
     42 
     43 struct dmalloc_preamble {
     44 	struct dmalloc_preamble *prev, *next;
     45 	const char *file;
     46 	int line;
     47 	size_t size;
     48 	unsigned long generation;
     49 	unsigned char low_fence [DMLFSIZE];
     50 };
     51 #else
     52 #define DMDOFFSET 0
     53 #define DMDSIZE 0
     54 #endif
     55 
     56 /* rc_history flags... */
     57 #define RC_LEASE	1
     58 #define RC_MISC		2
     59 
     60 #if defined (DEBUG_RC_HISTORY)
     61 #if !defined (RC_HISTORY_MAX)
     62 # define RC_HISTORY_MAX 256
     63 #endif
     64 
     65 #if !defined (RC_HISTORY_FLAGS)
     66 # define RC_HISTORY_FLAGS (RC_LEASE | RC_MISC)
     67 #endif
     68 
     69 struct rc_history_entry {
     70 	const char *file;
     71 	int line;
     72 	void *reference;
     73 	void *addr;
     74 	int refcnt;
     75 };
     76 
     77 #define rc_register(x, l, r, y, z, d, f) do { \
     78 		if (RC_HISTORY_FLAGS & ~(f)) { \
     79 			rc_history [rc_history_index].file = (x); \
     80 			rc_history [rc_history_index].line = (l); \
     81 			rc_history [rc_history_index].reference = (r); \
     82 			rc_history [rc_history_index].addr = (y); \
     83 			rc_history [rc_history_index].refcnt = (z); \
     84 			rc_history_next (d); \
     85 		} \
     86 	} while (0)
     87 #define rc_register_mdl(r, y, z, d, f) \
     88 	rc_register (__FILE__, __LINE__, r, y, z, d, f)
     89 #else
     90 #define rc_register(file, line, reference, addr, refcnt, d, f)
     91 #define rc_register_mdl(reference, addr, refcnt, d, f)
     92 #endif
     93 
     94 #if defined (DEBUG_MEMORY_LEAKAGE) || defined (DEBUG_MALLOC_POOL) || \
     95 		defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)
     96 extern struct dmalloc_preamble *dmalloc_list;
     97 extern unsigned long dmalloc_outstanding;
     98 extern unsigned long dmalloc_longterm;
     99 extern unsigned long dmalloc_generation;
    100 extern unsigned long dmalloc_cutoff_generation;
    101 #endif
    102 
    103 #if defined (DEBUG_RC_HISTORY)
    104 extern struct rc_history_entry rc_history [RC_HISTORY_MAX];
    105 extern int rc_history_index;
    106 extern int rc_history_count;
    107 #endif
    108