]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - secure/lib/libcrypto/man/OPENSSL_malloc.3
Regen manual pages.
[FreeBSD/FreeBSD.git] / secure / lib / libcrypto / man / OPENSSL_malloc.3
1 .\" Automatically generated by Pod::Man 4.09 (Pod::Simple 3.35)
2 .\"
3 .\" Standard preamble:
4 .\" ========================================================================
5 .de Sp \" Vertical space (when we can't use .PP)
6 .if t .sp .5v
7 .if n .sp
8 ..
9 .de Vb \" Begin verbatim text
10 .ft CW
11 .nf
12 .ne \\$1
13 ..
14 .de Ve \" End verbatim text
15 .ft R
16 .fi
17 ..
18 .\" Set up some character translations and predefined strings.  \*(-- will
19 .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
20 .\" double quote, and \*(R" will give a right double quote.  \*(C+ will
21 .\" give a nicer C++.  Capital omega is used to do unbreakable dashes and
22 .\" therefore won't be available.  \*(C` and \*(C' expand to `' in nroff,
23 .\" nothing in troff, for use with C<>.
24 .tr \(*W-
25 .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
26 .ie n \{\
27 .    ds -- \(*W-
28 .    ds PI pi
29 .    if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
30 .    if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\"  diablo 12 pitch
31 .    ds L" ""
32 .    ds R" ""
33 .    ds C` ""
34 .    ds C' ""
35 'br\}
36 .el\{\
37 .    ds -- \|\(em\|
38 .    ds PI \(*p
39 .    ds L" ``
40 .    ds R" ''
41 .    ds C`
42 .    ds C'
43 'br\}
44 .\"
45 .\" Escape single quotes in literal strings from groff's Unicode transform.
46 .ie \n(.g .ds Aq \(aq
47 .el       .ds Aq '
48 .\"
49 .\" If the F register is >0, we'll generate index entries on stderr for
50 .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
51 .\" entries marked with X<> in POD.  Of course, you'll have to process the
52 .\" output yourself in some meaningful fashion.
53 .\"
54 .\" Avoid warning from groff about undefined register 'F'.
55 .de IX
56 ..
57 .if !\nF .nr F 0
58 .if \nF>0 \{\
59 .    de IX
60 .    tm Index:\\$1\t\\n%\t"\\$2"
61 ..
62 .    if !\nF==2 \{\
63 .        nr % 0
64 .        nr F 2
65 .    \}
66 .\}
67 .\"
68 .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
69 .\" Fear.  Run.  Save yourself.  No user-serviceable parts.
70 .    \" fudge factors for nroff and troff
71 .if n \{\
72 .    ds #H 0
73 .    ds #V .8m
74 .    ds #F .3m
75 .    ds #[ \f1
76 .    ds #] \fP
77 .\}
78 .if t \{\
79 .    ds #H ((1u-(\\\\n(.fu%2u))*.13m)
80 .    ds #V .6m
81 .    ds #F 0
82 .    ds #[ \&
83 .    ds #] \&
84 .\}
85 .    \" simple accents for nroff and troff
86 .if n \{\
87 .    ds ' \&
88 .    ds ` \&
89 .    ds ^ \&
90 .    ds , \&
91 .    ds ~ ~
92 .    ds /
93 .\}
94 .if t \{\
95 .    ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
96 .    ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
97 .    ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
98 .    ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
99 .    ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
100 .    ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
101 .\}
102 .    \" troff and (daisy-wheel) nroff accents
103 .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
104 .ds 8 \h'\*(#H'\(*b\h'-\*(#H'
105 .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
106 .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
107 .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
108 .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
109 .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
110 .ds ae a\h'-(\w'a'u*4/10)'e
111 .ds Ae A\h'-(\w'A'u*4/10)'E
112 .    \" corrections for vroff
113 .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
114 .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
115 .    \" for low resolution devices (crt and lpr)
116 .if \n(.H>23 .if \n(.V>19 \
117 \{\
118 .    ds : e
119 .    ds 8 ss
120 .    ds o a
121 .    ds d- d\h'-1'\(ga
122 .    ds D- D\h'-1'\(hy
123 .    ds th \o'bp'
124 .    ds Th \o'LP'
125 .    ds ae ae
126 .    ds Ae AE
127 .\}
128 .rm #[ #] #H #V #F C
129 .\" ========================================================================
130 .\"
131 .IX Title "OPENSSL_MALLOC 3"
132 .TH OPENSSL_MALLOC 3 "2018-09-11" "1.1.1" "OpenSSL"
133 .\" For nroff, turn off justification.  Always turn off hyphenation; it makes
134 .\" way too many mistakes in technical documents.
135 .if n .ad l
136 .nh
137 .SH "NAME"
138 OPENSSL_malloc_init, OPENSSL_malloc, OPENSSL_zalloc, OPENSSL_realloc, OPENSSL_free, OPENSSL_clear_realloc, OPENSSL_clear_free, OPENSSL_cleanse, CRYPTO_malloc, CRYPTO_zalloc, CRYPTO_realloc, CRYPTO_free, OPENSSL_strdup, OPENSSL_strndup, OPENSSL_memdup, OPENSSL_strlcpy, OPENSSL_strlcat, OPENSSL_hexstr2buf, OPENSSL_buf2hexstr, OPENSSL_hexchar2int, CRYPTO_strdup, CRYPTO_strndup, OPENSSL_mem_debug_push, OPENSSL_mem_debug_pop, CRYPTO_mem_debug_push, CRYPTO_mem_debug_pop, CRYPTO_clear_realloc, CRYPTO_clear_free, CRYPTO_get_mem_functions, CRYPTO_set_mem_functions, CRYPTO_get_alloc_counts, CRYPTO_set_mem_debug, CRYPTO_mem_ctrl, CRYPTO_mem_leaks, CRYPTO_mem_leaks_fp, CRYPTO_mem_leaks_cb, OPENSSL_MALLOC_FAILURES, OPENSSL_MALLOC_FD \&\- Memory allocation functions
139 .SH "SYNOPSIS"
140 .IX Header "SYNOPSIS"
141 .Vb 1
142 \& #include <openssl/crypto.h>
143 \&
144 \& int OPENSSL_malloc_init(void)
145 \&
146 \& void *OPENSSL_malloc(size_t num)
147 \& void *OPENSSL_zalloc(size_t num)
148 \& void *OPENSSL_realloc(void *addr, size_t num)
149 \& void OPENSSL_free(void *addr)
150 \& char *OPENSSL_strdup(const char *str)
151 \& char *OPENSSL_strndup(const char *str, size_t s)
152 \& size_t OPENSSL_strlcat(char *dst, const char *src, size_t size);
153 \& size_t OPENSSL_strlcpy(char *dst, const char *src, size_t size);
154 \& void *OPENSSL_memdup(void *data, size_t s)
155 \& void *OPENSSL_clear_realloc(void *p, size_t old_len, size_t num)
156 \& void OPENSSL_clear_free(void *str, size_t num)
157 \& void OPENSSL_cleanse(void *ptr, size_t len);
158 \&
159 \& unsigned char *OPENSSL_hexstr2buf(const char *str, long *len);
160 \& char *OPENSSL_buf2hexstr(const unsigned char *buffer, long len);
161 \& int OPENSSL_hexchar2int(unsigned char c);
162 \&
163 \& void *CRYPTO_malloc(size_t num, const char *file, int line)
164 \& void *CRYPTO_zalloc(size_t num, const char *file, int line)
165 \& void *CRYPTO_realloc(void *p, size_t num, const char *file, int line)
166 \& void CRYPTO_free(void *str, const char *, int)
167 \& char *CRYPTO_strdup(const char *p, const char *file, int line)
168 \& char *CRYPTO_strndup(const char *p, size_t num, const char *file, int line)
169 \& void *CRYPTO_clear_realloc(void *p, size_t old_len, size_t num,
170 \&                            const char *file, int line)
171 \& void CRYPTO_clear_free(void *str, size_t num, const char *, int)
172 \&
173 \& void CRYPTO_get_mem_functions(
174 \&         void *(**m)(size_t, const char *, int),
175 \&         void *(**r)(void *, size_t, const char *, int),
176 \&         void (**f)(void *, const char *, int))
177 \& int CRYPTO_set_mem_functions(
178 \&         void *(*m)(size_t, const char *, int),
179 \&         void *(*r)(void *, size_t, const char *, int),
180 \&         void (*f)(void *, const char *, int))
181 \&
182 \& void CRYPTO_get_alloc_counts(int *m, int *r, int *f)
183 \&
184 \& int CRYPTO_set_mem_debug(int onoff)
185 \&
186 \& env OPENSSL_MALLOC_FAILURES=... <application>
187 \& env OPENSSL_MALLOC_FD=... <application>
188 \&
189 \& int CRYPTO_mem_ctrl(int mode);
190 \&
191 \& int OPENSSL_mem_debug_push(const char *info)
192 \& int OPENSSL_mem_debug_pop(void);
193 \&
194 \& int CRYPTO_mem_debug_push(const char *info, const char *file, int line);
195 \& int CRYPTO_mem_debug_pop(void);
196 \&
197 \& int CRYPTO_mem_leaks(BIO *b);
198 \& int CRYPTO_mem_leaks_fp(FILE *fp);
199 \& int CRYPTO_mem_leaks_cb(int (*cb)(const char *str, size_t len, void *u),
200 \&                         void *u);
201 .Ve
202 .SH "DESCRIPTION"
203 .IX Header "DESCRIPTION"
204 OpenSSL memory allocation is handled by the \fBOPENSSL_xxx\fR \s-1API.\s0 These are
205 generally macro's that add the standard C \fB_\|_FILE_\|_\fR and \fB_\|_LINE_\|_\fR
206 parameters and call a lower-level \fBCRYPTO_xxx\fR \s-1API.\s0
207 Some functions do not add those parameters, but exist for consistency.
208 .PP
209 \&\fIOPENSSL_malloc_init()\fR sets the lower-level memory allocation functions
210 to their default implementation.
211 It is generally not necessary to call this, except perhaps in certain
212 shared-library situations.
213 .PP
214 \&\fIOPENSSL_malloc()\fR, \fIOPENSSL_realloc()\fR, and \fIOPENSSL_free()\fR are like the
215 C \fImalloc()\fR, \fIrealloc()\fR, and \fIfree()\fR functions.
216 \&\fIOPENSSL_zalloc()\fR calls \fImemset()\fR to zero the memory before returning.
217 .PP
218 \&\fIOPENSSL_clear_realloc()\fR and \fIOPENSSL_clear_free()\fR should be used
219 when the buffer at \fBaddr\fR holds sensitive information.
220 The old buffer is filled with zero's by calling \fIOPENSSL_cleanse()\fR
221 before ultimately calling \fIOPENSSL_free()\fR.
222 .PP
223 \&\fIOPENSSL_cleanse()\fR fills \fBptr\fR of size \fBlen\fR with a string of 0's.
224 Use \fIOPENSSL_cleanse()\fR with care if the memory is a mapping of a file.
225 If the storage controller uses write compression, then its possible
226 that sensitive tail bytes will survive zeroization because the block of
227 zeros will be compressed. If the storage controller uses wear leveling,
228 then the old sensitive data will not be overwritten; rather, a block of
229 0's will be written at a new physical location.
230 .PP
231 \&\fIOPENSSL_strdup()\fR, \fIOPENSSL_strndup()\fR and \fIOPENSSL_memdup()\fR are like the
232 equivalent C functions, except that memory is allocated by calling the
233 \&\fIOPENSSL_malloc()\fR and should be released by calling \fIOPENSSL_free()\fR.
234 .PP
235 \&\fIOPENSSL_strlcpy()\fR,
236 \&\fIOPENSSL_strlcat()\fR and \fIOPENSSL_strnlen()\fR are equivalents of the common C
237 library functions and are provided for portability.
238 .PP
239 \&\fIOPENSSL_hexstr2buf()\fR parses \fBstr\fR as a hex string and returns a
240 pointer to the parsed value. The memory is allocated by calling
241 \&\fIOPENSSL_malloc()\fR and should be released by calling \fIOPENSSL_free()\fR.
242 If \fBlen\fR is not \s-1NULL,\s0 it is filled in with the output length.
243 Colons between two-character hex \*(L"bytes\*(R" are ignored.
244 An odd number of hex digits is an error.
245 .PP
246 \&\fIOPENSSL_buf2hexstr()\fR takes the specified buffer and length, and returns
247 a hex string for value, or \s-1NULL\s0 on error.
248 \&\fBBuffer\fR cannot be \s-1NULL\s0; if \fBlen\fR is 0 an empty string is returned.
249 .PP
250 \&\fIOPENSSL_hexchar2int()\fR converts a character to the hexadecimal equivalent,
251 or returns \-1 on error.
252 .PP
253 If no allocations have been done, it is possible to \*(L"swap out\*(R" the default
254 implementations for \fIOPENSSL_malloc()\fR, OPENSSL_realloc and \fIOPENSSL_free()\fR
255 and replace them with alternate versions (hooks).
256 \&\fICRYPTO_get_mem_functions()\fR function fills in the given arguments with the
257 function pointers for the current implementations.
258 With \fICRYPTO_set_mem_functions()\fR, you can specify a different set of functions.
259 If any of \fBm\fR, \fBr\fR, or \fBf\fR are \s-1NULL,\s0 then the function is not changed.
260 .PP
261 The default implementation can include some debugging capability (if enabled
262 at build-time).
263 This adds some overhead by keeping a list of all memory allocations, and
264 removes items from the list when they are free'd.
265 This is most useful for identifying memory leaks.
266 \&\fICRYPTO_set_mem_debug()\fR turns this tracking on and off.  In order to have
267 any effect, is must be called before any of the allocation functions
268 (e.g., \fICRYPTO_malloc()\fR) are called, and is therefore normally one of the
269 first lines of \fImain()\fR in an application.
270 \&\fICRYPTO_mem_ctrl()\fR provides fine-grained control of memory leak tracking.
271 To enable tracking call \fICRYPTO_mem_ctrl()\fR with a \fBmode\fR argument of
272 the \fB\s-1CRYPTO_MEM_CHECK_ON\s0\fR.
273 To disable tracking call \fICRYPTO_mem_ctrl()\fR with a \fBmode\fR argument of
274 the \fB\s-1CRYPTO_MEM_CHECK_OFF\s0\fR.
275 .PP
276 While checking memory, it can be useful to store additional context
277 about what is being done.
278 For example, identifying the field names when parsing a complicated
279 data structure.
280 \&\fIOPENSSL_mem_debug_push()\fR (which calls \fICRYPTO_mem_debug_push()\fR)
281 attachs an identifying string to the allocation stack.
282 This must be a global or other static string; it is not copied.
283 \&\fIOPENSSL_mem_debug_pop()\fR removes identifying state from the stack.
284 .PP
285 At the end of the program, calling \fICRYPTO_mem_leaks()\fR or
286 \&\fICRYPTO_mem_leaks_fp()\fR will report all \*(L"leaked\*(R" memory, writing it
287 to the specified \s-1BIO\s0 \fBb\fR or \s-1FILE\s0 \fBfp\fR. These functions return 1 if
288 there are no leaks, 0 if there are leaks and \-1 if an error occurred.
289 .PP
290 \&\fICRYPTO_mem_leaks_cb()\fR does the same as \fICRYPTO_mem_leaks()\fR, but instead
291 of writing to a given \s-1BIO,\s0 the callback function is called for each
292 output string with the string, length, and userdata \fBu\fR as the callback
293 parameters.
294 .PP
295 If the library is built with the \f(CW\*(C`crypto\-mdebug\*(C'\fR option, then one
296 function, \fICRYPTO_get_alloc_counts()\fR, and two additional environment
297 variables, \fB\s-1OPENSSL_MALLOC_FAILURES\s0\fR and \fB\s-1OPENSSL_MALLOC_FD\s0\fR,
298 are available.
299 .PP
300 The function \fICRYPTO_get_alloc_counts()\fR fills in the number of times
301 each of \fICRYPTO_malloc()\fR, \fICRYPTO_realloc()\fR, and \fICRYPTO_free()\fR have been
302 called, into the values pointed to by \fBmcount\fR, \fBrcount\fR, and \fBfcount\fR,
303 respectively.  If a pointer is \s-1NULL,\s0 then the corresponding count is not stored.
304 .PP
305 The variable
306 \&\fB\s-1OPENSSL_MALLOC_FAILURES\s0\fR controls how often allocations should fail.
307 It is a set of fields separated by semicolons, which each field is a count
308 (defaulting to zero) and an optional atsign and percentage (defaulting
309 to 100).  If the count is zero, then it lasts forever.  For example,
310 \&\f(CW\*(C`100;@25\*(C'\fR or \f(CW\*(C`100@0;0@25\*(C'\fR means the first 100 allocations pass, then all
311 other allocations (until the program exits or crashes) have a 25% chance of
312 failing.
313 .PP
314 If the variable \fB\s-1OPENSSL_MALLOC_FD\s0\fR is parsed as a positive integer, then
315 it is taken as an open file descriptor, and a record of all allocations is
316 written to that descriptor.  If an allocation will fail, and the platform
317 supports it, then a backtrace will be written to the descriptor.  This can
318 be useful because a malloc may fail but not be checked, and problems will
319 only occur later.  The following example in classic shell syntax shows how
320 to use this (will not work on all platforms):
321 .PP
322 .Vb 5
323 \&  OPENSSL_MALLOC_FAILURES=\*(Aq200;@10\*(Aq
324 \&  export OPENSSL_MALLOC_FAILURES
325 \&  OPENSSL_MALLOC_FD=3
326 \&  export OPENSSL_MALLOC_FD
327 \&  ...app invocation... 3>/tmp/log$$
328 .Ve
329 .SH "RETURN VALUES"
330 .IX Header "RETURN VALUES"
331 \&\fIOPENSSL_malloc_init()\fR, \fIOPENSSL_free()\fR, \fIOPENSSL_clear_free()\fR
332 \&\fICRYPTO_free()\fR, \fICRYPTO_clear_free()\fR and \fICRYPTO_get_mem_functions()\fR
333 return no value.
334 .PP
335 \&\fICRYPTO_mem_leaks()\fR, \fICRYPTO_mem_leaks_fp()\fR and \fICRYPTO_mem_leaks_cb()\fR return 1 if
336 there are no leaks, 0 if there are leaks and \-1 if an error occurred.
337 .PP
338 \&\fIOPENSSL_malloc()\fR, \fIOPENSSL_zalloc()\fR, \fIOPENSSL_realloc()\fR,
339 \&\fIOPENSSL_clear_realloc()\fR,
340 \&\fICRYPTO_malloc()\fR, \fICRYPTO_zalloc()\fR, \fICRYPTO_realloc()\fR,
341 \&\fICRYPTO_clear_realloc()\fR,
342 \&\fIOPENSSL_buf2hexstr()\fR, \fIOPENSSL_hexstr2buf()\fR,
343 \&\fIOPENSSL_strdup()\fR, and \fIOPENSSL_strndup()\fR
344 return a pointer to allocated memory or \s-1NULL\s0 on error.
345 .PP
346 \&\fICRYPTO_set_mem_functions()\fR and \fICRYPTO_set_mem_debug()\fR
347 return 1 on success or 0 on failure (almost
348 always because allocations have already happened).
349 .PP
350 \&\fICRYPTO_mem_ctrl()\fR returns \-1 if an error occurred, otherwise the
351 previous value of the mode.
352 .PP
353 \&\fIOPENSSL_mem_debug_push()\fR and \fIOPENSSL_mem_debug_pop()\fR
354 return 1 on success or 0 on failure.
355 .SH "NOTES"
356 .IX Header "NOTES"
357 While it's permitted to swap out only a few and not all the functions
358 with \fICRYPTO_set_mem_functions()\fR, it's recommended to swap them all out
359 at once.  \fIThis applies specially if OpenSSL was built with the
360 configuration option\fR \f(CW\*(C`crypto\-mdebug\*(C'\fR \fIenabled.  In case, swapping out
361 only, say, the \fImalloc()\fI implementation is outright dangerous.\fR
362 .SH "COPYRIGHT"
363 .IX Header "COPYRIGHT"
364 Copyright 2016\-2018 The OpenSSL Project Authors. All Rights Reserved.
365 .PP
366 Licensed under the OpenSSL license (the \*(L"License\*(R").  You may not use
367 this file except in compliance with the License.  You can obtain a copy
368 in the file \s-1LICENSE\s0 in the source distribution or at
369 <https://www.openssl.org/source/license.html>.