and added files
[bcm963xx.git] / userapps / opensource / ipsec-tools / src / racoon / gcmalloc.h
1 /*      $KAME: gcmalloc.h,v 1.4 2001/11/16 04:34:57 sakane Exp $        */
2
3 /*
4  * Copyright (C) 2000, 2001 WIDE Project.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. Neither the name of the project nor the names of its contributors
16  *    may be used to endorse or promote products derived from this software
17  *    without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29  * SUCH DAMAGE.
30  */
31
32 /*
33  * Debugging malloc glue for Racoon.
34  */
35
36 #ifndef _GCMALLOC_H_DEFINED
37 #define _GCMALLOC_H_DEFINED
38
39 /* ElectricFence needs no special handling. */
40
41 /*
42  * Boehm-GC provides GC_malloc(), GC_realloc(), GC_free() functions,
43  * but not the traditional entry points.  So what we do is provide  
44  * malloc(), calloc(), realloc(), and free() entry points in the main
45  * program and letting the linker do the rest.
46  */
47 #ifdef GC
48 #define GC_DEBUG
49 #include <gc.h>
50
51 #ifdef RACOON_MAIN_PROGRAM
52 void *
53 malloc(size_t size)
54 {
55
56         return (GC_MALLOC(size));
57 }
58
59 void *
60 calloc(size_t number, size_t size)
61 {
62
63         /* GC_malloc() clears the storage. */
64         return (GC_MALLOC(number * size));
65 }
66
67 void *
68 realloc(void *ptr, size_t size)
69 {
70
71         return (GC_REALLOC(ptr, size));
72 }
73
74 void
75 free(void *ptr)
76 {
77
78         GC_FREE(ptr);
79 }
80 #endif /* RACOON_MAIN_PROGRAM */
81
82 #define racoon_malloc(sz)       GC_debug_malloc(sz, GC_EXTRAS)
83 #define racoon_calloc(cnt, sz)  GC_debug_malloc(cnt * sz, GC_EXTRAS)
84 #define racoon_realloc(old, sz) GC_debug_realloc(old, sz, GC_EXTRAS)
85 #define racoon_free(p)          GC_debug_free(p)
86
87 #endif /* GC */
88
89 /*
90  * Dmalloc only requires that you pull in a header file and link
91  * against libdmalloc.
92  */
93 #ifdef DMALLOC
94 #include <dmalloc.h>
95 #endif /* DMALLOC */
96
97 #ifdef DEBUG_RECORD_MALLOCATION
98 #include <debugrm.h>
99 #else
100 #ifndef racoon_malloc
101 #define racoon_malloc(sz)       malloc((sz))
102 #endif
103 #ifndef racoon_calloc
104 #define racoon_calloc(cnt, sz)  calloc((cnt), (sz))
105 #endif
106 #ifndef racoon_realloc
107 #define racoon_realloc(old, sz) realloc((old), (sz))
108 #endif
109 #ifndef racoon_free
110 #define racoon_free(p)          free((p))
111 #endif
112 #endif /* DEBUG_RECORD_MALLOCATION */
113
114 #endif /* _GCMALLOC_H_DEFINED */