summaryrefslogtreecommitdiff
path: root/src/lib/libc/stdlib/malloc.3
diff options
context:
space:
mode:
authorotto <>2018-11-18 16:15:18 +0000
committerotto <>2018-11-18 16:15:18 +0000
commite03dc031fa67e7d982aeacfea51fb4615d4783b6 (patch)
tree8f4e932865189bdd3f6d7c230def20c4842f4c69 /src/lib/libc/stdlib/malloc.3
parent041aeb91a95a5be54d73153ff1a3efac4df4bc99 (diff)
downloadopenbsd-e03dc031fa67e7d982aeacfea51fb4615d4783b6.tar.gz
openbsd-e03dc031fa67e7d982aeacfea51fb4615d4783b6.tar.bz2
openbsd-e03dc031fa67e7d982aeacfea51fb4615d4783b6.zip
Implement malloc_usable_size(); ok millert@ deraadt@ and jmc@ for the man page
Diffstat (limited to 'src/lib/libc/stdlib/malloc.3')
-rw-r--r--src/lib/libc/stdlib/malloc.334
1 files changed, 29 insertions, 5 deletions
diff --git a/src/lib/libc/stdlib/malloc.3 b/src/lib/libc/stdlib/malloc.3
index 35222a15ce..c1776f61cb 100644
--- a/src/lib/libc/stdlib/malloc.3
+++ b/src/lib/libc/stdlib/malloc.3
@@ -30,9 +30,9 @@
30.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31.\" SUCH DAMAGE. 31.\" SUCH DAMAGE.
32.\" 32.\"
33.\" $OpenBSD: malloc.3,v 1.118 2018/11/08 05:58:21 otto Exp $ 33.\" $OpenBSD: malloc.3,v 1.119 2018/11/18 16:15:18 otto Exp $
34.\" 34.\"
35.Dd $Mdocdate: November 8 2018 $ 35.Dd $Mdocdate: November 18 2018 $
36.Dt MALLOC 3 36.Dt MALLOC 3
37.Os 37.Os
38.Sh NAME 38.Sh NAME
@@ -43,7 +43,8 @@
43.Nm reallocarray , 43.Nm reallocarray ,
44.Nm recallocarray , 44.Nm recallocarray ,
45.Nm freezero , 45.Nm freezero ,
46.Nm aligned_alloc 46.Nm aligned_alloc ,
47.Nm malloc_usable_size
47.Nd memory allocation and deallocation 48.Nd memory allocation and deallocation
48.Sh SYNOPSIS 49.Sh SYNOPSIS
49.In stdlib.h 50.In stdlib.h
@@ -63,6 +64,8 @@
63.Fn freezero "void *ptr" "size_t size" 64.Fn freezero "void *ptr" "size_t size"
64.Ft void * 65.Ft void *
65.Fn aligned_alloc "size_t alignment" "size_t size" 66.Fn aligned_alloc "size_t alignment" "size_t size"
67.Ft size_t
68.Fn malloc_usable_size "void *ptr"
66.Vt char *malloc_options ; 69.Vt char *malloc_options ;
67.Sh DESCRIPTION 70.Sh DESCRIPTION
68The standard functions 71The standard functions
@@ -191,7 +194,7 @@ must be a value such that
191.Fa size 194.Fa size
192is the size of the earlier allocation that returned 195is the size of the earlier allocation that returned
193.Fa ptr , 196.Fa ptr ,
194otherwise the behaviour is undefined. 197otherwise the behavior is undefined.
195.Pp 198.Pp
196The 199The
197.Fn freezero 200.Fn freezero
@@ -233,6 +236,25 @@ If
233is not a multiple of 236is not a multiple of
234.Fa alignment , 237.Fa alignment ,
235behavior is undefined. 238behavior is undefined.
239.Pp
240The
241.Fn malloc_usable_size
242function returns the actual size of the allocated memory pointed to by
243.Va ptr .
244If
245.Va ptr
246is
247.Dv NULL ,
248it returns 0.
249If
250.Va ptr
251was never returned by an allocation function or freed before,
252the behavior is undefined.
253This function should not be relied upon since it exposes some of the internal
254workings of the
255.Fn malloc
256family of functions.
257Writing beyond the requested size introduces undefined behavior.
236.Sh RETURN VALUES 258.Sh RETURN VALUES
237Upon successful completion, the allocation functions 259Upon successful completion, the allocation functions
238return a pointer to the allocated space; otherwise, 260return a pointer to the allocated space; otherwise,
@@ -618,7 +640,9 @@ function appeared in
618.Ox 6.2 . 640.Ox 6.2 .
619The 641The
620.Fn aligned_alloc 642.Fn aligned_alloc
621function appeared in 643and
644.Fn malloc_usable_size
645functions appeared in
622.Ox 6.5 . 646.Ox 6.5 .
623.Sh CAVEATS 647.Sh CAVEATS
624When using 648When using