1
dnl @synopsis AX_CHECK_PAGE_ALIGNED_MALLOC
3
dnl Some operating systems (generally, BSD Unix variants) lack a
4
dnl posix_memalign function, a memalign function, and a working
5
dnl (meaning, the memory can be freed) valloc function. To make up for
6
dnl it, the malloc function promises to return page-aligned addresses
7
dnl if more than one page's worth of memory is allocated.
8
dnl AX_CHECK_PAGE_ALIGNED_MALLOC checks for this condition and defines
9
dnl HAVE_PAGE_ALIGNED_MALLOC if the condition holds.
11
dnl As an aside, note that valloc'd memory cannot safely be freed on
12
dnl all operating systems. (Again, some flavors of BSD are the
13
dnl troublemakers.) It's best to avoid using valloc in favor of
14
dnl posix_memalign, memalign, or an aligned malloc as detected by
15
dnl AX_CHECK_PAGE_ALIGNED_MALLOC.
17
dnl Caveat: AX_CHECK_PAGE_ALIGNED_MALLOC takes a probabalistic
18
dnl approach. If 100 calls to malloc all return page-aligned addresses,
19
dnl it assumes that all calls will behave likewise. It is therefore
20
dnl possible -- albeit extremely unlikely -- that
21
dnl AX_CHECK_PAGE_ALIGNED_MALLOC can return a false positive.
24
dnl @author Scott Pakin <pakin@uiuc.edu>
25
dnl @version 2005-01-22
26
dnl @license AllPermissive
28
AC_DEFUN([AX_CHECK_PAGE_ALIGNED_MALLOC],
29
[AC_CACHE_CHECK([if large mallocs guarantee page-alignment],
30
[ax_cv_func_malloc_aligned],
40
int pagesize = getpagesize();
44
if ((unsigned long)malloc(pagesize+1) & (pagesize-1))
49
[ax_cv_func_malloc_aligned=yes],
50
[ax_cv_func_malloc_aligned=no],
51
[ax_cv_func_malloc_aligned=no])
53
if test "$ax_cv_func_malloc_aligned" = yes ; then
54
AC_DEFINE([HAVE_PAGE_ALIGNED_MALLOC], [1],
55
[Define if `malloc'ing more than one page always returns a page-aligned address.])