Print this page
3946 ::gcore
Reviewed by: Adam Leventhal <ahl@delphix.com>
Reviewed by: Matthew Ahrens <mahrens@delphix.com>

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libproc/common/Pidle.c
          +++ new/usr/src/lib/libproc/common/Pidle.c
↓ open down ↓ 14 lines elided ↑ open up ↑
  15   15   * If applicable, add the following below this CDDL HEADER, with the
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  /*
  22   22   * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  23   23   * Use is subject to license terms.
  24   24   */
       25 +/*
       26 + * Copyright (c) 2013 by Delphix. All rights reserved.
       27 + */
  25   28  
  26   29  #include <stdlib.h>
  27   30  #include <libelf.h>
  28   31  #include <libgen.h>
  29   32  #include <string.h>
  30   33  #include <strings.h>
  31   34  #include <errno.h>
  32   35  #include <sys/sysmacros.h>
  33   36  
  34   37  #include "libproc.h"
  35   38  #include "Pcontrol.h"
  36   39  
       40 +/*ARGSUSED*/
  37   41  static ssize_t
  38      -Pread_idle(struct ps_prochandle *P, void *buf, size_t n, uintptr_t addr)
       42 +Pread_idle(struct ps_prochandle *P, void *buf, size_t n, uintptr_t addr,
       43 +    void *data)
  39   44  {
  40   45          size_t resid = n;
  41   46  
  42   47          while (resid > 0) {
  43   48                  map_info_t *mp;
  44   49                  uintptr_t mapoff;
  45   50                  ssize_t len;
  46   51                  off64_t off;
  47   52  
  48   53                  if ((mp = Paddr2mptr(P, addr)) == NULL)
↓ open down ↓ 9 lines elided ↑ open up ↑
  58   63                  resid -= len;
  59   64                  addr += len;
  60   65                  buf = (char *)buf + len;
  61   66          }
  62   67  
  63   68          return (n - resid);
  64   69  }
  65   70  
  66   71  /*ARGSUSED*/
  67   72  static ssize_t
  68      -Pwrite_idle(struct ps_prochandle *P, const void *buf, size_t n, uintptr_t addr)
       73 +Pwrite_idle(struct ps_prochandle *P, const void *buf, size_t n, uintptr_t addr,
       74 +    void *data)
  69   75  {
  70   76          errno = EIO;
  71   77          return (-1);
  72   78  }
  73   79  
  74      -static const ps_rwops_t P_idle_ops = {
  75      -        Pread_idle,
  76      -        Pwrite_idle
       80 +/*ARGSUSED*/
       81 +static int
       82 +Ppriv_idle(struct ps_prochandle *P, prpriv_t **pprv, void *data)
       83 +{
       84 +        prpriv_t *pp;
       85 +
       86 +        pp = proc_get_priv(P->pid);
       87 +        if (pp == NULL) {
       88 +                return (-1);
       89 +        }
       90 +
       91 +        *pprv = pp;
       92 +        return (0);
       93 +}
       94 +
       95 +/* Default operations for the idl ops vector. */
       96 +static void *
       97 +Pidle_voidp()
       98 +{
       99 +        errno = ENODATA;
      100 +        return (NULL);
      101 +}
      102 +
      103 +static int
      104 +Pidle_int()
      105 +{
      106 +        errno = ENODATA;
      107 +        return (-1);
      108 +}
      109 +
      110 +static const ps_ops_t P_idle_ops = {
      111 +        .pop_pread      = Pread_idle,
      112 +        .pop_pwrite     = Pwrite_idle,
      113 +        .pop_cred       = (pop_cred_t)Pidle_int,
      114 +        .pop_priv       = Ppriv_idle,
      115 +        .pop_psinfo     = (pop_psinfo_t)Pidle_voidp,
      116 +        .pop_platform   = (pop_platform_t)Pidle_voidp,
      117 +        .pop_uname      = (pop_uname_t)Pidle_int,
      118 +        .pop_zonename   = (pop_zonename_t)Pidle_voidp,
      119 +#if defined(__i386) || defined(__amd64)
      120 +        .pop_ldt        = (pop_ldt_t)Pidle_int
      121 +#endif
  77  122  };
  78  123  
  79  124  static int
  80  125  idle_add_mapping(struct ps_prochandle *P, GElf_Phdr *php, file_info_t *fp)
  81  126  {
  82  127          prmap_t pmap;
  83  128  
  84  129          dprintf("mapping base %llx filesz %llu memsz %llu offset %llu\n",
  85  130              (u_longlong_t)php->p_vaddr, (u_longlong_t)php->p_filesz,
  86  131              (u_longlong_t)php->p_memsz, (u_longlong_t)php->p_offset);
↓ open down ↓ 49 lines elided ↑ open up ↑
 136  181  
 137  182          (void) mutex_init(&P->proc_lock, USYNC_THREAD, NULL);
 138  183          P->state = PS_IDLE;
 139  184          P->pid = (pid_t)-1;
 140  185          P->asfd = fd;
 141  186          P->ctlfd = -1;
 142  187          P->statfd = -1;
 143  188          P->agentctlfd = -1;
 144  189          P->agentstatfd = -1;
 145  190          P->info_valid = -1;
 146      -        P->ops = &P_idle_ops;
      191 +        Pinit_ops(&P->ops, &P_idle_ops);
 147  192          Pinitsym(P);
 148  193  
 149  194          if ((elf = elf_begin(fd, ELF_C_READ, NULL)) == NULL) {
 150  195                  *perr = G_ELF;
 151  196                  return (NULL);
 152  197          }
 153  198  
 154  199          /*
 155  200           * Construct a file_info_t that corresponds to this file.
 156  201           */
↓ open down ↓ 127 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX