2
dnl Copyright (C) 1993-2005 Free Software Foundation, Inc.
3
dnl This file is free software, distributed under the terms of the GNU
4
dnl General Public License. As a special exception to the GNU General
5
dnl Public License, this file may be distributed as part of a program
6
dnl that contains a configuration script generated by Autoconf, under
7
dnl the same distribution terms as the rest of that program.
9
dnl From Bruno Haible, Marcus Daniels, Sam Steingold.
13
AC_DEFUN([CL_MPROTECT],
14
[AC_REQUIRE([CL_GETPAGESIZE])dnl
15
AC_REQUIRE([CL_MMAP])dnl
16
AC_CHECK_FUNCS(mprotect)dnl
17
if test $ac_cv_func_mprotect = yes; then
18
AC_CACHE_CHECK(for working mprotect, cl_cv_func_mprotect_works, [
20
#include <sys/types.h>
21
/* declare malloc() */
26
/* declare getpagesize() and mprotect() */
28
#ifndef HAVE_GETPAGESIZE
29
#include <sys/param.h>
30
#define getpagesize() PAGESIZE
33
#if defined(__STDC__) || defined(__cplusplus)
34
RETGETPAGESIZETYPE getpagesize (void);
36
RETGETPAGESIZETYPE getpagesize();
41
unsigned long pagesize = getpagesize();
42
#define page_align(address) (char*)((unsigned long)(address) & -pagesize)
44
AC_TRY_RUN([$mprotect_prog
45
if ((pagesize-1) & pagesize) exit(1);
46
exit(0); }], , no_mprotect=1,
47
# When cross-compiling, don't assume anything.
49
mprotect_prog="$mprotect_prog"'
50
char* area = (char*) malloc(6*pagesize);
51
char* fault_address = area + pagesize*7/2;
53
if test -z "$no_mprotect"; then
54
AC_TRY_RUN(GL_NOCRASH[$mprotect_prog
56
if (mprotect(page_align(fault_address),pagesize,PROT_NONE) < 0) exit(0);
57
foo = *fault_address; /* this should cause an exception or signal */
60
: # When cross-compiling, don't assume anything.
63
if test -z "$no_mprotect"; then
64
AC_TRY_RUN(GL_NOCRASH[$mprotect_prog
66
if (mprotect(page_align(fault_address),pagesize,PROT_NONE) < 0) exit(0);
67
*fault_address = 'z'; /* this should cause an exception or signal */
70
: # When cross-compiling, don't assume anything.
73
if test -z "$no_mprotect"; then
74
AC_TRY_RUN(GL_NOCRASH[$mprotect_prog
76
if (mprotect(page_align(fault_address),pagesize,PROT_READ) < 0) exit(0);
77
*fault_address = 'z'; /* this should cause an exception or signal */
80
: # When cross-compiling, don't assume anything.
83
if test -z "$no_mprotect"; then
84
AC_TRY_RUN(GL_NOCRASH[$mprotect_prog
86
if (mprotect(page_align(fault_address),pagesize,PROT_READ) < 0) exit(1);
87
if (mprotect(page_align(fault_address),pagesize,PROT_READ|PROT_WRITE) < 0) exit(1);
88
*fault_address = 'z'; /* this should not cause an exception or signal */
89
exit(0); }], , no_mprotect=1,
90
: # When cross-compiling, don't assume anything.
93
if test -z "$no_mprotect"; then
94
cl_cv_func_mprotect_works=yes
96
cl_cv_func_mprotect_works=no
99
if test $cl_cv_func_mprotect_works = yes; then
100
AC_DEFINE(HAVE_WORKING_MPROTECT,,[have a working mprotect() function])