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


   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   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  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  */
  25 /*
  26  * Copyright 2012 DEY Storage Systems, Inc.  All rights reserved.
  27  * Copyright (c) 2013, Joyent, Inc. All rights reserved.

  28  */
  29 
  30 #ifndef _PCONTROL_H
  31 #define _PCONTROL_H
  32 
  33 /*
  34  * Implemention-specific include file for libproc process management.
  35  * This is not to be seen by the clients of libproc.
  36  */
  37 
  38 #include <stdio.h>
  39 #include <gelf.h>
  40 #include <synch.h>
  41 #include <procfs.h>
  42 #include <rtld_db.h>
  43 #include <libproc.h>
  44 #include <libctf.h>
  45 #include <limits.h>

  46 
  47 #ifdef  __cplusplus
  48 extern "C" {
  49 #endif
  50 
  51 #include "Putil.h"
  52 
  53 /*
  54  * Definitions of the process control structures, internal to libproc.
  55  * These may change without affecting clients of libproc.
  56  */
  57 
  58 /*
  59  * sym_tbl_t contains a primary and an (optional) auxiliary symbol table, which
  60  * we wish to treat as a single logical symbol table. In this logical table,
  61  * the data from the auxiliary table preceeds that from the primary. Symbol
  62  * indices start at [0], which is the first item in the auxiliary table
  63  * if there is one. The sole purpose for this is so that we can treat the
  64  * combination of .SUNW_ldynsym and .dynsym sections as a logically single
  65  * entity without having to violate the public interface to libelf.


 173         Elf64_Half e_machine;
 174         Elf64_Word e_version;
 175         Elf64_Addr e_entry;
 176         Elf64_Off e_phoff;
 177         Elf64_Off e_shoff;
 178         Elf64_Word e_flags;
 179         Elf64_Half e_ehsize;
 180         Elf64_Half e_phentsize;
 181         Elf64_Half e_shentsize;
 182         Elf64_Word e_phnum;     /* phdr count extended to 32 bits */
 183         Elf64_Word e_shnum;     /* shdr count extended to 32 bits */
 184         Elf64_Word e_shstrndx;  /* shdr string index extended to 32 bits */
 185 } elf_file_header_t;
 186 
 187 typedef struct elf_file {       /* convenience for managing ELF files */
 188         elf_file_header_t e_hdr; /* Extended ELF header */
 189         Elf *e_elf;             /* ELF library handle */
 190         int e_fd;               /* file descriptor */
 191 } elf_file_t;
 192 
 193 typedef struct ps_rwops {       /* ops vector for Pread() and Pwrite() */
 194         ssize_t (*p_pread)(struct ps_prochandle *,
 195             void *, size_t, uintptr_t);
 196         ssize_t (*p_pwrite)(struct ps_prochandle *,
 197             const void *, size_t, uintptr_t);
 198 } ps_rwops_t;
 199 
 200 #define HASHSIZE                1024    /* hash table size, power of 2 */
 201 
 202 struct ps_prochandle {
 203         struct ps_lwphandle **hashtab;  /* hash table for LWPs (Lgrab()) */
 204         mutex_t proc_lock;      /* protects hash table; serializes Lgrab() */
 205         pstatus_t orig_status;  /* remembered status on Pgrab() */
 206         pstatus_t status;       /* status when stopped */
 207         psinfo_t psinfo;        /* psinfo_t from last Ppsinfo() request */
 208         uintptr_t sysaddr;      /* address of most recent syscall instruction */
 209         pid_t   pid;            /* process-ID */
 210         int     state;          /* state of the process, see "libproc.h" */
 211         uint_t  flags;          /* see defines below */
 212         uint_t  agentcnt;       /* Pcreate_agent()/Pdestroy_agent() ref count */
 213         int     asfd;           /* /proc/<pid>/as filedescriptor */
 214         int     ctlfd;          /* /proc/<pid>/ctl filedescriptor */
 215         int     statfd;         /* /proc/<pid>/status filedescriptor */
 216         int     agentctlfd;     /* /proc/<pid>/lwp/agent/ctl */
 217         int     agentstatfd;    /* /proc/<pid>/lwp/agent/status */
 218         int     info_valid;     /* if zero, map and file info need updating */
 219         map_info_t *mappings;   /* cached process mappings */
 220         size_t  map_count;      /* number of mappings */
 221         size_t  map_alloc;      /* number of mappings allocated */
 222         uint_t  num_files;      /* number of file elements in file_info */
 223         plist_t file_head;      /* head of mapped files w/ symbol table info */
 224         char    *execname;      /* name of the executable file */
 225         auxv_t  *auxv;          /* the process's aux vector */
 226         int     nauxv;          /* number of aux vector entries */
 227         rd_agent_t *rap;        /* cookie for rtld_db */
 228         map_info_t *map_exec;   /* the mapping for the executable file */
 229         map_info_t *map_ldso;   /* the mapping for ld.so.1 */
 230         const ps_rwops_t *ops;  /* pointer to ops-vector for read and write */
 231         core_info_t *core;      /* information specific to core (if PS_DEAD) */
 232         uintptr_t *ucaddrs;     /* ucontext-list addresses */
 233         uint_t  ucnelems;       /* number of elements in the ucaddrs list */
 234         char    *zoneroot;      /* cached path to zone root */
 235         plist_t fd_head;        /* head of file desc info list */
 236         int     num_fd;         /* number of file descs in list */
 237         uintptr_t map_missing;  /* first missing mapping in core due to sig */
 238         siginfo_t killinfo;     /* signal that interrupted core dump */
 239         psinfo_t spymaster;     /* agent LWP's spymaster, if any */

 240 };
 241 
 242 /* flags */
 243 #define CREATED         0x01    /* process was created by Pcreate() */
 244 #define SETSIG          0x02    /* set signal trace mask before continuing */
 245 #define SETFAULT        0x04    /* set fault trace mask before continuing */
 246 #define SETENTRY        0x08    /* set sysentry trace mask before continuing */
 247 #define SETEXIT         0x10    /* set sysexit trace mask before continuing */
 248 #define SETHOLD         0x20    /* set signal hold mask before continuing */
 249 #define SETREGS         0x40    /* set registers before continuing */

 250 
 251 struct ps_lwphandle {
 252         struct ps_prochandle *lwp_proc; /* process to which this lwp belongs */
 253         struct ps_lwphandle *lwp_hash;  /* hash table linked list */
 254         lwpstatus_t     lwp_status;     /* status when stopped */
 255         lwpsinfo_t      lwp_psinfo;     /* lwpsinfo_t from last Lpsinfo() */
 256         lwpid_t         lwp_id;         /* lwp identifier */
 257         int             lwp_state;      /* state of the lwp, see "libproc.h" */
 258         uint_t          lwp_flags;      /* SETHOLD and/or SETREGS */
 259         int             lwp_ctlfd;      /* /proc/<pid>/lwp/<lwpid>/lwpctl */
 260         int             lwp_statfd;     /* /proc/<pid>/lwp/<lwpid>/lwpstatus */
 261 };
 262 
 263 /*
 264  * Implementation functions in the process control library.
 265  * These are not exported to clients of the library.
 266  */
 267 extern  void    prldump(const char *, lwpstatus_t *);
 268 extern  int     dupfd(int, int);
 269 extern  int     set_minfd(void);




   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   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  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  */
  25 /*
  26  * Copyright 2012 DEY Storage Systems, Inc.  All rights reserved.
  27  * Copyright (c) 2013, Joyent, Inc. All rights reserved.
  28  * Copyright (c) 2013 by Delphix. All rights reserved.
  29  */
  30 
  31 #ifndef _PCONTROL_H
  32 #define _PCONTROL_H
  33 
  34 /*
  35  * Implemention-specific include file for libproc process management.
  36  * This is not to be seen by the clients of libproc.
  37  */
  38 
  39 #include <stdio.h>
  40 #include <gelf.h>
  41 #include <synch.h>
  42 #include <procfs.h>
  43 #include <rtld_db.h>
  44 #include <libproc.h>
  45 #include <libctf.h>
  46 #include <limits.h>
  47 #include <libproc.h>
  48 
  49 #ifdef  __cplusplus
  50 extern "C" {
  51 #endif
  52 
  53 #include "Putil.h"
  54 
  55 /*
  56  * Definitions of the process control structures, internal to libproc.
  57  * These may change without affecting clients of libproc.
  58  */
  59 
  60 /*
  61  * sym_tbl_t contains a primary and an (optional) auxiliary symbol table, which
  62  * we wish to treat as a single logical symbol table. In this logical table,
  63  * the data from the auxiliary table preceeds that from the primary. Symbol
  64  * indices start at [0], which is the first item in the auxiliary table
  65  * if there is one. The sole purpose for this is so that we can treat the
  66  * combination of .SUNW_ldynsym and .dynsym sections as a logically single
  67  * entity without having to violate the public interface to libelf.


 175         Elf64_Half e_machine;
 176         Elf64_Word e_version;
 177         Elf64_Addr e_entry;
 178         Elf64_Off e_phoff;
 179         Elf64_Off e_shoff;
 180         Elf64_Word e_flags;
 181         Elf64_Half e_ehsize;
 182         Elf64_Half e_phentsize;
 183         Elf64_Half e_shentsize;
 184         Elf64_Word e_phnum;     /* phdr count extended to 32 bits */
 185         Elf64_Word e_shnum;     /* shdr count extended to 32 bits */
 186         Elf64_Word e_shstrndx;  /* shdr string index extended to 32 bits */
 187 } elf_file_header_t;
 188 
 189 typedef struct elf_file {       /* convenience for managing ELF files */
 190         elf_file_header_t e_hdr; /* Extended ELF header */
 191         Elf *e_elf;             /* ELF library handle */
 192         int e_fd;               /* file descriptor */
 193 } elf_file_t;
 194 







 195 #define HASHSIZE                1024    /* hash table size, power of 2 */
 196 
 197 struct ps_prochandle {
 198         struct ps_lwphandle **hashtab;  /* hash table for LWPs (Lgrab()) */
 199         mutex_t proc_lock;      /* protects hash table; serializes Lgrab() */
 200         pstatus_t orig_status;  /* remembered status on Pgrab() */
 201         pstatus_t status;       /* status when stopped */
 202         psinfo_t psinfo;        /* psinfo_t from last Ppsinfo() request */
 203         uintptr_t sysaddr;      /* address of most recent syscall instruction */
 204         pid_t   pid;            /* process-ID */
 205         int     state;          /* state of the process, see "libproc.h" */
 206         uint_t  flags;          /* see defines below */
 207         uint_t  agentcnt;       /* Pcreate_agent()/Pdestroy_agent() ref count */
 208         int     asfd;           /* /proc/<pid>/as filedescriptor */
 209         int     ctlfd;          /* /proc/<pid>/ctl filedescriptor */
 210         int     statfd;         /* /proc/<pid>/status filedescriptor */
 211         int     agentctlfd;     /* /proc/<pid>/lwp/agent/ctl */
 212         int     agentstatfd;    /* /proc/<pid>/lwp/agent/status */
 213         int     info_valid;     /* if zero, map and file info need updating */
 214         map_info_t *mappings;   /* cached process mappings */
 215         size_t  map_count;      /* number of mappings */
 216         size_t  map_alloc;      /* number of mappings allocated */
 217         uint_t  num_files;      /* number of file elements in file_info */
 218         plist_t file_head;      /* head of mapped files w/ symbol table info */
 219         char    *execname;      /* name of the executable file */
 220         auxv_t  *auxv;          /* the process's aux vector */
 221         int     nauxv;          /* number of aux vector entries */
 222         rd_agent_t *rap;        /* cookie for rtld_db */
 223         map_info_t *map_exec;   /* the mapping for the executable file */
 224         map_info_t *map_ldso;   /* the mapping for ld.so.1 */
 225         ps_ops_t ops;           /* ops-vector */

 226         uintptr_t *ucaddrs;     /* ucontext-list addresses */
 227         uint_t  ucnelems;       /* number of elements in the ucaddrs list */
 228         char    *zoneroot;      /* cached path to zone root */
 229         plist_t fd_head;        /* head of file desc info list */
 230         int     num_fd;         /* number of file descs in list */
 231         uintptr_t map_missing;  /* first missing mapping in core due to sig */
 232         siginfo_t killinfo;     /* signal that interrupted core dump */
 233         psinfo_t spymaster;     /* agent LWP's spymaster, if any */
 234         void *data;             /* private data */
 235 };
 236 
 237 /* flags */
 238 #define CREATED         0x01    /* process was created by Pcreate() */
 239 #define SETSIG          0x02    /* set signal trace mask before continuing */
 240 #define SETFAULT        0x04    /* set fault trace mask before continuing */
 241 #define SETENTRY        0x08    /* set sysentry trace mask before continuing */
 242 #define SETEXIT         0x10    /* set sysexit trace mask before continuing */
 243 #define SETHOLD         0x20    /* set signal hold mask before continuing */
 244 #define SETREGS         0x40    /* set registers before continuing */
 245 #define INCORE          0x80    /* use in-core data to build symbol tables */
 246 
 247 struct ps_lwphandle {
 248         struct ps_prochandle *lwp_proc; /* process to which this lwp belongs */
 249         struct ps_lwphandle *lwp_hash;  /* hash table linked list */
 250         lwpstatus_t     lwp_status;     /* status when stopped */
 251         lwpsinfo_t      lwp_psinfo;     /* lwpsinfo_t from last Lpsinfo() */
 252         lwpid_t         lwp_id;         /* lwp identifier */
 253         int             lwp_state;      /* state of the lwp, see "libproc.h" */
 254         uint_t          lwp_flags;      /* SETHOLD and/or SETREGS */
 255         int             lwp_ctlfd;      /* /proc/<pid>/lwp/<lwpid>/lwpctl */
 256         int             lwp_statfd;     /* /proc/<pid>/lwp/<lwpid>/lwpstatus */
 257 };
 258 
 259 /*
 260  * Implementation functions in the process control library.
 261  * These are not exported to clients of the library.
 262  */
 263 extern  void    prldump(const char *, lwpstatus_t *);
 264 extern  int     dupfd(int, int);
 265 extern  int     set_minfd(void);