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


   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  *
  26  * Portions Copyright 2007 Chad Mynhier
  27  * Copyright 2012 DEY Storage Systems, Inc.  All rights reserved.
  28  * Copyright (c) 2013, Joyent, Inc. All rights reserved.

  29  */
  30 
  31 /*
  32  * Interfaces available from the process control library, libproc.
  33  *
  34  * libproc provides process control functions for the /proc tools
  35  * (commands in /usr/proc/bin), /usr/bin/truss, and /usr/bin/gcore.
  36  * libproc is a private support library for these commands only.
  37  * It is _not_ a public interface, although it might become one
  38  * in the fullness of time, when the interfaces settle down.
  39  *
  40  * In the meantime, be aware that any program linked with libproc in this
  41  * release of Solaris is almost guaranteed to break in the next release.
  42  *
  43  * In short, do not use this header file or libproc for any purpose.
  44  */
  45 
  46 #ifndef _LIBPROC_H
  47 #define _LIBPROC_H
  48 


 110 #define R_RVAL  R_RVAL1         /* simple function return value register */
 111 
 112 /* maximum sizes of things */
 113 #define PRMAXSIG        (32 * sizeof (sigset_t) / sizeof (uint32_t))
 114 #define PRMAXFAULT      (32 * sizeof (fltset_t) / sizeof (uint32_t))
 115 #define PRMAXSYS        (32 * sizeof (sysset_t) / sizeof (uint32_t))
 116 
 117 /* State values returned by Pstate() */
 118 #define PS_RUN          1       /* process is running */
 119 #define PS_STOP         2       /* process is stopped */
 120 #define PS_LOST         3       /* process is lost to control (EAGAIN) */
 121 #define PS_UNDEAD       4       /* process is terminated (zombie) */
 122 #define PS_DEAD         5       /* process is terminated (core file) */
 123 #define PS_IDLE         6       /* process has not been run */
 124 
 125 /* Flags accepted by Pgrab() */
 126 #define PGRAB_RETAIN    0x01    /* Retain tracing flags, else clear flags */
 127 #define PGRAB_FORCE     0x02    /* Open the process w/o O_EXCL */
 128 #define PGRAB_RDONLY    0x04    /* Open the process or core w/ O_RDONLY */
 129 #define PGRAB_NOSTOP    0x08    /* Open the process but do not stop it */

 130 
 131 /* Error codes from Pcreate() */
 132 #define C_STRANGE       -1      /* Unanticipated error, errno is meaningful */
 133 #define C_FORK          1       /* Unable to fork */
 134 #define C_PERM          2       /* No permission (file set-id or unreadable) */
 135 #define C_NOEXEC        3       /* Cannot execute file */
 136 #define C_INTR          4       /* Interrupt received while creating */
 137 #define C_LP64          5       /* Program is _LP64, self is _ILP32 */
 138 #define C_NOENT         6       /* Cannot find executable file */
 139 
 140 /* Error codes from Pgrab(), Pfgrab_core(), and Pgrab_core() */
 141 #define G_STRANGE       -1      /* Unanticipated error, errno is meaningful */
 142 #define G_NOPROC        1       /* No such process */
 143 #define G_NOCORE        2       /* No such core file */
 144 #define G_NOPROCORCORE  3       /* No such proc or core (for proc_arg_grab) */
 145 #define G_NOEXEC        4       /* Cannot locate executable file */
 146 #define G_ZOMB          5       /* Zombie process */
 147 #define G_PERM          6       /* No permission */
 148 #define G_BUSY          7       /* Another process has control */
 149 #define G_SYS           8       /* System process */


 171         char    arg_inout;      /* AI_INPUT, AI_OUTPUT, AI_INOUT */
 172         ushort_t arg_size;      /* if AT_BYREF, size of object in bytes */
 173 } argdes_t;
 174 
 175 /* values for type */
 176 #define AT_BYVAL        1
 177 #define AT_BYREF        2
 178 
 179 /* values for inout */
 180 #define AI_INPUT        1
 181 #define AI_OUTPUT       2
 182 #define AI_INOUT        3
 183 
 184 /* maximum number of syscall arguments */
 185 #define MAXARGS         8
 186 
 187 /* maximum size in bytes of a BYREF argument */
 188 #define MAXARGL         (4*1024)
 189 
 190 /*

















































 191  * Function prototypes for routines in the process control package.
 192  */
 193 extern struct ps_prochandle *Pcreate(const char *, char *const *,
 194     int *, char *, size_t);
 195 extern struct ps_prochandle *Pxcreate(const char *, char *const *,
 196     char *const *, int *, char *, size_t);
 197 
 198 extern const char *Pcreate_error(int);
 199 
 200 extern struct ps_prochandle *Pgrab(pid_t, int, int *);
 201 extern struct ps_prochandle *Pgrab_core(const char *, const char *, int, int *);
 202 extern struct ps_prochandle *Pfgrab_core(int, const char *, int *);
 203 extern struct ps_prochandle *Pgrab_file(const char *, int *);

 204 extern const char *Pgrab_error(int);
 205 
 206 extern  int     Preopen(struct ps_prochandle *);
 207 extern  void    Prelease(struct ps_prochandle *, int);
 208 extern  void    Pfree(struct ps_prochandle *);
 209 
 210 extern  int     Pasfd(struct ps_prochandle *);
 211 extern  char   *Pbrandname(struct ps_prochandle *, char *, size_t);
 212 extern  int     Pctlfd(struct ps_prochandle *);
 213 extern  int     Pcreate_agent(struct ps_prochandle *);
 214 extern  void    Pdestroy_agent(struct ps_prochandle *);
 215 extern  int     Pstopstatus(struct ps_prochandle *, long, uint_t);
 216 extern  int     Pwait(struct ps_prochandle *, uint_t);
 217 extern  int     Pstop(struct ps_prochandle *, uint_t);
 218 extern  int     Pdstop(struct ps_prochandle *);
 219 extern  int     Pstate(struct ps_prochandle *);
 220 extern  const psinfo_t *Ppsinfo(struct ps_prochandle *);
 221 extern  const pstatus_t *Pstatus(struct ps_prochandle *);
 222 extern  int     Pcred(struct ps_prochandle *, prcred_t *, int);
 223 extern  int     Psetcred(struct ps_prochandle *, const prcred_t *);
 224 extern  ssize_t Ppriv(struct ps_prochandle *, prpriv_t *, size_t);
 225 extern  int     Psetpriv(struct ps_prochandle *, prpriv_t *);
 226 extern  void   *Pprivinfo(struct ps_prochandle *);
 227 extern  int     Psetzoneid(struct ps_prochandle *, zoneid_t);
 228 extern  int     Pgetareg(struct ps_prochandle *, int, prgreg_t *);
 229 extern  int     Pputareg(struct ps_prochandle *, int, prgreg_t);
 230 extern  int     Psetrun(struct ps_prochandle *, int, int);
 231 extern  ssize_t Pread(struct ps_prochandle *, void *, size_t, uintptr_t);
 232 extern  ssize_t Pread_string(struct ps_prochandle *, char *, size_t, uintptr_t);
 233 extern  ssize_t Pwrite(struct ps_prochandle *, const void *, size_t, uintptr_t);
 234 extern  int     Pclearsig(struct ps_prochandle *);
 235 extern  int     Pclearfault(struct ps_prochandle *);
 236 extern  int     Psetbkpt(struct ps_prochandle *, uintptr_t, ulong_t *);
 237 extern  int     Pdelbkpt(struct ps_prochandle *, uintptr_t, ulong_t);
 238 extern  int     Pxecbkpt(struct ps_prochandle *, ulong_t);
 239 extern  int     Psetwapt(struct ps_prochandle *, const prwatch_t *);
 240 extern  int     Pdelwapt(struct ps_prochandle *, const prwatch_t *);
 241 extern  int     Pxecwapt(struct ps_prochandle *, const prwatch_t *);
 242 extern  int     Psetflags(struct ps_prochandle *, long);
 243 extern  int     Punsetflags(struct ps_prochandle *, long);
 244 extern  int     Psignal(struct ps_prochandle *, int, int);




   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  *
  26  * Portions Copyright 2007 Chad Mynhier
  27  * Copyright 2012 DEY Storage Systems, Inc.  All rights reserved.
  28  * Copyright (c) 2013, Joyent, Inc. All rights reserved.
  29  * Copyright (c) 2013 by Delphix. All rights reserved.
  30  */
  31 
  32 /*
  33  * Interfaces available from the process control library, libproc.
  34  *
  35  * libproc provides process control functions for the /proc tools
  36  * (commands in /usr/proc/bin), /usr/bin/truss, and /usr/bin/gcore.
  37  * libproc is a private support library for these commands only.
  38  * It is _not_ a public interface, although it might become one
  39  * in the fullness of time, when the interfaces settle down.
  40  *
  41  * In the meantime, be aware that any program linked with libproc in this
  42  * release of Solaris is almost guaranteed to break in the next release.
  43  *
  44  * In short, do not use this header file or libproc for any purpose.
  45  */
  46 
  47 #ifndef _LIBPROC_H
  48 #define _LIBPROC_H
  49 


 111 #define R_RVAL  R_RVAL1         /* simple function return value register */
 112 
 113 /* maximum sizes of things */
 114 #define PRMAXSIG        (32 * sizeof (sigset_t) / sizeof (uint32_t))
 115 #define PRMAXFAULT      (32 * sizeof (fltset_t) / sizeof (uint32_t))
 116 #define PRMAXSYS        (32 * sizeof (sysset_t) / sizeof (uint32_t))
 117 
 118 /* State values returned by Pstate() */
 119 #define PS_RUN          1       /* process is running */
 120 #define PS_STOP         2       /* process is stopped */
 121 #define PS_LOST         3       /* process is lost to control (EAGAIN) */
 122 #define PS_UNDEAD       4       /* process is terminated (zombie) */
 123 #define PS_DEAD         5       /* process is terminated (core file) */
 124 #define PS_IDLE         6       /* process has not been run */
 125 
 126 /* Flags accepted by Pgrab() */
 127 #define PGRAB_RETAIN    0x01    /* Retain tracing flags, else clear flags */
 128 #define PGRAB_FORCE     0x02    /* Open the process w/o O_EXCL */
 129 #define PGRAB_RDONLY    0x04    /* Open the process or core w/ O_RDONLY */
 130 #define PGRAB_NOSTOP    0x08    /* Open the process but do not stop it */
 131 #define PGRAB_INCORE    0x10    /* Use in-core data to build symbol tables */
 132 
 133 /* Error codes from Pcreate() */
 134 #define C_STRANGE       -1      /* Unanticipated error, errno is meaningful */
 135 #define C_FORK          1       /* Unable to fork */
 136 #define C_PERM          2       /* No permission (file set-id or unreadable) */
 137 #define C_NOEXEC        3       /* Cannot execute file */
 138 #define C_INTR          4       /* Interrupt received while creating */
 139 #define C_LP64          5       /* Program is _LP64, self is _ILP32 */
 140 #define C_NOENT         6       /* Cannot find executable file */
 141 
 142 /* Error codes from Pgrab(), Pfgrab_core(), and Pgrab_core() */
 143 #define G_STRANGE       -1      /* Unanticipated error, errno is meaningful */
 144 #define G_NOPROC        1       /* No such process */
 145 #define G_NOCORE        2       /* No such core file */
 146 #define G_NOPROCORCORE  3       /* No such proc or core (for proc_arg_grab) */
 147 #define G_NOEXEC        4       /* Cannot locate executable file */
 148 #define G_ZOMB          5       /* Zombie process */
 149 #define G_PERM          6       /* No permission */
 150 #define G_BUSY          7       /* Another process has control */
 151 #define G_SYS           8       /* System process */


 173         char    arg_inout;      /* AI_INPUT, AI_OUTPUT, AI_INOUT */
 174         ushort_t arg_size;      /* if AT_BYREF, size of object in bytes */
 175 } argdes_t;
 176 
 177 /* values for type */
 178 #define AT_BYVAL        1
 179 #define AT_BYREF        2
 180 
 181 /* values for inout */
 182 #define AI_INPUT        1
 183 #define AI_OUTPUT       2
 184 #define AI_INOUT        3
 185 
 186 /* maximum number of syscall arguments */
 187 #define MAXARGS         8
 188 
 189 /* maximum size in bytes of a BYREF argument */
 190 #define MAXARGL         (4*1024)
 191 
 192 /*
 193  * Ops vector definition for the Pgrab_ops().
 194  */
 195 typedef ssize_t (*pop_pread_t)(struct ps_prochandle *, void *, size_t,
 196     uintptr_t, void *);
 197 typedef ssize_t (*pop_pwrite_t)(struct ps_prochandle *, const void *, size_t,
 198     uintptr_t, void *);
 199 typedef int (*pop_read_maps_t)(struct ps_prochandle *, prmap_t **, ssize_t *,
 200     void *);
 201 typedef void (*pop_read_aux_t)(struct ps_prochandle *, auxv_t **, int *,
 202     void *);
 203 typedef int (*pop_cred_t)(struct ps_prochandle *, prcred_t *, int,
 204     void *);
 205 typedef int (*pop_priv_t)(struct ps_prochandle *, prpriv_t **, void *);
 206 typedef const psinfo_t *(*pop_psinfo_t)(struct ps_prochandle *, psinfo_t *,
 207     void *);
 208 typedef void (*pop_status_t)(struct ps_prochandle *, pstatus_t *, void *);
 209 typedef prheader_t *(*pop_lstatus_t)(struct ps_prochandle *, void *);
 210 typedef prheader_t *(*pop_lpsinfo_t)(struct ps_prochandle *, void *);
 211 typedef void (*pop_fini_t)(struct ps_prochandle *, void *);
 212 typedef char *(*pop_platform_t)(struct ps_prochandle *, char *, size_t, void *);
 213 typedef int (*pop_uname_t)(struct ps_prochandle *, struct utsname *, void *);
 214 typedef char *(*pop_zonename_t)(struct ps_prochandle *, char *, size_t, void *);
 215 typedef char *(*pop_execname_t)(struct ps_prochandle *, char *, size_t, void *);
 216 #if defined(__i386) || defined(__amd64)
 217 typedef int (*pop_ldt_t)(struct ps_prochandle *, struct ssd *, int, void *);
 218 #endif
 219 
 220 typedef struct ps_ops {
 221         pop_pread_t             pop_pread;
 222         pop_pwrite_t            pop_pwrite;
 223         pop_read_maps_t         pop_read_maps;
 224         pop_read_aux_t          pop_read_aux;
 225         pop_cred_t              pop_cred;
 226         pop_priv_t              pop_priv;
 227         pop_psinfo_t            pop_psinfo;
 228         pop_status_t            pop_status;
 229         pop_lstatus_t           pop_lstatus;
 230         pop_lpsinfo_t           pop_lpsinfo;
 231         pop_fini_t              pop_fini;
 232         pop_platform_t          pop_platform;
 233         pop_uname_t             pop_uname;
 234         pop_zonename_t          pop_zonename;
 235         pop_execname_t          pop_execname;
 236 #if defined(__i386) || defined(__amd64)
 237         pop_ldt_t               pop_ldt;
 238 #endif
 239 } ps_ops_t;
 240 
 241 /*
 242  * Function prototypes for routines in the process control package.
 243  */
 244 extern struct ps_prochandle *Pcreate(const char *, char *const *,
 245     int *, char *, size_t);
 246 extern struct ps_prochandle *Pxcreate(const char *, char *const *,
 247     char *const *, int *, char *, size_t);
 248 
 249 extern const char *Pcreate_error(int);
 250 
 251 extern struct ps_prochandle *Pgrab(pid_t, int, int *);
 252 extern struct ps_prochandle *Pgrab_core(const char *, const char *, int, int *);
 253 extern struct ps_prochandle *Pfgrab_core(int, const char *, int *);
 254 extern struct ps_prochandle *Pgrab_file(const char *, int *);
 255 extern struct ps_prochandle *Pgrab_ops(pid_t, void *, const ps_ops_t *, int);
 256 extern const char *Pgrab_error(int);
 257 
 258 extern  int     Preopen(struct ps_prochandle *);
 259 extern  void    Prelease(struct ps_prochandle *, int);
 260 extern  void    Pfree(struct ps_prochandle *);
 261 
 262 extern  int     Pasfd(struct ps_prochandle *);
 263 extern  char   *Pbrandname(struct ps_prochandle *, char *, size_t);
 264 extern  int     Pctlfd(struct ps_prochandle *);
 265 extern  int     Pcreate_agent(struct ps_prochandle *);
 266 extern  void    Pdestroy_agent(struct ps_prochandle *);
 267 extern  int     Pstopstatus(struct ps_prochandle *, long, uint_t);
 268 extern  int     Pwait(struct ps_prochandle *, uint_t);
 269 extern  int     Pstop(struct ps_prochandle *, uint_t);
 270 extern  int     Pdstop(struct ps_prochandle *);
 271 extern  int     Pstate(struct ps_prochandle *);
 272 extern  const psinfo_t *Ppsinfo(struct ps_prochandle *);
 273 extern  const pstatus_t *Pstatus(struct ps_prochandle *);
 274 extern  int     Pcred(struct ps_prochandle *, prcred_t *, int);
 275 extern  int     Psetcred(struct ps_prochandle *, const prcred_t *);
 276 extern  int     Ppriv(struct ps_prochandle *, prpriv_t **);
 277 extern  int     Psetpriv(struct ps_prochandle *, prpriv_t *);
 278 extern  void   *Pprivinfo(struct ps_prochandle *);
 279 extern  int     Psetzoneid(struct ps_prochandle *, zoneid_t);
 280 extern  int     Pgetareg(struct ps_prochandle *, int, prgreg_t *);
 281 extern  int     Pputareg(struct ps_prochandle *, int, prgreg_t);
 282 extern  int     Psetrun(struct ps_prochandle *, int, int);
 283 extern  ssize_t Pread(struct ps_prochandle *, void *, size_t, uintptr_t);
 284 extern  ssize_t Pread_string(struct ps_prochandle *, char *, size_t, uintptr_t);
 285 extern  ssize_t Pwrite(struct ps_prochandle *, const void *, size_t, uintptr_t);
 286 extern  int     Pclearsig(struct ps_prochandle *);
 287 extern  int     Pclearfault(struct ps_prochandle *);
 288 extern  int     Psetbkpt(struct ps_prochandle *, uintptr_t, ulong_t *);
 289 extern  int     Pdelbkpt(struct ps_prochandle *, uintptr_t, ulong_t);
 290 extern  int     Pxecbkpt(struct ps_prochandle *, ulong_t);
 291 extern  int     Psetwapt(struct ps_prochandle *, const prwatch_t *);
 292 extern  int     Pdelwapt(struct ps_prochandle *, const prwatch_t *);
 293 extern  int     Pxecwapt(struct ps_prochandle *, const prwatch_t *);
 294 extern  int     Psetflags(struct ps_prochandle *, long);
 295 extern  int     Punsetflags(struct ps_prochandle *, long);
 296 extern  int     Psignal(struct ps_prochandle *, int, int);