1 /*	$NetBSD: alloc.h,v 1.1.1.3 2014/07/12 11:57:57 spz Exp $	*/
2 /* alloc.h
3 
4    Definitions for the object management API protocol memory allocation... */
5 
6 /*
7  * Copyright (c) 2004,2009,2014 by Internet Systems Consortium, Inc. ("ISC")
8  * Copyright (c) 1996-2003 by Internet Software Consortium
9  *
10  * Permission to use, copy, modify, and distribute this software for any
11  * purpose with or without fee is hereby granted, provided that the above
12  * copyright notice and this permission notice appear in all copies.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
15  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
16  * MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR
17  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
18  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
19  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
20  * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21  *
22  *   Internet Systems Consortium, Inc.
23  *   950 Charter Street
24  *   Redwood City, CA 94063
25  *   <info@isc.org>
26  *   https://www.isc.org/
27  *
28  */
29 
30 isc_result_t omapi_buffer_new (omapi_buffer_t **, const char *, int);
31 isc_result_t omapi_buffer_reference (omapi_buffer_t **,
32 				     omapi_buffer_t *, const char *, int);
33 isc_result_t omapi_buffer_dereference (omapi_buffer_t **, const char *, int);
34 
35 #if defined (DEBUG_MEMORY_LEAKAGE) || defined (DEBUG_MALLOC_POOL) || \
36 		defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)
37 #define DMDOFFSET (sizeof (struct dmalloc_preamble))
38 #define DMLFSIZE 16
39 #define DMUFSIZE 16
40 #define DMDSIZE (DMDOFFSET + DMLFSIZE + DMUFSIZE)
41 
42 struct dmalloc_preamble {
43 	struct dmalloc_preamble *prev, *next;
44 	const char *file;
45 	int line;
46 	size_t size;
47 	unsigned long generation;
48 	unsigned char low_fence [DMLFSIZE];
49 };
50 #else
51 #define DMDOFFSET 0
52 #define DMDSIZE 0
53 #endif
54 
55 /* rc_history flags... */
56 #define RC_LEASE	1
57 #define RC_MISC		2
58 
59 #if defined (DEBUG_RC_HISTORY)
60 #if !defined (RC_HISTORY_MAX)
61 # define RC_HISTORY_MAX 256
62 #endif
63 
64 #if !defined (RC_HISTORY_FLAGS)
65 # define RC_HISTORY_FLAGS (RC_LEASE | RC_MISC)
66 #endif
67 
68 struct rc_history_entry {
69 	const char *file;
70 	int line;
71 	void *reference;
72 	void *addr;
73 	int refcnt;
74 };
75 
76 #define rc_register(x, l, r, y, z, d, f) do { \
77 		if (RC_HISTORY_FLAGS & ~(f)) { \
78 			rc_history [rc_history_index].file = (x); \
79 			rc_history [rc_history_index].line = (l); \
80 			rc_history [rc_history_index].reference = (r); \
81 			rc_history [rc_history_index].addr = (y); \
82 			rc_history [rc_history_index].refcnt = (z); \
83 			rc_history_next (d); \
84 		} \
85 	} while (0)
86 #define rc_register_mdl(r, y, z, d, f) \
87 	rc_register (__FILE__, __LINE__, r, y, z, d, f)
88 #else
89 #define rc_register(file, line, reference, addr, refcnt, d, f)
90 #define rc_register_mdl(reference, addr, refcnt, d, f)
91 #endif
92 
93 #if defined (DEBUG_MEMORY_LEAKAGE) || defined (DEBUG_MALLOC_POOL) || \
94 		defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)
95 extern struct dmalloc_preamble *dmalloc_list;
96 extern unsigned long dmalloc_outstanding;
97 extern unsigned long dmalloc_longterm;
98 extern unsigned long dmalloc_generation;
99 extern unsigned long dmalloc_cutoff_generation;
100 #endif
101 
102 #if defined (DEBUG_RC_HISTORY)
103 extern struct rc_history_entry rc_history [RC_HISTORY_MAX];
104 extern int rc_history_index;
105 extern int rc_history_count;
106 #endif
107