summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorjasone <jasone@FreeBSD.org>2006-03-28 22:16:04 +0000
committerjasone <jasone@FreeBSD.org>2006-03-28 22:16:04 +0000
commit1a854b0cf791f1081496d7fa2abb3db55adf618d (patch)
tree84a037e2c3045c857b69637dcac7955a8481ae0d /lib
parent91d320d3aa6099a2fd925118aa8bd0b06b763b8f (diff)
downloadFreeBSD-src-1a854b0cf791f1081496d7fa2abb3db55adf618d.zip
FreeBSD-src-1a854b0cf791f1081496d7fa2abb3db55adf618d.tar.gz
Add malloc_usable_size(3).
Discussed with: arch@
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/stdlib/Makefile.inc2
-rw-r--r--lib/libc/stdlib/Symbol.map1
-rw-r--r--lib/libc/stdlib/malloc.327
-rw-r--r--lib/libc/stdlib/malloc.c20
4 files changed, 47 insertions, 3 deletions
diff --git a/lib/libc/stdlib/Makefile.inc b/lib/libc/stdlib/Makefile.inc
index 27eee7d..99ea7fb 100644
--- a/lib/libc/stdlib/Makefile.inc
+++ b/lib/libc/stdlib/Makefile.inc
@@ -46,5 +46,5 @@ MLINKS+=strtod.3 strtof.3 strtod.3 strtold.3
MLINKS+=strtol.3 strtoll.3 strtol.3 strtoq.3 strtol.3 strtoimax.3
MLINKS+=strtoul.3 strtoull.3 strtoul.3 strtouq.3 strtoul.3 strtoumax.3
MLINKS+=malloc.3 calloc.3 malloc.3 free.3 malloc.3 malloc.conf.5 \
- malloc.3 realloc.3 malloc.3 reallocf.3
+ malloc.3 realloc.3 malloc.3 reallocf.3 malloc.3 malloc_usable_size.3
MLINKS+=tsearch.3 tdelete.3 tsearch.3 tfind.3 tsearch.3 twalk.3
diff --git a/lib/libc/stdlib/Symbol.map b/lib/libc/stdlib/Symbol.map
index 2459fe2..ff11d7a 100644
--- a/lib/libc/stdlib/Symbol.map
+++ b/lib/libc/stdlib/Symbol.map
@@ -53,6 +53,7 @@ FBSD_1.0 {
calloc;
realloc;
free;
+ malloc_usable_size;
mergesort;
putenv;
qsort_r;
diff --git a/lib/libc/stdlib/malloc.3 b/lib/libc/stdlib/malloc.3
index 9a888c5..46ce26c 100644
--- a/lib/libc/stdlib/malloc.3
+++ b/lib/libc/stdlib/malloc.3
@@ -32,11 +32,11 @@
.\" @(#)malloc.3 8.1 (Berkeley) 6/4/93
.\" $FreeBSD$
.\"
-.Dd March 9, 2006
+.Dd March 28, 2006
.Dt MALLOC 3
.Os
.Sh NAME
-.Nm malloc , calloc , realloc , free , reallocf
+.Nm malloc , calloc , realloc , free , reallocf , malloc_usable_size
.Nd general purpose memory allocation functions
.Sh LIBRARY
.Lb libc
@@ -58,6 +58,9 @@
.Fo \*(lp*_malloc_message\*(rp
.Fa "const char *p1" "const char *p2" "const char *p3" "const char *p4"
.Fc
+.In malloc_np.h
+.Ft size_t
+.Fn malloc_usable_size "const void *ptr"
.Sh DESCRIPTION
The
.Fn malloc
@@ -133,6 +136,21 @@ If
is
.Dv NULL ,
no action occurs.
+.Pp
+The
+.Fn malloc_usable_size
+function returns the usable size of the allocation pointed to by
+.Fa ptr .
+The return value may be larger than the size that was requested during
+allocation.
+.Fn malloc_usable_size
+is not a mechanism for in-place
+.Fn realloc ;
+rather it is provided soley as a tool for introspection purposes.
+Any discrepancy between the requested allocation size and the size reported by
+.Fn malloc_usable_size
+should not be depended on, since such behavior is entirely
+implementation-dependent.
.Sh TUNING
Once, when the first call is made to one of these memory allocation
routines, various flags will be set or reset, which affect the
@@ -443,3 +461,8 @@ The
.Fn reallocf
function first appeared in
.Fx 3.0 .
+.Pp
+The
+.Fn malloc_usable_size
+function first appeared in
+.Fx 7.0 .
diff --git a/lib/libc/stdlib/malloc.c b/lib/libc/stdlib/malloc.c
index 91357a0..359c98a 100644
--- a/lib/libc/stdlib/malloc.c
+++ b/lib/libc/stdlib/malloc.c
@@ -3489,6 +3489,26 @@ free(void *ptr)
*/
/******************************************************************************/
/*
+ * Begin non-standard functions.
+ */
+
+size_t
+malloc_usable_size(const void *ptr)
+{
+
+ assert(ptr != NULL);
+
+ if (ptr == &nil)
+ return (0);
+ else
+ return (isalloc(ptr));
+}
+
+/*
+ * End non-standard functions.
+ */
+/******************************************************************************/
+/*
* Begin library-private functions, used by threading libraries for protection
* of malloc during fork(). These functions are only called if the program is
* running in threaded mode, so there is no need to check whether the program
OpenPOWER on IntegriCloud