update libressl to v2.7.4
[unleashed.git] / lib / libcrypto / malloc-wrapper.c
blob12867387bf7f1a86bda7d0da1140207596a42181
1 /* $OpenBSD: malloc-wrapper.c,v 1.6 2017/05/02 03:59:44 deraadt Exp $ */
2 /*
3 * Copyright (c) 2014 Bob Beck
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <string.h>
21 int
22 CRYPTO_set_mem_functions(void *(*m)(size_t), void *(*r)(void *, size_t),
23 void (*f)(void *))
25 return 0;
28 int
29 CRYPTO_set_mem_ex_functions(void *(*m)(size_t, const char *, int),
30 void *(*r)(void *, size_t, const char *, int), void (*f)(void *))
32 return 0;
35 int
36 CRYPTO_set_locked_mem_functions(void *(*m)(size_t), void (*f)(void *))
38 return 0;
41 int
42 CRYPTO_set_locked_mem_ex_functions(void *(*m)(size_t, const char *, int),
43 void (*f)(void *))
45 return 0;
48 int
49 CRYPTO_set_mem_debug_functions(void (*m)(void *, int, const char *, int, int),
50 void (*r)(void *, void *, int, const char *, int, int),
51 void (*f)(void *, int), void (*so)(long), long (*go)(void))
53 return 0;
57 void
58 CRYPTO_get_mem_functions(void *(**m)(size_t), void *(**r)(void *, size_t),
59 void (**f)(void *))
61 if (m != NULL)
62 *m = malloc;
63 if (r != NULL)
64 *r = realloc;
65 if (f != NULL)
66 *f = free;
69 void
70 CRYPTO_get_mem_ex_functions(void *(**m)(size_t, const char *, int),
71 void *(**r)(void *, size_t, const char *, int), void (**f)(void *))
73 if (m != NULL)
74 *m = NULL;
75 if (r != NULL)
76 *r = NULL;
77 if (f != NULL)
78 *f = free;
81 void
82 CRYPTO_get_locked_mem_functions(void *(**m)(size_t), void (**f)(void *))
84 if (m != NULL)
85 *m = malloc;
86 if (f != NULL)
87 *f = free;
90 void
91 CRYPTO_get_locked_mem_ex_functions(void *(**m)(size_t, const char *, int),
92 void (**f)(void *))
94 if (m != NULL)
95 *m = NULL;
96 if (f != NULL)
97 *f = free;
100 void
101 CRYPTO_get_mem_debug_functions(void (**m)(void *, int, const char *, int, int),
102 void (**r)(void *, void *, int, const char *, int, int),
103 void (**f)(void *, int), void (**so)(long), long (**go)(void))
105 if (m != NULL)
106 *m = NULL;
107 if (r != NULL)
108 *r = NULL;
109 if (f != NULL)
110 *f = NULL;
111 if (so != NULL)
112 *so = NULL;
113 if (go != NULL)
114 *go = NULL;
118 void *
119 CRYPTO_malloc_locked(int num, const char *file, int line)
121 if (num <= 0)
122 return NULL;
123 return malloc(num);
126 void
127 CRYPTO_free_locked(void *ptr)
129 free(ptr);
132 void *
133 CRYPTO_malloc(int num, const char *file, int line)
135 if (num <= 0)
136 return NULL;
137 return malloc(num);
140 char *
141 CRYPTO_strdup(const char *str, const char *file, int line)
143 return strdup(str);
146 void *
147 CRYPTO_realloc(void *ptr, int num, const char *file, int line)
149 if (num <= 0)
150 return NULL;
152 return realloc(ptr, num);
155 void *
156 CRYPTO_realloc_clean(void *ptr, int old_len, int num, const char *file,
157 int line)
159 void *ret = NULL;
161 if (num <= 0)
162 return NULL;
163 if (num < old_len)
164 return NULL; /* original does not support shrinking */
165 ret = malloc(num);
166 if (ret && ptr && old_len > 0) {
167 memcpy(ret, ptr, old_len);
168 freezero(ptr, old_len);
170 return ret;
173 void
174 CRYPTO_free(void *ptr)
176 free(ptr);
179 void *
180 CRYPTO_remalloc(void *a, int num, const char *file, int line)
182 free(a);
183 return malloc(num);
186 void
187 CRYPTO_set_mem_debug_options(long bits)
189 return;
192 long
193 CRYPTO_get_mem_debug_options(void)
195 return 0;