components/libsigsegv/patches/stackvma-procfs.c.patch
changeset 1850 fc1533d9d8d7
child 6403 9d25dbe7eb71
equal deleted inserted replaced
1849:039e7d9ae82b 1850:fc1533d9d8d7
       
     1 #
       
     2 # This patch converts libsigsegv from using the obsolete (since Solaris 2.6,
       
     3 # 1997) ioctl-based version of the /proc interface to using the structured
       
     4 # /proc interface as described in the proc(4) manual page.
       
     5 # See libsigsegv bug: https://savannah.gnu.org/bugs/?42187
       
     6 #
       
     7 diff -r -u libsigsegv-2.6/configure.orig libsigsegv-2.6/configure
       
     8 --- libsigsegv-2.6/configure.orig	2008-08-24 15:58:15.000000000 -0700
       
     9 +++ libsigsegv-2.6/configure	2014-04-10 11:02:03.212637829 -0700
       
    10 @@ -15596,8 +15596,8 @@
       
    11  _ACEOF
       
    12  
       
    13  
       
    14 -{ $as_echo "$as_me:$LINENO: checking for PIOCMAP in sys/procfs.h" >&5
       
    15 -$as_echo_n "checking for PIOCMAP in sys/procfs.h... " >&6; }
       
    16 +{ $as_echo "$as_me:$LINENO: checking for prmap_t in procfs.h" >&5
       
    17 +$as_echo_n "checking for prmap_t in procfs.h... " >&6; }
       
    18  if test "${sv_cv_procfsvma+set}" = set; then
       
    19    $as_echo_n "(cached) " >&6
       
    20  else
       
    21 @@ -15608,12 +15608,11 @@
       
    22  cat confdefs.h >>conftest.$ac_ext
       
    23  cat >>conftest.$ac_ext <<_ACEOF
       
    24  /* end confdefs.h.  */
       
    25 -#include <sys/procfs.h>
       
    26 +#include <procfs.h>
       
    27  int
       
    28  main ()
       
    29  {
       
    30 -int x = PIOCNMAP + PIOCMAP; prmap_t y;
       
    31 -  ;
       
    32 +  prmap_t y;
       
    33    return 0;
       
    34  }
       
    35  _ACEOF
       
    36 diff -r -u libsigsegv-2.6/configure.ac.orig libsigsegv-2.6/configure.ac
       
    37 --- libsigsegv-2.6/configure.ac.orig	2014-04-10 10:55:23.907673765 -0700
       
    38 +++ libsigsegv-2.6/configure.ac	2014-04-10 11:02:35.810560742 -0700
       
    39 @@ -619,9 +619,9 @@
       
    40     STACK_DIRECTION = 0 => spaghetti stack.])
       
    41  
       
    42  dnl Determination of the stack's virtual memory area.
       
    43 -AC_CACHE_CHECK([for PIOCMAP in sys/procfs.h], sv_cv_procfsvma, [
       
    44 -  AC_TRY_LINK([#include <sys/procfs.h>],
       
    45 -    [int x = PIOCNMAP + PIOCMAP; prmap_t y;],
       
    46 +AC_CACHE_CHECK([for prmap_t in procfs.h], sv_cv_procfsvma, [
       
    47 +  AC_TRY_LINK([#include <procfs.h>],
       
    48 +    [ prmap_t y;],
       
    49      sv_cv_procfsvma=yes, sv_cv_procfsvma=no)
       
    50  ])
       
    51  AC_CHECK_FUNCS([mincore])
       
    52 diff -r -u libsigsegv-2.6/src/stackvma-procfs.c.orig libsigsegv-2.6/src/stackvma-procfs.c
       
    53 --- libsigsegv-2.6/src/stackvma-procfs.c.orig	2014-04-10 11:05:58.957104341 -0700
       
    54 +++ libsigsegv-2.6/src/stackvma-procfs.c	2014-04-10 10:49:41.584900672 -0700
       
    55 @@ -19,8 +19,9 @@
       
    56  #include <unistd.h> /* open, close */
       
    57  #include <fcntl.h> /* open */
       
    58  #include <sys/types.h>
       
    59 +#include <sys/stat.h>
       
    60  #include <sys/mman.h> /* mmap, munmap */
       
    61 -#include <sys/procfs.h> /* PIOC*, prmap_t */
       
    62 +#include <procfs.h> /* prmap_t */
       
    63  
       
    64  #include "stackvma-simple.c"
       
    65  
       
    66 @@ -43,10 +44,7 @@
       
    67  int
       
    68  sigsegv_get_vma (unsigned long address, struct vma_struct *vma)
       
    69  {
       
    70 -  char fnamebuf[6+10+1];
       
    71 -  char *fname;
       
    72    int fd;
       
    73 -  int nmaps;
       
    74    size_t memneed;
       
    75  #if HAVE_MMAP_ANON
       
    76  # define zero_fd -1
       
    77 @@ -58,6 +56,7 @@
       
    78    int zero_fd;
       
    79  # define map_flags 0
       
    80  #endif
       
    81 +  struct stat statb;
       
    82    void *auxmap;
       
    83    unsigned long auxmap_start;
       
    84    unsigned long auxmap_end;
       
    85 @@ -71,26 +70,14 @@
       
    86    if (pagesize == 0)
       
    87      init_pagesize ();
       
    88  
       
    89 -  /* Construct fname = sprintf (fnamebuf+i, "/proc/%u", getpid ()).  */
       
    90 -  fname = fnamebuf + sizeof (fnamebuf) - 1;
       
    91 -  *fname = '\0';
       
    92 -  {
       
    93 -    unsigned int value = getpid ();
       
    94 -    do
       
    95 -      *--fname = (value % 10) + '0';
       
    96 -    while ((value = value / 10) > 0);
       
    97 -  }
       
    98 -  fname -= 6;
       
    99 -  memcpy (fname, "/proc/", 6);
       
   100 -
       
   101 -  fd = open (fname, O_RDONLY);
       
   102 +  fd = open ("/proc/self/map", O_RDONLY);
       
   103    if (fd < 0)
       
   104      goto failed;
       
   105  
       
   106 -  if (ioctl (fd, PIOCNMAP, &nmaps) < 0)
       
   107 +  if (fstat(fd, &statb) == -1)
       
   108      goto fail2;
       
   109  
       
   110 -  memneed = (nmaps + 10) * sizeof (prmap_t);
       
   111 +  memneed = statb.st_size + 10 * sizeof (prmap_t);
       
   112    /* Allocate memneed bytes of memory.
       
   113       We cannot use alloca here, because we are low on stack space.
       
   114       We also cannot use malloc here, because a malloc() call may have been
       
   115 @@ -112,7 +99,7 @@
       
   116    auxmap_end = auxmap_start + memneed;
       
   117    maps = (prmap_t *) auxmap;
       
   118  
       
   119 -  if (ioctl (fd, PIOCMAP, maps) < 0)
       
   120 +  if (read(fd, (void *)maps, memneed) <= 0)
       
   121      goto fail1;
       
   122  
       
   123  #if STACK_DIRECTION < 0