~ubuntu-branches/debian/squeeze/ffcall/squeeze

« back to all changes in this revision

Viewing changes to src/m4/mprotect.m4

  • Committer: Bazaar Package Importer
  • Author(s): Christoph Egger
  • Date: 2010-06-26 15:29:30 UTC
  • mfrom: (5.1.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20100626152930-c09y01gk3szcnykn
Tags: 1.10+cvs20100619-2
Ship to unstable

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
dnl -*- Autoconf -*-
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.
8
 
 
9
 
dnl From Bruno Haible, Marcus Daniels, Sam Steingold.
10
 
 
11
 
AC_PREREQ(2.57)
12
 
 
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, [
19
 
mprotect_prog='
20
 
#include <sys/types.h>
21
 
/* declare malloc() */
22
 
#include <stdlib.h>
23
 
#ifdef HAVE_UNISTD_H
24
 
#include <unistd.h>
25
 
#endif
26
 
/* declare getpagesize() and mprotect() */
27
 
#include <sys/mman.h>
28
 
#ifndef HAVE_GETPAGESIZE
29
 
#include <sys/param.h>
30
 
#define getpagesize() PAGESIZE
31
 
#else
32
 
]AC_LANG_EXTERN[
33
 
#if defined(__STDC__) || defined(__cplusplus)
34
 
RETGETPAGESIZETYPE getpagesize (void);
35
 
#else
36
 
RETGETPAGESIZETYPE getpagesize();
37
 
#endif
38
 
#endif
39
 
char foo;
40
 
int main () {
41
 
  unsigned long pagesize = getpagesize();
42
 
#define page_align(address)  (char*)((unsigned long)(address) & -pagesize)
43
 
'
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.
48
 
no_mprotect=1)
49
 
mprotect_prog="$mprotect_prog"'
50
 
  char* area = (char*) malloc(6*pagesize);
51
 
  char* fault_address = area + pagesize*7/2;
52
 
'
53
 
if test -z "$no_mprotect"; then
54
 
AC_TRY_RUN(GL_NOCRASH[$mprotect_prog
55
 
  nocrash_init();
56
 
  if (mprotect(page_align(fault_address),pagesize,PROT_NONE) < 0) exit(0);
57
 
  foo = *fault_address; /* this should cause an exception or signal */
58
 
  exit(0); }],
59
 
  no_mprotect=1, ,
60
 
: # When cross-compiling, don't assume anything.
61
 
)
62
 
fi
63
 
if test -z "$no_mprotect"; then
64
 
AC_TRY_RUN(GL_NOCRASH[$mprotect_prog
65
 
  nocrash_init();
66
 
  if (mprotect(page_align(fault_address),pagesize,PROT_NONE) < 0) exit(0);
67
 
  *fault_address = 'z'; /* this should cause an exception or signal */
68
 
  exit(0); }],
69
 
  no_mprotect=1, ,
70
 
: # When cross-compiling, don't assume anything.
71
 
)
72
 
fi
73
 
if test -z "$no_mprotect"; then
74
 
AC_TRY_RUN(GL_NOCRASH[$mprotect_prog
75
 
  nocrash_init();
76
 
  if (mprotect(page_align(fault_address),pagesize,PROT_READ) < 0) exit(0);
77
 
  *fault_address = 'z'; /* this should cause an exception or signal */
78
 
  exit(0); }],
79
 
  no_mprotect=1, ,
80
 
: # When cross-compiling, don't assume anything.
81
 
)
82
 
fi
83
 
if test -z "$no_mprotect"; then
84
 
AC_TRY_RUN(GL_NOCRASH[$mprotect_prog
85
 
  nocrash_init();
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.
91
 
)
92
 
fi
93
 
if test -z "$no_mprotect"; then
94
 
  cl_cv_func_mprotect_works=yes
95
 
else
96
 
  cl_cv_func_mprotect_works=no
97
 
fi
98
 
])
99
 
if test $cl_cv_func_mprotect_works = yes; then
100
 
  AC_DEFINE(HAVE_WORKING_MPROTECT,,[have a working mprotect() function])
101
 
fi
102
 
fi
103
 
])