components/libsigsegv/patches/stackvma-procfs.c.patch
author Jingning Ji <jingning.ji@oracle.com>
Fri, 07 Oct 2016 17:53:08 -0700
changeset 7233 b36e8c8d93ff
parent 6403 9d25dbe7eb71
permissions -rw-r--r--
23094049 Upgrade zope-interface to 4.1.3

#
# This patch converts libsigsegv from using the obsolete (since Solaris 2.6,
# 1997) ioctl-based version of the /proc interface to using the structured
# /proc interface as described in the proc(4) manual page.
# See libsigsegv bug: https://savannah.gnu.org/bugs/?42187
#
diff -Naru libsigsegv-2.10.original/configure libsigsegv-2.10/configure
--- libsigsegv-2.10.original/configure	2011-04-03 08:50:50.000000000 -0700
+++ libsigsegv-2.10/configure	2016-05-12 19:05:26.396147574 -0700
@@ -14601,20 +14601,19 @@
 
 
 
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for PIOCMAP in sys/procfs.h" >&5
-$as_echo_n "checking for PIOCMAP in sys/procfs.h... " >&6; }
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for prmap_t in procfs.h" >&5
+$as_echo_n "checking for prmap_t in procfs.h... " >&6; }
 if ${sv_cv_procfsvma+:} false; then :
   $as_echo_n "(cached) " >&6
 else
 
   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
-#include <sys/procfs.h>
+#include <procfs.h>
 int
 main ()
 {
-int x = PIOCNMAP + PIOCMAP; prmap_t y;
-  ;
+  prmap_t y;
   return 0;
 }
 _ACEOF
diff -Naru libsigsegv-2.10.original/configure.ac libsigsegv-2.10/configure.ac
--- libsigsegv-2.10.original/configure.ac	2011-04-03 08:30:16.000000000 -0700
+++ libsigsegv-2.10/configure.ac	2016-05-12 19:08:31.848947387 -0700
@@ -648,9 +648,9 @@
 dnl Requires AC_CANONICAL_HOST.
 
 dnl Determination of the stack's virtual memory area.
-AC_CACHE_CHECK([for PIOCMAP in sys/procfs.h], [sv_cv_procfsvma], [
-  AC_TRY_LINK([#include <sys/procfs.h>],
-    [int x = PIOCNMAP + PIOCMAP; prmap_t y;],
+AC_CACHE_CHECK([for prmap_t in procfs.h], sv_cv_procfsvma, [
+  AC_TRY_LINK([#include <procfs.h>],
+    [ prmap_t y;],
     [sv_cv_procfsvma=yes], [sv_cv_procfsvma=no])
 ])
 AC_CHECK_FUNCS([mquery mincore])
diff -Naru libsigsegv-2.10.original/src/stackvma-procfs.c libsigsegv-2.10/src/stackvma-procfs.c
--- libsigsegv-2.10.original/src/stackvma-procfs.c	2009-08-16 04:10:00.000000000 -0700
+++ libsigsegv-2.10/src/stackvma-procfs.c	2016-05-12 19:11:17.173911686 -0700
@@ -20,8 +20,9 @@
 #include <fcntl.h> /* open */
 #include <string.h> /* memcpy */
 #include <sys/types.h>
+#include <sys/stat.h>
 #include <sys/mman.h> /* mmap, munmap */
-#include <sys/procfs.h> /* PIOC*, prmap_t */
+#include <procfs.h> /* prmap_t */
 
 #include "stackvma-simple.c"
 
@@ -44,10 +45,7 @@
 int
 sigsegv_get_vma (unsigned long address, struct vma_struct *vma)
 {
-  char fnamebuf[6+10+1];
-  char *fname;
   int fd;
-  int nmaps;
   size_t memneed;
 #if HAVE_MMAP_ANON
 # define zero_fd -1
@@ -59,6 +57,7 @@
   int zero_fd;
 # define map_flags 0
 #endif
+  struct stat statb;
   void *auxmap;
   unsigned long auxmap_start;
   unsigned long auxmap_end;
@@ -72,26 +71,14 @@
   if (pagesize == 0)
     init_pagesize ();
 
-  /* Construct fname = sprintf (fnamebuf+i, "/proc/%u", getpid ()).  */
-  fname = fnamebuf + sizeof (fnamebuf) - 1;
-  *fname = '\0';
-  {
-    unsigned int value = getpid ();
-    do
-      *--fname = (value % 10) + '0';
-    while ((value = value / 10) > 0);
-  }
-  fname -= 6;
-  memcpy (fname, "/proc/", 6);
-
-  fd = open (fname, O_RDONLY);
+  fd = open ("/proc/self/map", O_RDONLY);
   if (fd < 0)
     goto failed;
 
-  if (ioctl (fd, PIOCNMAP, &nmaps) < 0)
+  if (fstat(fd, &statb) == -1)
     goto fail2;
 
-  memneed = (nmaps + 10) * sizeof (prmap_t);
+  memneed = statb.st_size + 10 * sizeof (prmap_t);
   /* Allocate memneed bytes of memory.
      We cannot use alloca here, because we are low on stack space.
      We also cannot use malloc here, because a malloc() call may have been
@@ -113,7 +100,7 @@
   auxmap_end = auxmap_start + memneed;
   maps = (prmap_t *) auxmap;
 
-  if (ioctl (fd, PIOCMAP, maps) < 0)
+  if (read(fd, (void *)maps, memneed) <= 0)
     goto fail1;
 
 #if STACK_DIRECTION < 0