summaryrefslogtreecommitdiff
path: root/lib/libcrypto/malloc-wrapper.c
blob: cb9a31186dde610fedddc7d73862de54467ce539 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/* $OpenBSD: malloc-wrapper.c,v 1.7 2018/05/13 13:49:04 jsing Exp $ */
/*
 * Copyright (c) 2014 Bob Beck
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int
CRYPTO_set_mem_functions(void *(*m)(size_t), void *(*r)(void *, size_t),
    void (*f)(void *))
{
	return 0;
}

int
CRYPTO_set_mem_ex_functions(void *(*m)(size_t, const char *, int),
    void *(*r)(void *, size_t, const char *, int), void (*f)(void *))
{
	return 0;
}

int
CRYPTO_set_locked_mem_functions(void *(*m)(size_t), void (*f)(void *))
{
	return 0;
}

int
CRYPTO_set_locked_mem_ex_functions(void *(*m)(size_t, const char *, int),
    void (*f)(void *))
{
	return 0;
}

int
CRYPTO_set_mem_debug_functions(void (*m)(void *, int, const char *, int, int),
    void (*r)(void *, void *, int, const char *, int, int),
    void (*f)(void *, int), void (*so)(long), long (*go)(void))
{
	return 0;
}


void
CRYPTO_get_mem_functions(void *(**m)(size_t), void *(**r)(void *, size_t),
    void (**f)(void *))
{
	if (m != NULL)
		*m = malloc;
	if (r != NULL)
		*r = realloc;
	if (f != NULL)
		*f = free;
}

void
CRYPTO_get_mem_ex_functions(void *(**m)(size_t, const char *, int),
    void *(**r)(void *, size_t, const char *, int), void (**f)(void *))
{
	if (m != NULL)
		*m = NULL;
	if (r != NULL)
		*r = NULL;
	if (f != NULL)
		*f = free;
}

void
CRYPTO_get_locked_mem_functions(void *(**m)(size_t), void (**f)(void *))
{
	if (m != NULL)
		*m = malloc;
	if (f != NULL)
		*f = free;
}

void
CRYPTO_get_locked_mem_ex_functions(void *(**m)(size_t, const char *, int),
    void (**f)(void *))
{
	if (m != NULL)
		*m = NULL;
	if (f != NULL)
		*f = free;
}

void
CRYPTO_get_mem_debug_functions(void (**m)(void *, int, const char *, int, int),
    void (**r)(void *, void *, int, const char *, int, int),
    void (**f)(void *, int), void (**so)(long), long (**go)(void))
{
	if (m != NULL)
		*m = NULL;
	if (r != NULL)
		*r = NULL;
	if (f != NULL)
		*f = NULL;
	if (so != NULL)
		*so = NULL;
	if (go != NULL)
		*go = NULL;
}


void *
CRYPTO_malloc_locked(int num, const char *file, int line)
{
	if (num <= 0)
		return NULL;
	return malloc(num);
}

void
CRYPTO_free_locked(void *ptr)
{
	free(ptr);
}

void *
CRYPTO_malloc(int num, const char *file, int line)
{
	if (num <= 0)
		return NULL;
	return malloc(num);
}

char *
CRYPTO_strdup(const char *str, const char *file, int line)
{
	return strdup(str);
}

void *
CRYPTO_realloc(void *ptr, int num, const char *file, int line)
{
	if (num <= 0)
		return NULL;
	return realloc(ptr, num);
}

void *
CRYPTO_realloc_clean(void *ptr, int old_len, int num, const char *file,
    int line)
{
	if (num <= 0)
		return NULL;
	/* Original does not support shrinking. */
	if (num < old_len)
		return NULL;
	return recallocarray(ptr, old_len, num, 1);
}

void
CRYPTO_free(void *ptr)
{
	free(ptr);
}

void *
CRYPTO_remalloc(void *a, int num, const char *file, int line)
{
	free(a);
	return malloc(num);
}

void
CRYPTO_set_mem_debug_options(long bits)
{
	return;
}

long
CRYPTO_get_mem_debug_options(void)
{
	return 0;
}