summaryrefslogtreecommitdiffstats
path: root/gl/m4/memchr.m4
diff options
context:
space:
mode:
Diffstat (limited to 'gl/m4/memchr.m4')
-rw-r--r--gl/m4/memchr.m436
1 files changed, 13 insertions, 23 deletions
diff --git a/gl/m4/memchr.m4 b/gl/m4/memchr.m4
index 346a2882..c5c74682 100644
--- a/gl/m4/memchr.m4
+++ b/gl/m4/memchr.m4
@@ -1,9 +1,10 @@
1# memchr.m4 1# memchr.m4
2# serial 19 2# serial 21
3dnl Copyright (C) 2002-2004, 2009-2024 Free Software Foundation, Inc. 3dnl Copyright (C) 2002-2004, 2009-2026 Free Software Foundation, Inc.
4dnl This file is free software; the Free Software Foundation 4dnl This file is free software; the Free Software Foundation
5dnl gives unlimited permission to copy and/or distribute it, 5dnl gives unlimited permission to copy and/or distribute it,
6dnl with or without modifications, as long as this notice is preserved. 6dnl with or without modifications, as long as this notice is preserved.
7dnl This file is offered as-is, without any warranty.
7 8
8AC_DEFUN_ONCE([gl_FUNC_MEMCHR], 9AC_DEFUN_ONCE([gl_FUNC_MEMCHR],
9[ 10[
@@ -20,7 +21,7 @@ AC_DEFUN_ONCE([gl_FUNC_MEMCHR],
20 # https://bugzilla.redhat.com/show_bug.cgi?id=499689 21 # https://bugzilla.redhat.com/show_bug.cgi?id=499689
21 # memchr should not dereference overestimated length after a match 22 # memchr should not dereference overestimated length after a match
22 # https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=521737 23 # https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=521737
23 # https://sourceware.org/bugzilla/show_bug.cgi?id=10162 24 # https://sourceware.org/PR10162
24 # memchr should cast the second argument to 'unsigned char'. 25 # memchr should cast the second argument to 'unsigned char'.
25 # This bug exists in Android 4.3. 26 # This bug exists in Android 4.3.
26 # Assume that memchr works on platforms that lack mprotect. 27 # Assume that memchr works on platforms that lack mprotect.
@@ -32,31 +33,20 @@ AC_DEFUN_ONCE([gl_FUNC_MEMCHR],
32# include <unistd.h> 33# include <unistd.h>
33# include <sys/types.h> 34# include <sys/types.h>
34# include <sys/mman.h> 35# include <sys/mman.h>
35# ifndef MAP_FILE
36# define MAP_FILE 0
37# endif
38#endif 36#endif
39]], [[ 37]], [[
40 int result = 0; 38 int result = 0;
41 char *fence = NULL; 39 char *fence = NULL;
42#if HAVE_SYS_MMAN_H && HAVE_MPROTECT 40#if HAVE_SYS_MMAN_H && HAVE_MPROTECT
43# if HAVE_MAP_ANONYMOUS 41 {
44 const int flags = MAP_ANONYMOUS | MAP_PRIVATE; 42 long int pagesize = sysconf (_SC_PAGESIZE);
45 const int fd = -1; 43 char *two_pages =
46# else /* !HAVE_MAP_ANONYMOUS */ 44 (char *) mmap (NULL, 2 * pagesize, PROT_READ | PROT_WRITE,
47 const int flags = MAP_FILE | MAP_PRIVATE; 45 MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
48 int fd = open ("/dev/zero", O_RDONLY, 0666); 46 if (two_pages != (char *)(-1)
49 if (fd >= 0) 47 && mprotect (two_pages + pagesize, pagesize, PROT_NONE) == 0)
50# endif 48 fence = two_pages + pagesize;
51 { 49 }
52 int pagesize = getpagesize ();
53 char *two_pages =
54 (char *) mmap (NULL, 2 * pagesize, PROT_READ | PROT_WRITE,
55 flags, fd, 0);
56 if (two_pages != (char *)(-1)
57 && mprotect (two_pages + pagesize, pagesize, PROT_NONE) == 0)
58 fence = two_pages + pagesize;
59 }
60#endif 50#endif
61 if (fence) 51 if (fence)
62 { 52 {