llib-lproc revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/* LINTLIBRARY */
/* PROTOLIB1 */
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include "libproc.h"
/*
* usr/src/lib/libproc
*/
/* Pcontrol.c */
int _libproc_debug;
struct ps_prochandle *Pcreate(const char *file, char *const *argv,
int *perr, char *path, size_t len);
const char *Pcreate_error(int error);
void Pcreate_callback(struct ps_prochandle *Pr);
struct ps_prochandle *Pgrab(pid_t pid, int gflag, int *perr);
const char *Pgrab_error(int error);
void Pfree(struct ps_prochandle *Pr);
int Pstate(struct ps_prochandle *Pr);
int Pasfd(struct ps_prochandle *Pr);
int Pctlfd(struct ps_prochandle *Pr);
const psinfo_t *Ppsinfo(struct ps_prochandle *Pr);
const pstatus_t *Pstatus(struct ps_prochandle *Pr);
int Pcred(struct ps_prochandle *Pr, prcred_t *pcrp, int ngroups);
ssize_t Ppriv(struct ps_prochandle *Pr, prpriv_t *pprivp, size_t);
void Psync(struct ps_prochandle *Pr);
int Pcreate_agent(struct ps_prochandle *Pr);
void Pdestroy_agent(struct ps_prochandle *Pr);
int Preopen(struct ps_prochandle *Pr);
void Prelease(struct ps_prochandle *Pr, int flags);
int Pstopstatus(struct ps_prochandle *Pr, long cmd, uint_t msec);
int Pwait(struct ps_prochandle *Pr, uint_t msec);
int Pstop(struct ps_prochandle *Pr, uint_t msec);
int Pdstop(struct ps_prochandle *Pr);
int Pgetareg(struct ps_prochandle *Pr, int regno, prgreg_t *preg);
int Pputareg(struct ps_prochandle *Pr, int regno, prgreg_t reg);
int Psetrun(struct ps_prochandle *Pr, int sig, int flags);
ssize_t Pread(struct ps_prochandle *Pr,
void *buf, size_t nbyte, uintptr_t address);
ssize_t Pread_string(struct ps_prochandle *Pr,
char *buf, size_t nbyte, uintptr_t address);
ssize_t Pwrite(struct ps_prochandle *Pr,
const void *buf, size_t nbyte, uintptr_t address);
int Pclearsig(struct ps_prochandle *Pr);
int Pclearfault(struct ps_prochandle *Pr);
int Psetbkpt(struct ps_prochandle *Pr, uintptr_t address, ulong_t *saved);
int Pdelbkpt(struct ps_prochandle *Pr, uintptr_t address, ulong_t saved);
int Pxecbkpt(struct ps_prochandle *Pr, ulong_t saved);
int Psetwapt(struct ps_prochandle *Pr, const prwatch_t *wp);
int Pdelwapt(struct ps_prochandle *Pr, const prwatch_t *wp);
int Pxecwapt(struct ps_prochandle *Pr, const prwatch_t *wp);
int Psetflags(struct ps_prochandle *Pr, long flags);
int Punsetflags(struct ps_prochandle *Pr, long flags);
int Psignal(struct ps_prochandle *Pr, int which, int stop);
void Psetsignal(struct ps_prochandle *Pr, const sigset_t *set);
int Pfault(struct ps_prochandle *Pr, int which, int stop);
void Psetfault(struct ps_prochandle *Pr, const fltset_t *set);
int Psysentry(struct ps_prochandle *Pr, int which, int stop);
void Psetsysentry(struct ps_prochandle *Pr, const sysset_t *set);
int Psysexit(struct ps_prochandle *Pr, int which, int stop);
void Psetsysexit(struct ps_prochandle *Pr, const sysset_t *set);
int Plwp_iter(struct ps_prochandle *Pr, proc_lwp_f *func, void *cd);
int Psyscall(struct ps_prochandle *Pr, sysret_t *,
int sysindex, uint_t nargs, argdes_t *argp);
struct ps_lwphandle *Lgrab(struct ps_prochandle *P, lwpid_t lwpid, int *perr);
const char *Lgrab_error(int error);
struct ps_prochandle *Lprochandle(struct ps_lwphandle *Lwp);
void Lfree(struct ps_lwphandle *Lwp);
int Lctlfd(struct ps_lwphandle *Lwp);
int Lwait(struct ps_lwphandle *Lwp, uint_t msec);
int Lstop(struct ps_lwphandle *Lwp, uint_t msec);
int Ldstop(struct ps_lwphandle *Lwp);
int Lstate(struct ps_lwphandle *Lwp);
const lwpsinfo_t *Lpsinfo(struct ps_lwphandle *Lwp);
const lwpstatus_t *Lstatus(struct ps_lwphandle *Lwp);
int Lgetareg(struct ps_lwphandle *Lwp, int regno, prgreg_t *preg);
int Lputareg(struct ps_lwphandle *Lwp, int regno, prgreg_t reg);
int Lsetrun(struct ps_lwphandle *Lwp, int sig, int flags);
int Lclearsig(struct ps_lwphandle *Lwp);
int Lclearfault(struct ps_lwphandle *Lwp);
int Lxecbkpt(struct ps_lwphandle *Lwp, ulong_t saved);
int Lxecwapt(struct ps_lwphandle *Lwp, const prwatch_t *wp);
void Lsync(struct ps_lwphandle *Lwp);
/* Plwpregs.c */
int Plwp_getregs(struct ps_prochandle *Pr, lwpid_t i, prgregset_t gr);
int Plwp_setregs(struct ps_prochandle *Pr, lwpid_t i, const prgregset_t gr);
int Plwp_getfpregs(struct ps_prochandle *Pr, lwpid_t i, prfpregset_t *fp);
int Plwp_setfpregs(struct ps_prochandle *Pr, lwpid_t i, const prfpregset_t *fp);
#if defined(sparc) || defined(__sparc)
int Plwp_getxregs(struct ps_prochandle *Pr, lwpid_t i, prxregset_t *xr);
int Plwp_setxregs(struct ps_prochandle *Pr, lwpid_t i, const prxregset_t *xr);
#if defined(__sparcv9)
int Plwp_getasrs(struct ps_prochandle *Pr, lwpid_t i, asrset_t asrs);
int Plwp_setasrs(struct ps_prochandle *Pr, lwpid_t i, const asrset_t asrs);
#endif /* __sparcv9 */
#endif /* __sparc */
int Plwp_getpsinfo(struct ps_prochandle *Pr, lwpid_t i, lwpsinfo_t *lps);
/* Pcore.c */
struct ps_prochandle *Pfgrab_core(int fd, const char *aout, int *perr);
struct ps_prochandle *Pgrab_core(const char *core, const char *aout,
int gflag, int *perr);
/* Pisprocdir.c */
int Pisprocdir(struct ps_prochandle *Pr, const char *dir);
/* Pservice.c */
ps_err_e ps_pdmodel(struct ps_prochandle *Pr, int *modelp);
ps_err_e ps_pread(struct ps_prochandle *Pr,
psaddr_t addr, void *buf, size_t size);
ps_err_e ps_pwrite(struct ps_prochandle *Pr,
psaddr_t addr, const void *buf, size_t size);
ps_err_e ps_pdread(struct ps_prochandle *Pr,
psaddr_t addr, void *buf, size_t size);
ps_err_e ps_pdwrite(struct ps_prochandle *Pr,
psaddr_t addr, const void *buf, size_t size);
ps_err_e ps_ptread(struct ps_prochandle *Pr,
psaddr_t addr, void *buf, size_t size);
ps_err_e ps_ptwrite(struct ps_prochandle *Pr,
psaddr_t addr, const void *buf, size_t size);
ps_err_e ps_pstop(struct ps_prochandle *Pr);
ps_err_e ps_pcontinue(struct ps_prochandle *Pr);
ps_err_e ps_lstop(struct ps_prochandle *Pr, lwpid_t lwpid);
ps_err_e ps_lcontinue(struct ps_prochandle *Pr, lwpid_t lwpid);
ps_err_e ps_lgetregs(struct ps_prochandle *Pr,
lwpid_t lwpid, prgregset_t regs);
ps_err_e ps_lsetregs(struct ps_prochandle *Pr,
lwpid_t lwpid, const prgregset_t regs);
ps_err_e ps_lgetfpregs(struct ps_prochandle *Pr,
lwpid_t lwpid, prfpregset_t *regs);
ps_err_e ps_lsetfpregs(struct ps_prochandle *Pr,
lwpid_t lwpid, const prfpregset_t *regs);
#if defined(sparc) || defined(__sparc)
ps_err_e ps_lgetxregsize(struct ps_prochandle *Pr,
lwpid_t lwpid, int *xrsize);
ps_err_e ps_lgetxregs(struct ps_prochandle *Pr,
lwpid_t lwpid, caddr_t xregs);
ps_err_e ps_lsetxregs(struct ps_prochandle *Pr,
lwpid_t lwpid, caddr_t xregs);
#endif /* sparc */
#if defined(__i386) || defined(__amd64)
ps_err_e ps_lgetLDT(struct ps_prochandle *Pr,
lwpid_t lwpid, struct ssd *ldt);
#endif /* __i386 || __amd6464 */
void ps_plog(const char *fmt, ...);
/* Psymtab.c */
void Pupdate_maps(struct ps_prochandle *Pr);
void Pupdate_syms(struct ps_prochandle *Pr);
rd_agent_t *Prd_agent(struct ps_prochandle *Pr);
const prmap_t *Paddr_to_map(struct ps_prochandle *Pr, uintptr_t addr);
const prmap_t *Paddr_to_text_map(struct ps_prochandle *Pr, uintptr_t addr);
const prmap_t *Pname_to_map(struct ps_prochandle *Pr, const char *name);
const prmap_t *Plmid_to_map(struct ps_prochandle *Pr, Lmid_t lmid,
const char *name);
int Plookup_by_addr(struct ps_prochandle *Pr, uintptr_t addr,
char *sym_name_buffer, size_t bufsize, GElf_Sym *symbolp);
int Plookup_by_name(struct ps_prochandle *Pr,
const char *object_name, const char *symbol_name,
GElf_Sym *sym);
int Plookup_by_lmid(struct ps_prochandle *Pr,
Lmid_t lmid, const char *object_name, const char *symbol_name,
GElf_Sym *sym);
const rd_loadobj_t *Paddr_to_loadobj(struct ps_prochandle *, uintptr_t);
const rd_loadobj_t *Pname_to_loadobj(struct ps_prochandle *, const char *);
const rd_loadobj_t *Plmid_to_loadobj(struct ps_prochandle *, Lmid_t,
const char *);
int Pmapping_iter(struct ps_prochandle *Pr, proc_map_f *func, void *cd);
int Pobject_iter(struct ps_prochandle *Pr, proc_map_f *func, void *cd);
char *Pobjname(struct ps_prochandle *Pr, uintptr_t addr,
char *buffer, size_t bufsize);
int Plmid(struct ps_prochandle *Pr, uintptr_t addr, Lmid_t *lmidp);
int Psymbol_iter(struct ps_prochandle *Pr, const char *object_name,
int which, int type, proc_sym_f *func, void *cd);
int Psymbol_iter_by_lmid(struct ps_prochandle *Pr, Lmid_t lmid,
const char *object_name, int which, int type,
proc_sym_f *func, void *cd);
char *Pgetenv(struct ps_prochandle *Pr, const char *name,
char *buffer, size_t bufsize);
char *Pplatform(struct ps_prochandle *Pr, char *s, size_t n);
int Puname(struct ps_prochandle *Pr, struct utsname *u);
char *Pzonename(struct ps_prochandle *Pr, char *s, size_t n);
char *Pexecname(struct ps_prochandle *Pr, char *buffer, size_t bufsize);
void Preset_maps(struct ps_prochandle *Pr);
ps_err_e ps_pglobal_lookup(struct ps_prochandle *Pr,
const char *object_name, const char *sym_name,
psaddr_t *sym_addr);
ps_err_e ps_pglobal_sym(struct ps_prochandle *Pr,
const char *object_name, const char *sym_name,
ps_sym_t *symp);
long Pgetauxval(struct ps_prochandle *Pr, int type);
const auxv_t *Pgetauxvec(struct ps_prochandle *Pr);
ps_err_e ps_pauxv(struct ps_prochandle *Pr, const auxv_t **aux);
/* Putil.c */
void Perror_printf(struct ps_prochandle *Pr, const char *format, ...);
/* pr_door.c */
int pr_door_info(struct ps_prochandle *Pr, int did, door_info_t *di);
/* pr_exit.c */
int pr_exit(struct ps_prochandle *Pr, int status);
int pr_lwp_exit(struct ps_prochandle *Pr);
/* pr_fcntl.c */
int pr_fcntl(struct ps_prochandle *Pr, int fd, int cmd, void *argp);
/* pr_getitimer.c */
int pr_getitimer(struct ps_prochandle *Pr,
int which, struct itimerval *itv);
int pr_setitimer(struct ps_prochandle *Pr,
int which, const struct itimerval *itv, struct itimerval *oitv);
/* pr_getrctl.c */
int pr_getrctl(struct ps_prochandle *Pr, const char *rname,
rctlblk_t *old_blk, rctlblk_t *new_blk, int rflag);
int pr_setrctl(struct ps_prochandle *Pr, const char *rname,
rctlblk_t *old_blk, rctlblk_t *new_blk, int rflag);
/* pr_getrlimit.c */
int pr_getrlimit(struct ps_prochandle *Pr,
int resource, struct rlimit *rlp);
int pr_setrlimit(struct ps_prochandle *Pr,
int resource, const struct rlimit *rlp);
int pr_getrlimit64(struct ps_prochandle *Pr,
int resource, struct rlimit64 *rlp);
int pr_setrlimit64(struct ps_prochandle *Pr,
int resource, const struct rlimit64 *rlp);
/* pr_getsockname.c */
int pr_getsockname(struct ps_prochandle *Pr,
int sock, struct sockaddr *name, socklen_t *namelen);
int pr_getpeername(struct ps_prochandle *Pr,
int sock, struct sockaddr *name, socklen_t *namelen);
/* pr_ioctl.c */
int pr_ioctl(struct ps_prochandle *Pr,
int fd, int code, void *buf, size_t size);
/* pr_lseek.c */
off_t pr_lseek(struct ps_prochandle *Pr,
int filedes, off_t offset, int whence);
offset_t pr_llseek(struct ps_prochandle *Pr,
int filedes, offset_t offset, int whence);
/* pr_memcntl.c */
int pr_memcntl(struct ps_prochandle *Pr,
caddr_t addr, size_t len, int cmd, caddr_t arg, int attr, int mask);
/* pr_mmap.c */
void *pr_mmap(struct ps_prochandle *Pr,
void *addr, size_t len, int prot, int flags, int fd, off_t off);
int pr_munmap(struct ps_prochandle *Pr,
void *addr, size_t len);
void *pr_zmap(struct ps_prochandle *Pr,
void *addr, size_t len, int prot, int flags);
/* pr_open.c */
int pr_open(struct ps_prochandle *Pr,
const char *filename, int flags, mode_t mode);
int pr_creat(struct ps_prochandle *Pr,
const char *filename, mode_t mode);
int pr_close(struct ps_prochandle *Pr, int fd);
int pr_access(struct ps_prochandle *Pr, const char *path, int amode);
/* pr_pbind.c */
int pr_processor_bind(struct ps_prochandle *Pr, idtype_t, id_t, int, int *);
int pr_pset_bind(struct ps_prochandle *Pr, int, idtype_t, id_t, int *);
/* pr_rename.c */
int pr_rename(struct ps_prochandle *Pr, const char *old, const char *new);
int pr_link(struct ps_prochandle *Pr, const char *exist, const char *new);
int pr_unlink(struct ps_prochandle *Pr, const char *);
/* pr_sigaction.c */
int pr_sigaction(struct ps_prochandle *Pr,
int sig, const struct sigaction *act, struct sigaction *oact);
/* pr_stat.c */
int pr_stat(struct ps_prochandle *Pr, const char *path, struct stat *buf);
int pr_lstat(struct ps_prochandle *Pr, const char *path, struct stat *buf);
int pr_fstat(struct ps_prochandle *Pr, int fd, struct stat *buf);
int pr_stat64(struct ps_prochandle *Pr, const char *path,
struct stat64 *buf);
int pr_lstat64(struct ps_prochandle *Pr, const char *path,
struct stat64 *buf);
int pr_fstat64(struct ps_prochandle *Pr, int fd, struct stat64 *buf);
/* pr_statvfs.c */
int pr_statvfs(struct ps_prochandle *Pr, const char *path, statvfs_t *buf);
int pr_fstatvfs(struct ps_prochandle *Pr, int fd, statvfs_t *buf);
/* pr_tasksys.c */
projid_t pr_getprojid(struct ps_prochandle *Pr);
taskid_t pr_gettaskid(struct ps_prochandle *Pr);
taskid_t pr_settaskid(struct ps_prochandle *Pr, projid_t project, int flags);
/* pr_waitid.c */
int pr_waitid(struct ps_prochandle *Pr,
idtype_t idtype, id_t id, siginfo_t *infop, int options);
/* proc_get_info.c */
int proc_get_cred(pid_t pid, prcred_t *credp, int ngroups);
prpriv_t *proc_get_priv(pid_t pid);
int proc_get_psinfo(pid_t pid, psinfo_t *psp);
int proc_get_status(pid_t pid, pstatus_t *psp);
int proc_get_auxv(pid_t pid, auxv_t *pauxv, int naux);
/* proc_names.c */
char *proc_fltname(int flt, char *buf, size_t bufsz);
char *proc_signame(int sig, char *buf, size_t bufsz);
char *proc_sysname(int sys, char *buf, size_t bufsz);
int proc_str2flt(const char *str, int *fltnum);
int proc_str2sig(const char *str, int *signum);
int proc_str2sys(const char *str, int *sysnum);
char *proc_fltset2str(const fltset_t *set, const char *delim, int members,
char *buf, size_t nbytes);
char *proc_sigset2str(const sigset_t *set, const char *delim, int members,
char *buf, size_t nbytes);
char *proc_sysset2str(const sysset_t *set, const char *delim, int members,
char *buf, size_t nbytes);
char *proc_str2fltset(const char *str, const char *delim, int members,
fltset_t *set);
char *proc_str2sigset(const char *str, const char *delim, int members,
sigset_t *set);
char *proc_str2sysset(const char *str, const char *delim, int members,
sysset_t *set);
int proc_walk(proc_walk_f *func, void *arg, int flags);
/* proc_arg.c */
struct ps_prochandle *proc_arg_grab(const char *arg,
int oflag, int gflag, int *perr);
pid_t proc_arg_psinfo(const char *arg, int oflag, psinfo_t *psp, int *perr);
void proc_unctrl_psinfo(psinfo_t *psp);
/* proc_set.c */
int Psetcred(struct ps_prochandle *Pr, const prcred_t *pcred);
/* Pstack.c */
int Pstack_iter(struct ps_prochandle *Pr,
const prgregset_t regs, proc_stack_f *func, void *arg);
/* Pisadep.c */
const char *Ppltdest(struct ps_prochandle *Pr, uintptr_t addr);