X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=tests%2Fzerosize-ptr.h;h=db30f4b104bc7fd73e91bfb681c3a9db81dc579c;hb=1276a2c5f24c0c932426aca9c899fa524d2443f2;hp=fa00aeeee5d6e63824432a410df93371f3f77cdb;hpb=bb051a0a3c0febe9d3fabb21ae5b7fcc2ae7aa10;p=gnulib.git diff --git a/tests/zerosize-ptr.h b/tests/zerosize-ptr.h index fa00aeeee..db30f4b10 100644 --- a/tests/zerosize-ptr.h +++ b/tests/zerosize-ptr.h @@ -1,5 +1,5 @@ /* Return a pointer to a zero-size object in memory. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2014 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -20,7 +20,11 @@ #include -#if HAVE_MPROTECT +/* Test whether mmap() and mprotect() are available. + We don't use HAVE_MMAP, because AC_FUNC_MMAP would not define it on HP-UX. + HAVE_MPROTECT is not enough, because mingw does not have mmap() but has an + mprotect() function in libgcc.a. */ +#if HAVE_SYS_MMAN_H && HAVE_MPROTECT # include # include # include @@ -31,7 +35,9 @@ # endif #endif -/* Return a pointer to a zero-size object in memory, if possible. +/* Return a pointer to a zero-size object in memory (that is, actually, a + pointer to a page boundary where the previous page is readable and writable + and the next page is neither readable not writable), if possible. Return NULL otherwise. */ static void * @@ -39,7 +45,7 @@ zerosize_ptr (void) { /* Use mmap and mprotect when they exist. Don't test HAVE_MMAP, because it is not defined on HP-UX 11 (since it does not support MAP_FIXED). */ -#if HAVE_MPROTECT +#if HAVE_SYS_MMAN_H && HAVE_MPROTECT # if HAVE_MAP_ANONYMOUS const int flags = MAP_ANONYMOUS | MAP_PRIVATE; const int fd = -1; @@ -51,11 +57,11 @@ zerosize_ptr (void) { int pagesize = getpagesize (); char *two_pages = - (char *) mmap (NULL, 2 * pagesize, PROT_READ | PROT_WRITE, - flags, fd, 0); + (char *) mmap (NULL, 2 * pagesize, PROT_READ | PROT_WRITE, + flags, fd, 0); if (two_pages != (char *)(-1) - && mprotect (two_pages + pagesize, pagesize, PROT_NONE) == 0) - return two_pages + pagesize; + && mprotect (two_pages + pagesize, pagesize, PROT_NONE) == 0) + return two_pages + pagesize; } #endif return NULL;