2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License (the "License").
2N/A * You may not use this file except in compliance with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A/*
2N/A * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
2N/A */
2N/A
2N/A#ifndef _PCONTROL_H
2N/A#define _PCONTROL_H
2N/A
2N/A/*
2N/A * Implemention-specific include file for libproc process management.
2N/A * This is not to be seen by the clients of libproc.
2N/A */
2N/A
2N/A#include <stdio.h>
2N/A#include <gelf.h>
2N/A#include <synch.h>
2N/A#include <procfs.h>
2N/A#include <rtld_db.h>
2N/A#include <libproc.h>
2N/A#include <libctf.h>
2N/A#include <limits.h>
2N/A
2N/A#ifdef __cplusplus
2N/Aextern "C" {
2N/A#endif
2N/A
2N/A#include "Putil.h"
2N/A
2N/A/*
2N/A * Definitions of the process control structures, internal to libproc.
2N/A * These may change without affecting clients of libproc.
2N/A */
2N/A
2N/A/*
2N/A * sym_tbl_t contains a primary and an (optional) auxiliary symbol table, which
2N/A * we wish to treat as a single logical symbol table. In this logical table,
2N/A * the data from the auxiliary table precedes that from the primary. Symbol
2N/A * indices start at [0], which is the first item in the auxiliary table
2N/A * if there is one. The sole purpose for this is so that we can treat the
2N/A * combination of .SUNW_ldynsym and .dynsym sections as a logically single
2N/A * entity without having to violate the public interface to libelf.
2N/A *
2N/A * Both tables must share the same string table section.
2N/A *
2N/A * The symtab_getsym() function serves as a gelf_getsym() replacement
2N/A * that is aware of the two tables and makes them look like a single table
2N/A * to the caller.
2N/A *
2N/A */
2N/Atypedef struct sym_tbl { /* symbol table */
2N/A Elf_Data *sym_data_pri; /* primary table */
2N/A Elf_Data *sym_data_aux; /* auxiliary table */
2N/A size_t sym_symn_aux; /* number of entries in auxiliary table */
2N/A size_t sym_symn; /* total number of entries in both tables */
2N/A char *sym_strs; /* ptr to strings */
2N/A size_t sym_strsz; /* size of string table */
2N/A GElf_Shdr sym_hdr_pri; /* primary symbol table section header */
2N/A GElf_Shdr sym_hdr_aux; /* auxiliary symbol table section header */
2N/A GElf_Shdr sym_strhdr; /* string table section header */
2N/A Elf *sym_elf; /* faked-up ELF handle from core file */
2N/A void *sym_elfmem; /* data for faked-up ELF handle */
2N/A uint_t *sym_byname; /* symbols sorted by name */
2N/A uint_t *sym_byaddr; /* symbols sorted by addr */
2N/A size_t sym_count; /* number of symbols in each sorted list */
2N/A} sym_tbl_t;
2N/A
2N/Atypedef struct file_info { /* symbol information for a mapped file */
2N/A plist_t file_list; /* linked list */
2N/A char file_pname[PRMAPSZ]; /* name from prmap_t */
2N/A struct map_info *file_map; /* primary (text) mapping */
2N/A int file_ref; /* references from map_info_t structures */
2N/A int file_fd; /* file descriptor for the mapped file */
2N/A int file_init; /* 0: initialization yet to be performed */
2N/A GElf_Half file_etype; /* ELF e_type from ehdr */
2N/A GElf_Half file_class; /* ELF e_ident[EI_CLASS] from ehdr */
2N/A rd_loadobj_t *file_lo; /* load object structure from rtld_db */
2N/A char *file_lname; /* load object name from rtld_db */
2N/A char *file_lbase; /* pointer to basename of file_lname */
2N/A char *file_rname; /* resolved on-disk object pathname */
2N/A char *file_rbase; /* pointer to basename of file_rname */
2N/A Elf *file_elf; /* ELF handle so we can close */
2N/A void *file_elfmem; /* data for faked-up ELF handle */
2N/A sym_tbl_t file_symtab; /* symbol table */
2N/A sym_tbl_t file_dynsym; /* dynamic symbol table */
2N/A uintptr_t file_dyn_base; /* load address for ET_DYN files */
2N/A uintptr_t file_plt_base; /* base address for PLT */
2N/A size_t file_plt_size; /* size of PLT region */
2N/A uintptr_t file_jmp_rel; /* base address of PLT relocations */
2N/A uintptr_t file_ctf_off; /* offset of CTF data in object file */
2N/A size_t file_ctf_size; /* size of CTF data in object file */
2N/A int file_ctf_dyn; /* does the CTF data reference the dynsym */
2N/A void *file_ctf_buf; /* CTF data for this file */
2N/A ctf_file_t *file_ctfp; /* CTF container for this file */
2N/A char *file_shstrs; /* section header string table */
2N/A size_t file_shstrsz; /* section header string table size */
2N/A uintptr_t *file_saddrs; /* section header addresses */
2N/A uint_t file_nsaddrs; /* number of section header addresses */
2N/A} file_info_t;
2N/A
2N/Atypedef struct map_info { /* description of an address space mapping */
2N/A prmap_t map_pmap; /* /proc description of this mapping */
2N/A file_info_t *map_file; /* pointer into list of mapped files */
2N/A off64_t map_offset; /* offset into core file (if core) */
2N/A int map_relocate; /* associated file_map needs to be relocated */
2N/A} map_info_t;
2N/A
2N/Atypedef struct lwp_info { /* per-lwp information from core file */
2N/A plist_t lwp_list; /* linked list */
2N/A lwpid_t lwp_id; /* lwp identifier */
2N/A lwpsinfo_t lwp_psinfo; /* /proc/<pid>/lwp/<lwpid>/lwpsinfo data */
2N/A lwpstatus_t lwp_status; /* /proc/<pid>/lwp/<lwpid>/lwpstatus data */
2N/A#if defined(sparc) || defined(__sparc)
2N/A gwindows_t *lwp_gwins; /* /proc/<pid>/lwp/<lwpid>/gwindows data */
2N/A prxregset_t *lwp_xregs; /* /proc/<pid>/lwp/<lwpid>/xregs data */
2N/A int64_t *lwp_asrs; /* /proc/<pid>/lwp/<lwpid>/asrs data */
2N/A int64_t *lwp_cxregs; /* /proc/<pid>/lwp/<lwpid>/cpuxregs data */
2N/A size_t lwp_cxsize; /* size of cpuxregs data */
2N/A#elif defined(__i386) || defined(__amd64)
2N/A prxregset_t *lwp_xregs; /* /proc/<pid>/lwp/<lwpid>/xregs data */
2N/A#endif
2N/A} lwp_info_t;
2N/A
2N/Atypedef struct core_info { /* information specific to core files */
2N/A char core_dmodel; /* data model for core file */
2N/A int core_errno; /* error during initialization if != 0 */
2N/A plist_t core_lwp_head; /* head of list of lwp info */
2N/A lwp_info_t *core_lwp; /* current lwp information */
2N/A uint_t core_nlwp; /* number of lwp's in list */
2N/A off64_t core_size; /* size of core file in bytes */
2N/A char *core_platform; /* platform string from core file */
2N/A struct utsname *core_uts; /* uname(2) data from core file */
2N/A prcred_t *core_cred; /* process credential from core file */
2N/A core_content_t core_content; /* content dumped to core file */
2N/A prpriv_t *core_priv; /* process privileges from core file */
2N/A size_t core_priv_size; /* size of the privileges */
2N/A void *core_privinfo; /* system privileges info from core file */
2N/A priv_impl_info_t *core_ppii; /* NOTE entry for core_privinfo */
2N/A char *core_zonename; /* zone name from core file */
2N/A#if defined(__i386) || defined(__amd64)
2N/A struct ssd *core_ldt; /* LDT entries from core file */
2N/A uint_t core_nldt; /* number of LDT entries in core file */
2N/A#endif
2N/A} core_info_t;
2N/A
2N/Atypedef struct elf_file_header { /* extended ELF header */
2N/A unsigned char e_ident[EI_NIDENT];
2N/A Elf64_Half e_type;
2N/A Elf64_Half e_machine;
2N/A Elf64_Word e_version;
2N/A Elf64_Addr e_entry;
2N/A Elf64_Off e_phoff;
2N/A Elf64_Off e_shoff;
2N/A Elf64_Word e_flags;
2N/A Elf64_Half e_ehsize;
2N/A Elf64_Half e_phentsize;
2N/A Elf64_Half e_shentsize;
2N/A Elf64_Word e_phnum; /* phdr count extended to 32 bits */
2N/A Elf64_Word e_shnum; /* shdr count extended to 32 bits */
2N/A Elf64_Word e_shstrndx; /* shdr string index extended to 32 bits */
2N/A} elf_file_header_t;
2N/A
2N/Atypedef struct elf_file { /* convenience for managing ELF files */
2N/A elf_file_header_t e_hdr; /* Extended ELF header */
2N/A Elf *e_elf; /* ELF library handle */
2N/A int e_fd; /* file descriptor */
2N/A} elf_file_t;
2N/A
2N/Atypedef struct ps_rwops { /* ops vector for Pread() and Pwrite() */
2N/A ssize_t (*p_pread)(struct ps_prochandle *,
2N/A void *, size_t, uintptr_t);
2N/A ssize_t (*p_pwrite)(struct ps_prochandle *,
2N/A const void *, size_t, uintptr_t);
2N/A} ps_rwops_t;
2N/A
2N/A#define HASHSIZE 1024 /* hash table size, power of 2 */
2N/A
2N/Astruct ps_prochandle {
2N/A struct ps_lwphandle **hashtab; /* hash table for LWPs (Lgrab()) */
2N/A mutex_t proc_lock; /* protects hash table; serializes Lgrab() */
2N/A pstatus_t orig_status; /* remembered status on Pgrab() */
2N/A pstatus_t status; /* status when stopped */
2N/A psinfo_t psinfo; /* psinfo_t from last Ppsinfo() request */
2N/A uintptr_t sysaddr; /* address of most recent syscall instruction */
2N/A pid_t pid; /* process-ID */
2N/A int state; /* state of the process, see "libproc.h" */
2N/A uint_t flags; /* see defines below */
2N/A uint_t agentcnt; /* Pcreate_agent()/Pdestroy_agent() ref count */
2N/A int asfd; /* /proc/<pid>/as filedescriptor */
2N/A int ctlfd; /* /proc/<pid>/ctl filedescriptor */
2N/A int statfd; /* /proc/<pid>/status filedescriptor */
2N/A int agentctlfd; /* /proc/<pid>/lwp/agent/ctl */
2N/A int agentstatfd; /* /proc/<pid>/lwp/agent/status */
2N/A int info_valid; /* if zero, map and file info need updating */
2N/A map_info_t *mappings; /* cached process mappings */
2N/A size_t map_count; /* number of mappings */
2N/A size_t map_alloc; /* number of mappings allocated */
2N/A uint_t num_files; /* number of file elements in file_info */
2N/A plist_t file_head; /* head of mapped files w/ symbol table info */
2N/A char *execname; /* name of the executable file */
2N/A auxv_t *auxv; /* the process's aux vector */
2N/A int nauxv; /* number of aux vector entries */
2N/A rd_agent_t *rap; /* cookie for rtld_db */
2N/A map_info_t *map_exec; /* the mapping for the executable file */
2N/A map_info_t *map_ldso; /* the mapping for ld.so.1 */
2N/A const ps_rwops_t *ops; /* pointer to ops-vector for read and write */
2N/A core_info_t *core; /* information specific to core (if PS_DEAD) */
2N/A uintptr_t *ucaddrs; /* ucontext-list addresses */
2N/A uint_t ucnelems; /* number of elements in the ucaddrs list */
2N/A char *zoneroot; /* cached path to zone root */
2N/A};
2N/A
2N/A/* flags */
2N/A#define CREATED 0x01 /* process was created by Pcreate() */
2N/A#define SETSIG 0x02 /* set signal trace mask before continuing */
2N/A#define SETFAULT 0x04 /* set fault trace mask before continuing */
2N/A#define SETENTRY 0x08 /* set sysentry trace mask before continuing */
2N/A#define SETEXIT 0x10 /* set sysexit trace mask before continuing */
2N/A#define SETHOLD 0x20 /* set signal hold mask before continuing */
2N/A#define SETREGS 0x40 /* set registers before continuing */
2N/A
2N/Astruct ps_lwphandle {
2N/A struct ps_prochandle *lwp_proc; /* process to which this lwp belongs */
2N/A struct ps_lwphandle *lwp_hash; /* hash table linked list */
2N/A lwpstatus_t lwp_status; /* status when stopped */
2N/A lwpsinfo_t lwp_psinfo; /* lwpsinfo_t from last Lpsinfo() */
2N/A lwpid_t lwp_id; /* lwp identifier */
2N/A int lwp_state; /* state of the lwp, see "libproc.h" */
2N/A uint_t lwp_flags; /* SETHOLD and/or SETREGS */
2N/A int lwp_ctlfd; /* /proc/<pid>/lwp/<lwpid>/lwpctl */
2N/A int lwp_statfd; /* /proc/<pid>/lwp/<lwpid>/lwpstatus */
2N/A};
2N/A
2N/A/*
2N/A * Implementation functions in the process control library.
2N/A * These are not exported to clients of the library.
2N/A */
2N/Aextern void prldump(const char *, lwpstatus_t *);
2N/Aextern int dupfd(int, int);
2N/Aextern int set_minfd(void);
2N/Aextern int Pscantext(struct ps_prochandle *);
2N/Aextern void Pinitsym(struct ps_prochandle *);
2N/Aextern void Preadauxvec(struct ps_prochandle *);
2N/Aextern void optimize_symtab(sym_tbl_t *);
2N/Aextern void Pbuild_file_symtab(struct ps_prochandle *, file_info_t *);
2N/Aextern ctf_file_t *Pbuild_file_ctf(struct ps_prochandle *, file_info_t *);
2N/Aextern map_info_t *Paddr2mptr(struct ps_prochandle *, uintptr_t);
2N/Aextern char *Pfindexec(struct ps_prochandle *, const char *,
2N/A int (*)(const char *, void *), void *);
2N/Aextern int getlwpstatus(struct ps_prochandle *, lwpid_t, lwpstatus_t *);
2N/Aint Pstopstatus(struct ps_prochandle *, long, uint32_t);
2N/Aextern file_info_t *file_info_new(struct ps_prochandle *, map_info_t *);
2N/Aextern char *Plofspath(const char *, char *, size_t);
2N/Aextern char *Pzoneroot(struct ps_prochandle *, char *, size_t);
2N/Aextern char *Pzonepath(struct ps_prochandle *, const char *, char *,
2N/A size_t);
2N/Aextern char *Pfindmap(struct ps_prochandle *, map_info_t *, char *,
2N/A size_t);
2N/A
2N/Aextern int Padd_mapping(struct ps_prochandle *, off64_t, file_info_t *,
2N/A prmap_t *);
2N/Aextern void Psort_mappings(struct ps_prochandle *);
2N/A
2N/Aextern char procfs_path[PATH_MAX];
2N/A
2N/A/*
2N/A * Architecture-dependent definition of the breakpoint instruction.
2N/A */
2N/A#if defined(sparc) || defined(__sparc)
2N/A#define BPT ((instr_t)0x91d02001)
2N/A#elif defined(__i386) || defined(__amd64)
2N/A#define BPT ((instr_t)0xcc)
2N/A#endif
2N/A
2N/A/*
2N/A * Simple convenience.
2N/A */
2N/A#define TRUE 1
2N/A#define FALSE 0
2N/A
2N/A#ifdef __cplusplus
2N/A}
2N/A#endif
2N/A
2N/A#endif /* _PCONTROL_H */