26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
-
-
-
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
|
/* declare getpagesize() and mprotect() */
#include <sys/mman.h>
#ifndef HAVE_GETPAGESIZE
#include <sys/param.h>
#define getpagesize() PAGESIZE
#else
]AC_LANG_EXTERN[
#if defined(__STDC__) || defined(__cplusplus)
RETGETPAGESIZETYPE getpagesize (void);
#else
RETGETPAGESIZETYPE getpagesize();
#endif
#endif
char foo;
int main () {
unsigned long pagesize = getpagesize();
#define page_align(address) (char*)((unsigned long)(address) & -pagesize)
'
AC_TRY_RUN([$mprotect_prog
if ((pagesize-1) & pagesize) exit(1);
exit(0); }], , no_mprotect=1,
# When cross-compiling, don't assume anything.
no_mprotect=1)
mprotect_prog="$mprotect_prog"'
char* area = (char*) malloc(6*pagesize);
char* fault_address = area + pagesize*7/2;
'
if test -z "$no_mprotect"; then
AC_TRY_RUN([$mprotect_prog
AC_TRY_RUN(GL_NOCRASH[$mprotect_prog
nocrash_init();
if (mprotect(page_align(fault_address),pagesize,PROT_NONE) < 0) exit(0);
foo = *fault_address; /* this should cause a core dump */
exit(0); }],
foo = *fault_address; /* this should cause an exception or signal */
exit(0); }], no_mprotect=1, ,
no_mprotect=1, rm -f core,
: # When cross-compiling, don't assume anything.
)
fi
if test -z "$no_mprotect"; then
AC_TRY_RUN([$mprotect_prog
AC_TRY_RUN(GL_NOCRASH[$mprotect_prog
nocrash_init();
if (mprotect(page_align(fault_address),pagesize,PROT_NONE) < 0) exit(0);
*fault_address = 'z'; /* this should cause a core dump */
exit(0); }],
*fault_address = 'z'; /* this should cause an exception or signal */
exit(0); }], no_mprotect=1, ,
no_mprotect=1, rm -f core,
: # When cross-compiling, don't assume anything.
)
fi
if test -z "$no_mprotect"; then
AC_TRY_RUN([$mprotect_prog
AC_TRY_RUN(GL_NOCRASH[$mprotect_prog
nocrash_init();
if (mprotect(page_align(fault_address),pagesize,PROT_READ) < 0) exit(0);
*fault_address = 'z'; /* this should cause a core dump */
exit(0); }],
*fault_address = 'z'; /* this should cause an exception or signal */
exit(0); }], no_mprotect=1, ,
no_mprotect=1, rm -f core,
: # When cross-compiling, don't assume anything.
)
fi
if test -z "$no_mprotect"; then
AC_TRY_RUN([$mprotect_prog
AC_TRY_RUN(GL_NOCRASH[$mprotect_prog
nocrash_init();
if (mprotect(page_align(fault_address),pagesize,PROT_READ) < 0) exit(1);
if (mprotect(page_align(fault_address),pagesize,PROT_READ|PROT_WRITE) < 0) exit(1);
*fault_address = 'z'; /* this should not cause a core dump */
exit(0); }], , no_mprotect=1
*fault_address = 'z'; /* this should not cause an exception or signal */
exit(0); }], , no_mprotect=1,
rm -f core,
: # When cross-compiling, don't assume anything.
)
fi
if test -z "$no_mprotect"; then
cl_cv_func_mprotect_works=yes
else
cl_cv_func_mprotect_works=no
fi
])
if test $cl_cv_func_mprotect_works = yes; then
AC_DEFINE(HAVE_WORKING_MPROTECT,,[have a working mprotect() function])
AC_DEFINE([HAVE_WORKING_MPROTECT],[],[have a working mprotect() function])
fi
fi
])
|