Branch: Tag:

2005-05-30

2005-05-30 15:47:53 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Improved mmap PROT_EXEC test.

Rev: src/configure.in:1.883

1: - AC_REVISION("$Id: configure.in,v 1.882 2005/05/30 13:22:54 grubba Exp $") + AC_REVISION("$Id: configure.in,v 1.883 2005/05/30 15:47:53 grubba Exp $")   AC_INIT(interpret.c)   AC_CONFIG_HEADER(machine.h)   
2261:    # MinGW system.    cat <<\EOF   #!/bin/sh - # Automatically generated by $Id: configure.in,v 1.882 2005/05/30 13:22:54 grubba Exp $. + # Automatically generated by $Id: configure.in,v 1.883 2005/05/30 15:47:53 grubba Exp $.   # MinGW-version. Do NOT edit.   posix_name="`cat`"   posix_prefix="/"
2299:    # Native POSIX system.    cat <<\EOF   #!/bin/sh - # Automatically generated by $Id: configure.in,v 1.882 2005/05/30 13:22:54 grubba Exp $. + # Automatically generated by $Id: configure.in,v 1.883 2005/05/30 15:47:53 grubba Exp $.   # POSIX-version. Do NOT edit.   cat   EOF
2308:    # rntcl-style    cat <<\EOF   #!/bin/sh - # Automatically generated by $Id: configure.in,v 1.882 2005/05/30 13:22:54 grubba Exp $. + # Automatically generated by $Id: configure.in,v 1.883 2005/05/30 15:47:53 grubba Exp $.   # RNTCL-version. Do NOT edit.   sed -e "$PIKE_PATH_TRANSLATE"   EOF
3757:   if test "x$ac_cv_func_mmap" = "xyes"; then    # Mac OS X has an mmap that fails with ENODEV if we try    # to use it for mexec_alloc et al. +  # +  # NB: mmap with MAP_ANON does however work.    AC_MSG_CHECKING([if mmap can be used to allocate PROT_EXEC])    AC_CACHE_VAL(pike_cv_mmap_PROT_EXEC, [    AC_TRY_RUN([
3780:      #include <errno.h>    + #if !defined(MAP_ANONYMOUS) && defined(MAP_ANON) + #define MAP_ANONYMOUS MAP_ANON + #endif /* !MAP_ANONYMOUS && MAP_ANON */ +     int main(int argc, char **argv)    {    void *ptr; -  int dev_zero = open("/dev/zero", O_RDONLY); +  int dev_zero = -1; + #ifndef MAP_ANONYMOUS +  /* Neither MAP_ANONYMOUS nor MAP_ANON. +  * Map some /dev/zero. +  */ +  dev_zero = open("/dev/zero", O_RDONLY);    if (dev_zero < 0) {    fprintf(stderr, "open(\"/dev/zero\", O_RDONLY) failed. errno: %d\n",    errno);    return 1;    } -  + #define MAP_ANONYMOUS 0 + #endif /* !MAP_ANONYMOUS */    if ((ptr = mmap(NULL, 8192, PROT_EXEC|PROT_READ|PROT_WRITE, -  MAP_PRIVATE, dev_zero, 0)) == MAP_FAILED) { +  MAP_PRIVATE|MAP_ANONYMOUS, +  dev_zero, 0)) == MAP_FAILED) {    fprintf(stderr, "mmap(NULL, 8192, PROT_EXEC|PROT_READ|PROT_WRITE,\n" -  "MAP_PRIVATE, %d, 0) failed. errno: %d\n", +  "MAP_PRIVATE|MAP_ANONYMOUS, %d, 0) failed. errno: %d\n",    dev_zero,    errno);    return 2;
3822:   #endif      #include <errno.h> +  + #if !defined(MAP_ANONYMOUS) && defined(MAP_ANON) + #define MAP_ANONYMOUS MAP_ANON + #endif /* !MAP_ANONYMOUS && MAP_ANON */ +  + #if !defined(MAP_ANONYMOUS) && defined(MAP_ANON) + #define MAP_ANONYMOUS MAP_ANON + #endif /* !MAP_ANONYMOUS && MAP_ANON */    ], [    void *ptr; -  int dev_zero = open("/dev/zero", O_RDONLY); +  int dev_zero = -1; + #ifndef MAP_ANONYMOUS +  /* Neither MAP_ANONYMOUS nor MAP_ANON. +  * Map some /dev/zero. +  */ +  dev_zero = open("/dev/zero", O_RDONLY);    if (dev_zero < 0) return 1; -  + #define MAP_ANONYMOUS 0 + #endif /* !MAP_ANONYMOUS */    if ((ptr = mmap(NULL, 8192, PROT_EXEC|PROT_READ|PROT_WRITE, -  MAP_PRIVATE, dev_zero, 0)) == MAP_FAILED) { +  MAP_PRIVATE|MAP_ANONYMOUS, +  dev_zero, 0)) == MAP_FAILED) {    return 2;    }    return 0;