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