summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorjasone <jasone@FreeBSD.org>2006-01-12 09:29:38 +0000
committerjasone <jasone@FreeBSD.org>2006-01-12 09:29:38 +0000
commit958adbcf1809d37ffc55a46ff6ff83e321278156 (patch)
treedc1b6b34ccd9f732a2492983ab62fa818b5dd4bc /lib
parent6abe8a1c871e4dc46d382fe92b11c4608ea93fb8 (diff)
downloadFreeBSD-src-958adbcf1809d37ffc55a46ff6ff83e321278156.zip
FreeBSD-src-958adbcf1809d37ffc55a46ff6ff83e321278156.tar.gz
Use posix_memalign() in valloc() rather than making assumptions about
the alignment of malloc()ed memory. Approved by: markm (mentor)
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/gen/valloc.328
-rw-r--r--lib/libc/gen/valloc.c12
2 files changed, 20 insertions, 20 deletions
diff --git a/lib/libc/gen/valloc.3 b/lib/libc/gen/valloc.3
index fceec47..d9d60c1 100644
--- a/lib/libc/gen/valloc.3
+++ b/lib/libc/gen/valloc.3
@@ -32,7 +32,7 @@
.\" @(#)valloc.3 8.1 (Berkeley) 6/4/93
.\" $FreeBSD$
.\"
-.Dd June 4, 1993
+.Dd September 13, 2005
.Dt VALLOC 3
.Os
.Sh NAME
@@ -48,9 +48,9 @@
.Bf -symbolic
The
.Fn valloc
-function is obsoleted by the current version of
-.Xr malloc 3 ,
-which aligns page-sized and larger allocations.
+function is obsoleted by
+.Xr posix_memalign 3 ,
+which can be used to request page-aligned allocations.
.Ef
.Pp
The
@@ -59,23 +59,23 @@ function
allocates
.Fa size
bytes aligned on a page boundary.
-It is implemented by calling
-.Xr malloc 3
-with a slightly larger request, saving the true beginning of the block
-allocated, and returning a properly aligned pointer.
.Sh RETURN VALUES
The
.Fn valloc
function returns
a pointer to the allocated space if successful; otherwise
-a null pointer is returned
+a null pointer is returned.
+.Sh SEE ALSO
+.Xr posix_memalign 3
.Sh HISTORY
The
.Fn valloc
function appeared in
.Bx 3.0 .
-.Sh BUGS
-A
-.Fn vfree
-function
-has not been implemented.
+.Pp
+The
+.Fn valloc
+function correctly allocated memory that could be deallocated via
+.Fn free
+in
+.Bx 7.0 .
diff --git a/lib/libc/gen/valloc.c b/lib/libc/gen/valloc.c
index 456f31d..9d888d3 100644
--- a/lib/libc/gen/valloc.c
+++ b/lib/libc/gen/valloc.c
@@ -41,12 +41,12 @@ __FBSDID("$FreeBSD$");
#include <unistd.h>
void *
-valloc(i)
- size_t i;
+valloc(size_t i)
{
- long valsiz = getpagesize(), j;
- void *cp = malloc(i + (valsiz-1));
+ void *ret;
- j = ((long)cp + (valsiz-1)) &~ (valsiz-1);
- return ((void *)j);
+ if (posix_memalign(&ret, getpagesize(), i) != 0)
+ ret = NULL;
+
+ return ret;
}
OpenPOWER on IntegriCloud