Artifact
c869fe2d0fb0ea45f99eec20d3fe61a2766c5f54:
0000: 64 6e 6c 20 2d 2a 2d 20 41 75 74 6f 63 6f 6e 66 dnl -*- Autoconf
0010: 20 2d 2a 2d 0a 64 6e 6c 20 43 6f 70 79 72 69 67 -*-.dnl Copyrig
0020: 68 74 20 28 43 29 20 31 39 39 33 2d 32 30 30 39 ht (C) 1993-2009
0030: 20 46 72 65 65 20 53 6f 66 74 77 61 72 65 20 46 Free Software F
0040: 6f 75 6e 64 61 74 69 6f 6e 2c 20 49 6e 63 2e 0a oundation, Inc..
0050: 64 6e 6c 20 54 68 69 73 20 66 69 6c 65 20 69 73 dnl This file is
0060: 20 66 72 65 65 20 73 6f 66 74 77 61 72 65 2c 20 free software,
0070: 64 69 73 74 72 69 62 75 74 65 64 20 75 6e 64 65 distributed unde
0080: 72 20 74 68 65 20 74 65 72 6d 73 20 6f 66 20 74 r the terms of t
0090: 68 65 20 47 4e 55 0a 64 6e 6c 20 47 65 6e 65 72 he GNU.dnl Gener
00a0: 61 6c 20 50 75 62 6c 69 63 20 4c 69 63 65 6e 73 al Public Licens
00b0: 65 2e 20 20 41 73 20 61 20 73 70 65 63 69 61 6c e. As a special
00c0: 20 65 78 63 65 70 74 69 6f 6e 20 74 6f 20 74 68 exception to th
00d0: 65 20 47 4e 55 20 47 65 6e 65 72 61 6c 0a 64 6e e GNU General.dn
00e0: 6c 20 50 75 62 6c 69 63 20 4c 69 63 65 6e 73 65 l Public License
00f0: 2c 20 74 68 69 73 20 66 69 6c 65 20 6d 61 79 20 , this file may
0100: 62 65 20 64 69 73 74 72 69 62 75 74 65 64 20 61 be distributed a
0110: 73 20 70 61 72 74 20 6f 66 20 61 20 70 72 6f 67 s part of a prog
0120: 72 61 6d 0a 64 6e 6c 20 74 68 61 74 20 63 6f 6e ram.dnl that con
0130: 74 61 69 6e 73 20 61 20 63 6f 6e 66 69 67 75 72 tains a configur
0140: 61 74 69 6f 6e 20 73 63 72 69 70 74 20 67 65 6e ation script gen
0150: 65 72 61 74 65 64 20 62 79 20 41 75 74 6f 63 6f erated by Autoco
0160: 6e 66 2c 20 75 6e 64 65 72 0a 64 6e 6c 20 74 68 nf, under.dnl th
0170: 65 20 73 61 6d 65 20 64 69 73 74 72 69 62 75 74 e same distribut
0180: 69 6f 6e 20 74 65 72 6d 73 20 61 73 20 74 68 65 ion terms as the
0190: 20 72 65 73 74 20 6f 66 20 74 68 61 74 20 70 72 rest of that pr
01a0: 6f 67 72 61 6d 2e 0a 0a 64 6e 6c 20 46 72 6f 6d ogram...dnl From
01b0: 20 42 72 75 6e 6f 20 48 61 69 62 6c 65 2c 20 4d Bruno Haible, M
01c0: 61 72 63 75 73 20 44 61 6e 69 65 6c 73 2c 20 53 arcus Daniels, S
01d0: 61 6d 20 53 74 65 69 6e 67 6f 6c 64 2e 0a 0a 41 am Steingold...A
01e0: 43 5f 50 52 45 52 45 51 28 32 2e 35 37 29 0a 0a C_PREREQ(2.57)..
01f0: 41 43 5f 44 45 46 55 4e 28 5b 43 4c 5f 4d 50 52 AC_DEFUN([CL_MPR
0200: 4f 54 45 43 54 5d 2c 0a 5b 41 43 5f 52 45 51 55 OTECT],.[AC_REQU
0210: 49 52 45 28 5b 43 4c 5f 47 45 54 50 41 47 45 53 IRE([CL_GETPAGES
0220: 49 5a 45 5d 29 64 6e 6c 0a 41 43 5f 52 45 51 55 IZE])dnl.AC_REQU
0230: 49 52 45 28 5b 43 4c 5f 4d 4d 41 50 5d 29 64 6e IRE([CL_MMAP])dn
0240: 6c 0a 41 43 5f 43 48 45 43 4b 5f 46 55 4e 43 53 l.AC_CHECK_FUNCS
0250: 28 6d 70 72 6f 74 65 63 74 29 64 6e 6c 0a 69 66 (mprotect)dnl.if
0260: 20 74 65 73 74 20 24 61 63 5f 63 76 5f 66 75 6e test $ac_cv_fun
0270: 63 5f 6d 70 72 6f 74 65 63 74 20 3d 20 79 65 73 c_mprotect = yes
0280: 3b 20 74 68 65 6e 0a 41 43 5f 43 41 43 48 45 5f ; then.AC_CACHE_
0290: 43 48 45 43 4b 28 66 6f 72 20 77 6f 72 6b 69 6e CHECK(for workin
02a0: 67 20 6d 70 72 6f 74 65 63 74 2c 20 63 6c 5f 63 g mprotect, cl_c
02b0: 76 5f 66 75 6e 63 5f 6d 70 72 6f 74 65 63 74 5f v_func_mprotect_
02c0: 77 6f 72 6b 73 2c 20 5b 0a 6d 70 72 6f 74 65 63 works, [.mprotec
02d0: 74 5f 70 72 6f 67 3d 27 0a 23 69 6e 63 6c 75 64 t_prog='.#includ
02e0: 65 20 3c 73 79 73 2f 74 79 70 65 73 2e 68 3e 0a e <sys/types.h>.
02f0: 2f 2a 20 64 65 63 6c 61 72 65 20 6d 61 6c 6c 6f /* declare mallo
0300: 63 28 29 20 2a 2f 0a 23 69 6e 63 6c 75 64 65 20 c() */.#include
0310: 3c 73 74 64 6c 69 62 2e 68 3e 0a 23 69 66 64 65 <stdlib.h>.#ifde
0320: 66 20 48 41 56 45 5f 55 4e 49 53 54 44 5f 48 0a f HAVE_UNISTD_H.
0330: 23 69 6e 63 6c 75 64 65 20 3c 75 6e 69 73 74 64 #include <unistd
0340: 2e 68 3e 0a 23 65 6e 64 69 66 0a 2f 2a 20 64 65 .h>.#endif./* de
0350: 63 6c 61 72 65 20 67 65 74 70 61 67 65 73 69 7a clare getpagesiz
0360: 65 28 29 20 61 6e 64 20 6d 70 72 6f 74 65 63 74 e() and mprotect
0370: 28 29 20 2a 2f 0a 23 69 6e 63 6c 75 64 65 20 3c () */.#include <
0380: 73 79 73 2f 6d 6d 61 6e 2e 68 3e 0a 23 69 66 6e sys/mman.h>.#ifn
0390: 64 65 66 20 48 41 56 45 5f 47 45 54 50 41 47 45 def HAVE_GETPAGE
03a0: 53 49 5a 45 0a 23 69 6e 63 6c 75 64 65 20 3c 73 SIZE.#include <s
03b0: 79 73 2f 70 61 72 61 6d 2e 68 3e 0a 23 64 65 66 ys/param.h>.#def
03c0: 69 6e 65 20 67 65 74 70 61 67 65 73 69 7a 65 28 ine getpagesize(
03d0: 29 20 50 41 47 45 53 49 5a 45 0a 23 65 6c 73 65 ) PAGESIZE.#else
03e0: 0a 5d 41 43 5f 4c 41 4e 47 5f 45 58 54 45 52 4e .]AC_LANG_EXTERN
03f0: 5b 0a 52 45 54 47 45 54 50 41 47 45 53 49 5a 45 [.RETGETPAGESIZE
0400: 54 59 50 45 20 67 65 74 70 61 67 65 73 69 7a 65 TYPE getpagesize
0410: 20 28 76 6f 69 64 29 3b 0a 23 65 6e 64 69 66 0a (void);.#endif.
0420: 63 68 61 72 20 66 6f 6f 3b 0a 69 6e 74 20 6d 61 char foo;.int ma
0430: 69 6e 20 28 29 20 7b 0a 20 20 75 6e 73 69 67 6e in () {. unsign
0440: 65 64 20 6c 6f 6e 67 20 70 61 67 65 73 69 7a 65 ed long pagesize
0450: 20 3d 20 67 65 74 70 61 67 65 73 69 7a 65 28 29 = getpagesize()
0460: 3b 0a 23 64 65 66 69 6e 65 20 70 61 67 65 5f 61 ;.#define page_a
0470: 6c 69 67 6e 28 61 64 64 72 65 73 73 29 20 20 28 lign(address) (
0480: 63 68 61 72 2a 29 28 28 75 6e 73 69 67 6e 65 64 char*)((unsigned
0490: 20 6c 6f 6e 67 29 28 61 64 64 72 65 73 73 29 20 long)(address)
04a0: 26 20 2d 70 61 67 65 73 69 7a 65 29 0a 27 0a 41 & -pagesize).'.A
04b0: 43 5f 54 52 59 5f 52 55 4e 28 5b 24 6d 70 72 6f C_TRY_RUN([$mpro
04c0: 74 65 63 74 5f 70 72 6f 67 0a 20 20 69 66 20 28 tect_prog. if (
04d0: 28 70 61 67 65 73 69 7a 65 2d 31 29 20 26 20 70 (pagesize-1) & p
04e0: 61 67 65 73 69 7a 65 29 20 65 78 69 74 28 31 29 agesize) exit(1)
04f0: 3b 0a 20 20 65 78 69 74 28 30 29 3b 20 7d 5d 2c ;. exit(0); }],
0500: 20 2c 20 6e 6f 5f 6d 70 72 6f 74 65 63 74 3d 31 , no_mprotect=1
0510: 2c 0a 23 20 57 68 65 6e 20 63 72 6f 73 73 2d 63 ,.# When cross-c
0520: 6f 6d 70 69 6c 69 6e 67 2c 20 64 6f 6e 27 74 20 ompiling, don't
0530: 61 73 73 75 6d 65 20 61 6e 79 74 68 69 6e 67 2e assume anything.
0540: 0a 6e 6f 5f 6d 70 72 6f 74 65 63 74 3d 31 29 0a .no_mprotect=1).
0550: 6d 70 72 6f 74 65 63 74 5f 70 72 6f 67 3d 22 24 mprotect_prog="$
0560: 6d 70 72 6f 74 65 63 74 5f 70 72 6f 67 22 27 0a mprotect_prog"'.
0570: 20 20 63 68 61 72 2a 20 61 72 65 61 20 3d 20 28 char* area = (
0580: 63 68 61 72 2a 29 20 6d 61 6c 6c 6f 63 28 36 2a char*) malloc(6*
0590: 70 61 67 65 73 69 7a 65 29 3b 0a 20 20 63 68 61 pagesize);. cha
05a0: 72 2a 20 66 61 75 6c 74 5f 61 64 64 72 65 73 73 r* fault_address
05b0: 20 3d 20 61 72 65 61 20 2b 20 70 61 67 65 73 69 = area + pagesi
05c0: 7a 65 2a 37 2f 32 3b 0a 27 0a 69 66 20 74 65 73 ze*7/2;.'.if tes
05d0: 74 20 2d 7a 20 22 24 6e 6f 5f 6d 70 72 6f 74 65 t -z "$no_mprote
05e0: 63 74 22 3b 20 74 68 65 6e 0a 41 43 5f 54 52 59 ct"; then.AC_TRY
05f0: 5f 52 55 4e 28 47 4c 5f 4e 4f 43 52 41 53 48 5b _RUN(GL_NOCRASH[
0600: 24 6d 70 72 6f 74 65 63 74 5f 70 72 6f 67 0a 20 $mprotect_prog.
0610: 20 6e 6f 63 72 61 73 68 5f 69 6e 69 74 28 29 3b nocrash_init();
0620: 0a 20 20 69 66 20 28 6d 70 72 6f 74 65 63 74 28 . if (mprotect(
0630: 70 61 67 65 5f 61 6c 69 67 6e 28 66 61 75 6c 74 page_align(fault
0640: 5f 61 64 64 72 65 73 73 29 2c 70 61 67 65 73 69 _address),pagesi
0650: 7a 65 2c 50 52 4f 54 5f 4e 4f 4e 45 29 20 3c 20 ze,PROT_NONE) <
0660: 30 29 20 65 78 69 74 28 30 29 3b 0a 20 20 66 6f 0) exit(0);. fo
0670: 6f 20 3d 20 2a 66 61 75 6c 74 5f 61 64 64 72 65 o = *fault_addre
0680: 73 73 3b 20 2f 2a 20 74 68 69 73 20 73 68 6f 75 ss; /* this shou
0690: 6c 64 20 63 61 75 73 65 20 61 6e 20 65 78 63 65 ld cause an exce
06a0: 70 74 69 6f 6e 20 6f 72 20 73 69 67 6e 61 6c 20 ption or signal
06b0: 2a 2f 0a 20 20 65 78 69 74 28 30 29 3b 20 7d 5d */. exit(0); }]
06c0: 2c 20 6e 6f 5f 6d 70 72 6f 74 65 63 74 3d 31 2c , no_mprotect=1,
06d0: 20 2c 0a 3a 20 23 20 57 68 65 6e 20 63 72 6f 73 ,.: # When cros
06e0: 73 2d 63 6f 6d 70 69 6c 69 6e 67 2c 20 64 6f 6e s-compiling, don
06f0: 27 74 20 61 73 73 75 6d 65 20 61 6e 79 74 68 69 't assume anythi
0700: 6e 67 2e 0a 29 0a 66 69 0a 69 66 20 74 65 73 74 ng..).fi.if test
0710: 20 2d 7a 20 22 24 6e 6f 5f 6d 70 72 6f 74 65 63 -z "$no_mprotec
0720: 74 22 3b 20 74 68 65 6e 0a 41 43 5f 54 52 59 5f t"; then.AC_TRY_
0730: 52 55 4e 28 47 4c 5f 4e 4f 43 52 41 53 48 5b 24 RUN(GL_NOCRASH[$
0740: 6d 70 72 6f 74 65 63 74 5f 70 72 6f 67 0a 20 20 mprotect_prog.
0750: 6e 6f 63 72 61 73 68 5f 69 6e 69 74 28 29 3b 0a nocrash_init();.
0760: 20 20 69 66 20 28 6d 70 72 6f 74 65 63 74 28 70 if (mprotect(p
0770: 61 67 65 5f 61 6c 69 67 6e 28 66 61 75 6c 74 5f age_align(fault_
0780: 61 64 64 72 65 73 73 29 2c 70 61 67 65 73 69 7a address),pagesiz
0790: 65 2c 50 52 4f 54 5f 4e 4f 4e 45 29 20 3c 20 30 e,PROT_NONE) < 0
07a0: 29 20 65 78 69 74 28 30 29 3b 0a 20 20 2a 66 61 ) exit(0);. *fa
07b0: 75 6c 74 5f 61 64 64 72 65 73 73 20 3d 20 27 7a ult_address = 'z
07c0: 27 3b 20 2f 2a 20 74 68 69 73 20 73 68 6f 75 6c '; /* this shoul
07d0: 64 20 63 61 75 73 65 20 61 6e 20 65 78 63 65 70 d cause an excep
07e0: 74 69 6f 6e 20 6f 72 20 73 69 67 6e 61 6c 20 2a tion or signal *
07f0: 2f 0a 20 20 65 78 69 74 28 30 29 3b 20 7d 5d 2c /. exit(0); }],
0800: 20 6e 6f 5f 6d 70 72 6f 74 65 63 74 3d 31 2c 20 no_mprotect=1,
0810: 2c 0a 3a 20 23 20 57 68 65 6e 20 63 72 6f 73 73 ,.: # When cross
0820: 2d 63 6f 6d 70 69 6c 69 6e 67 2c 20 64 6f 6e 27 -compiling, don'
0830: 74 20 61 73 73 75 6d 65 20 61 6e 79 74 68 69 6e t assume anythin
0840: 67 2e 0a 29 0a 66 69 0a 69 66 20 74 65 73 74 20 g..).fi.if test
0850: 2d 7a 20 22 24 6e 6f 5f 6d 70 72 6f 74 65 63 74 -z "$no_mprotect
0860: 22 3b 20 74 68 65 6e 0a 41 43 5f 54 52 59 5f 52 "; then.AC_TRY_R
0870: 55 4e 28 47 4c 5f 4e 4f 43 52 41 53 48 5b 24 6d UN(GL_NOCRASH[$m
0880: 70 72 6f 74 65 63 74 5f 70 72 6f 67 0a 20 20 6e protect_prog. n
0890: 6f 63 72 61 73 68 5f 69 6e 69 74 28 29 3b 0a 20 ocrash_init();.
08a0: 20 69 66 20 28 6d 70 72 6f 74 65 63 74 28 70 61 if (mprotect(pa
08b0: 67 65 5f 61 6c 69 67 6e 28 66 61 75 6c 74 5f 61 ge_align(fault_a
08c0: 64 64 72 65 73 73 29 2c 70 61 67 65 73 69 7a 65 ddress),pagesize
08d0: 2c 50 52 4f 54 5f 52 45 41 44 29 20 3c 20 30 29 ,PROT_READ) < 0)
08e0: 20 65 78 69 74 28 30 29 3b 0a 20 20 2a 66 61 75 exit(0);. *fau
08f0: 6c 74 5f 61 64 64 72 65 73 73 20 3d 20 27 7a 27 lt_address = 'z'
0900: 3b 20 2f 2a 20 74 68 69 73 20 73 68 6f 75 6c 64 ; /* this should
0910: 20 63 61 75 73 65 20 61 6e 20 65 78 63 65 70 74 cause an except
0920: 69 6f 6e 20 6f 72 20 73 69 67 6e 61 6c 20 2a 2f ion or signal */
0930: 0a 20 20 65 78 69 74 28 30 29 3b 20 7d 5d 2c 20 . exit(0); }],
0940: 6e 6f 5f 6d 70 72 6f 74 65 63 74 3d 31 2c 20 2c no_mprotect=1, ,
0950: 0a 3a 20 23 20 57 68 65 6e 20 63 72 6f 73 73 2d .: # When cross-
0960: 63 6f 6d 70 69 6c 69 6e 67 2c 20 64 6f 6e 27 74 compiling, don't
0970: 20 61 73 73 75 6d 65 20 61 6e 79 74 68 69 6e 67 assume anything
0980: 2e 0a 29 0a 66 69 0a 69 66 20 74 65 73 74 20 2d ..).fi.if test -
0990: 7a 20 22 24 6e 6f 5f 6d 70 72 6f 74 65 63 74 22 z "$no_mprotect"
09a0: 3b 20 74 68 65 6e 0a 41 43 5f 54 52 59 5f 52 55 ; then.AC_TRY_RU
09b0: 4e 28 47 4c 5f 4e 4f 43 52 41 53 48 5b 24 6d 70 N(GL_NOCRASH[$mp
09c0: 72 6f 74 65 63 74 5f 70 72 6f 67 0a 20 20 6e 6f rotect_prog. no
09d0: 63 72 61 73 68 5f 69 6e 69 74 28 29 3b 0a 20 20 crash_init();.
09e0: 69 66 20 28 6d 70 72 6f 74 65 63 74 28 70 61 67 if (mprotect(pag
09f0: 65 5f 61 6c 69 67 6e 28 66 61 75 6c 74 5f 61 64 e_align(fault_ad
0a00: 64 72 65 73 73 29 2c 70 61 67 65 73 69 7a 65 2c dress),pagesize,
0a10: 50 52 4f 54 5f 52 45 41 44 29 20 3c 20 30 29 20 PROT_READ) < 0)
0a20: 65 78 69 74 28 31 29 3b 0a 20 20 69 66 20 28 6d exit(1);. if (m
0a30: 70 72 6f 74 65 63 74 28 70 61 67 65 5f 61 6c 69 protect(page_ali
0a40: 67 6e 28 66 61 75 6c 74 5f 61 64 64 72 65 73 73 gn(fault_address
0a50: 29 2c 70 61 67 65 73 69 7a 65 2c 50 52 4f 54 5f ),pagesize,PROT_
0a60: 52 45 41 44 7c 50 52 4f 54 5f 57 52 49 54 45 29 READ|PROT_WRITE)
0a70: 20 3c 20 30 29 20 65 78 69 74 28 31 29 3b 0a 20 < 0) exit(1);.
0a80: 20 2a 66 61 75 6c 74 5f 61 64 64 72 65 73 73 20 *fault_address
0a90: 3d 20 27 7a 27 3b 20 2f 2a 20 74 68 69 73 20 73 = 'z'; /* this s
0aa0: 68 6f 75 6c 64 20 6e 6f 74 20 63 61 75 73 65 20 hould not cause
0ab0: 61 6e 20 65 78 63 65 70 74 69 6f 6e 20 6f 72 20 an exception or
0ac0: 73 69 67 6e 61 6c 20 2a 2f 0a 20 20 65 78 69 74 signal */. exit
0ad0: 28 30 29 3b 20 7d 5d 2c 20 2c 20 6e 6f 5f 6d 70 (0); }], , no_mp
0ae0: 72 6f 74 65 63 74 3d 31 2c 0a 3a 20 23 20 57 68 rotect=1,.: # Wh
0af0: 65 6e 20 63 72 6f 73 73 2d 63 6f 6d 70 69 6c 69 en cross-compili
0b00: 6e 67 2c 20 64 6f 6e 27 74 20 61 73 73 75 6d 65 ng, don't assume
0b10: 20 61 6e 79 74 68 69 6e 67 2e 0a 29 0a 66 69 0a anything..).fi.
0b20: 69 66 20 74 65 73 74 20 2d 7a 20 22 24 6e 6f 5f if test -z "$no_
0b30: 6d 70 72 6f 74 65 63 74 22 3b 20 74 68 65 6e 0a mprotect"; then.
0b40: 20 20 63 6c 5f 63 76 5f 66 75 6e 63 5f 6d 70 72 cl_cv_func_mpr
0b50: 6f 74 65 63 74 5f 77 6f 72 6b 73 3d 79 65 73 0a otect_works=yes.
0b60: 65 6c 73 65 0a 20 20 63 6c 5f 63 76 5f 66 75 6e else. cl_cv_fun
0b70: 63 5f 6d 70 72 6f 74 65 63 74 5f 77 6f 72 6b 73 c_mprotect_works
0b80: 3d 6e 6f 0a 66 69 0a 5d 29 0a 69 66 20 74 65 73 =no.fi.]).if tes
0b90: 74 20 24 63 6c 5f 63 76 5f 66 75 6e 63 5f 6d 70 t $cl_cv_func_mp
0ba0: 72 6f 74 65 63 74 5f 77 6f 72 6b 73 20 3d 20 79 rotect_works = y
0bb0: 65 73 3b 20 74 68 65 6e 0a 20 20 41 43 5f 44 45 es; then. AC_DE
0bc0: 46 49 4e 45 28 5b 48 41 56 45 5f 57 4f 52 4b 49 FINE([HAVE_WORKI
0bd0: 4e 47 5f 4d 50 52 4f 54 45 43 54 5d 2c 5b 5d 2c NG_MPROTECT],[],
0be0: 5b 68 61 76 65 20 61 20 77 6f 72 6b 69 6e 67 20 [have a working
0bf0: 6d 70 72 6f 74 65 63 74 28 29 20 66 75 6e 63 74 mprotect() funct
0c00: 69 6f 6e 5d 29 0a 66 69 0a 66 69 0a 5d 29 0a ion]).fi.fi.]).