📄 libproc.h
字号:
/* * Copyright 2005 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only. * See the file usr/src/LICENSING.NOTICE in this distribution or * http://www.opensolaris.org/license/ for details. *//* * Interfaces available from the process control library, libproc. * * libproc provides process control functions for the /proc tools * (commands in /usr/proc/bin), /usr/bin/truss, and /usr/bin/gcore. * libproc is a private support library for these commands only. * It is _not_ a public interface, although it might become one * in the fullness of time, when the interfaces settle down. * * In the meantime, be aware that any program linked with libproc in this * release of Solaris is almost guaranteed to break in the next release. * * In short, do not use this header file or libproc for any purpose. */#ifndef _LIBPROC_H#define _LIBPROC_H#pragma ident "@(#)libproc.h 1.45 04/11/01 SMI"#include <stdlib.h>#include <unistd.h>#include <fcntl.h>#include <nlist.h>#include <door.h>#include <gelf.h>#include <proc_service.h>#include <rtld_db.h>#include <procfs.h>#include <rctl.h>#include <libctf.h>#include <sys/stat.h>#include <sys/statvfs.h>#include <sys/auxv.h>#include <sys/resource.h>#include <sys/socket.h>#include <sys/utsname.h>#include <sys/corectl.h>#if defined(__i386) || defined(__amd64)#include <sys/sysi86.h>#endif#ifdef __cplusplusextern "C" {#endif/* * Opaque structure tag reference to a process control structure. * Clients of libproc cannot look inside the process control structure. * The implementation of struct ps_prochandle can change w/o affecting clients. */struct ps_prochandle;/* * Opaque structure tag reference to an lwp control structure. */struct ps_lwphandle;extern int _libproc_debug; /* set non-zero to enable debugging fprintfs */#if defined(__sparc)#define R_RVAL1 R_O0 /* register holding a function return value */#define R_RVAL2 R_O1 /* 32 more bits for a 64-bit return value */#endif /* __sparc */#if defined(__amd64)#define R_PC REG_RIP#define R_SP REG_RSP#define R_RVAL1 REG_RAX /* register holding a function return value */#define R_RVAL2 REG_RDX /* 32 more bits for a 64-bit return value */#elif defined(__i386)#define R_PC EIP#define R_SP UESP#define R_RVAL1 EAX /* register holding a function return value */#define R_RVAL2 EDX /* 32 more bits for a 64-bit return value */#endif /* __amd64 || __i386 */#define R_RVAL R_RVAL1 /* simple function return value register *//* maximum sizes of things */#define PRMAXSIG (32 * sizeof (sigset_t) / sizeof (uint32_t))#define PRMAXFAULT (32 * sizeof (fltset_t) / sizeof (uint32_t))#define PRMAXSYS (32 * sizeof (sysset_t) / sizeof (uint32_t))/* State values returned by Pstate() */#define PS_RUN 1 /* process is running */#define PS_STOP 2 /* process is stopped */#define PS_LOST 3 /* process is lost to control (EAGAIN) */#define PS_UNDEAD 4 /* process is terminated (zombie) */#define PS_DEAD 5 /* process is terminated (core file) */#define PS_IDLE 6 /* process has not been run *//* Flags accepted by Pgrab() */#define PGRAB_RETAIN 0x01 /* Retain tracing flags, else clear flags */#define PGRAB_FORCE 0x02 /* Open the process w/o O_EXCL */#define PGRAB_RDONLY 0x04 /* Open the process or core w/ O_RDONLY */#define PGRAB_NOSTOP 0x08 /* Open the process but do not stop it *//* Error codes from Pcreate() */#define C_STRANGE -1 /* Unanticipated error, errno is meaningful */#define C_FORK 1 /* Unable to fork */#define C_PERM 2 /* No permission (file set-id or unreadable) */#define C_NOEXEC 3 /* Cannot execute file */#define C_INTR 4 /* Interrupt received while creating */#define C_LP64 5 /* Program is _LP64, self is _ILP32 */#define C_NOENT 6 /* Cannot find executable file *//* Error codes from Pgrab(), Pfgrab_core(), and Pgrab_core() */#define G_STRANGE -1 /* Unanticipated error, errno is meaningful */#define G_NOPROC 1 /* No such process */#define G_NOCORE 2 /* No such core file */#define G_NOPROCORCORE 3 /* No such proc or core (for proc_arg_grab) */#define G_NOEXEC 4 /* Cannot locate executable file */#define G_ZOMB 5 /* Zombie process */#define G_PERM 6 /* No permission */#define G_BUSY 7 /* Another process has control */#define G_SYS 8 /* System process */#define G_SELF 9 /* Process is self */#define G_INTR 10 /* Interrupt received while grabbing */#define G_LP64 11 /* Process is _LP64, self is ILP32 */#define G_FORMAT 12 /* File is not an ELF format core file */#define G_ELF 13 /* Libelf error, elf_errno() is meaningful */#define G_NOTE 14 /* Required PT_NOTE Phdr not present in core */#define G_ISAINVAL 15 /* Wrong ELF machine type */#define G_BADLWPS 16 /* Bad '/lwps' specification *//* Flags accepted by Prelease */#define PRELEASE_CLEAR 0x10 /* Clear all tracing flags */#define PRELEASE_RETAIN 0x20 /* Retain final tracing flags */#define PRELEASE_HANG 0x40 /* Leave the process stopped */#define PRELEASE_KILL 0x80 /* Terminate the process */typedef struct { /* argument descriptor for system call (Psyscall) */ long arg_value; /* value of argument given to system call */ void *arg_object; /* pointer to object in controlling process */ char arg_type; /* AT_BYVAL, AT_BYREF */ char arg_inout; /* AI_INPUT, AI_OUTPUT, AI_INOUT */ ushort_t arg_size; /* if AT_BYREF, size of object in bytes */} argdes_t;/* values for type */#define AT_BYVAL 1#define AT_BYREF 2/* values for inout */#define AI_INPUT 1#define AI_OUTPUT 2#define AI_INOUT 3/* maximum number of syscall arguments */#define MAXARGS 8/* maximum size in bytes of a BYREF argument */#define MAXARGL (4*1024)/* * Function prototypes for routines in the process control package. */extern struct ps_prochandle *Pcreate(const char *, char *const *, int *, char *, size_t);extern struct ps_prochandle *Pxcreate(const char *, char *const *, char *const *, int *, char *, size_t);extern const char *Pcreate_error(int);extern struct ps_prochandle *Pgrab(pid_t, int, int *);extern struct ps_prochandle *Pgrab_core(const char *, const char *, int, int *);extern struct ps_prochandle *Pfgrab_core(int, const char *, int *);extern struct ps_prochandle *Pgrab_file(const char *, int *);extern const char *Pgrab_error(int);extern int Preopen(struct ps_prochandle *);extern void Prelease(struct ps_prochandle *, int);extern void Pfree(struct ps_prochandle *);extern int Pasfd(struct ps_prochandle *);extern int Pctlfd(struct ps_prochandle *);extern int Pcreate_agent(struct ps_prochandle *);extern void Pdestroy_agent(struct ps_prochandle *);extern int Pstopstatus(struct ps_prochandle *, long, uint_t);extern int Pwait(struct ps_prochandle *, uint_t);extern int Pstop(struct ps_prochandle *, uint_t);extern int Pdstop(struct ps_prochandle *);extern int Pstate(struct ps_prochandle *);extern const psinfo_t *Ppsinfo(struct ps_prochandle *);extern const pstatus_t *Pstatus(struct ps_prochandle *);extern int Pcred(struct ps_prochandle *, prcred_t *, int);extern int Psetcred(struct ps_prochandle *, const prcred_t *);extern ssize_t Ppriv(struct ps_prochandle *, prpriv_t *, size_t);extern int Psetpriv(struct ps_prochandle *, prpriv_t *);extern void *Pprivinfo(struct ps_prochandle *);extern int Psetzoneid(struct ps_prochandle *, zoneid_t);extern int Pgetareg(struct ps_prochandle *, int, prgreg_t *);extern int Pputareg(struct ps_prochandle *, int, prgreg_t);extern int Psetrun(struct ps_prochandle *, int, int);extern ssize_t Pread(struct ps_prochandle *, void *, size_t, uintptr_t);extern ssize_t Pread_string(struct ps_prochandle *, char *, size_t, uintptr_t);extern ssize_t Pwrite(struct ps_prochandle *, const void *, size_t, uintptr_t);extern int Pclearsig(struct ps_prochandle *);extern int Pclearfault(struct ps_prochandle *);extern int Psetbkpt(struct ps_prochandle *, uintptr_t, ulong_t *);extern int Pdelbkpt(struct ps_prochandle *, uintptr_t, ulong_t);extern int Pxecbkpt(struct ps_prochandle *, ulong_t);extern int Psetwapt(struct ps_prochandle *, const prwatch_t *);extern int Pdelwapt(struct ps_prochandle *, const prwatch_t *);extern int Pxecwapt(struct ps_prochandle *, const prwatch_t *);extern int Psetflags(struct ps_prochandle *, long);extern int Punsetflags(struct ps_prochandle *, long);extern int Psignal(struct ps_prochandle *, int, int);extern int Pfault(struct ps_prochandle *, int, int);extern int Psysentry(struct ps_prochandle *, int, int);extern int Psysexit(struct ps_prochandle *, int, int);extern void Psetsignal(struct ps_prochandle *, const sigset_t *);extern void Psetfault(struct ps_prochandle *, const fltset_t *);extern void Psetsysentry(struct ps_prochandle *, const sysset_t *);extern void Psetsysexit(struct ps_prochandle *, const sysset_t *);extern void Psync(struct ps_prochandle *);extern int Psyscall(struct ps_prochandle *, sysret_t *, int, uint_t, argdes_t *);extern int Pisprocdir(struct ps_prochandle *, const char *);/* * Function prototypes for lwp-specific operations. */extern struct ps_lwphandle *Lgrab(struct ps_prochandle *, lwpid_t, int *);extern const char *Lgrab_error(int);extern struct ps_prochandle *Lprochandle(struct ps_lwphandle *);extern void Lfree(struct ps_lwphandle *);extern int Lctlfd(struct ps_lwphandle *);extern int Lwait(struct ps_lwphandle *, uint_t);extern int Lstop(struct ps_lwphandle *, uint_t);extern int Ldstop(struct ps_lwphandle *);extern int Lstate(struct ps_lwphandle *);extern const lwpsinfo_t *Lpsinfo(struct ps_lwphandle *);extern const lwpstatus_t *Lstatus(struct ps_lwphandle *);extern int Lgetareg(struct ps_lwphandle *, int, prgreg_t *);extern int Lputareg(struct ps_lwphandle *, int, prgreg_t);extern int Lsetrun(struct ps_lwphandle *, int, int);extern int Lclearsig(struct ps_lwphandle *);extern int Lclearfault(struct ps_lwphandle *);extern int Lxecbkpt(struct ps_lwphandle *, ulong_t);extern int Lxecwapt(struct ps_lwphandle *, const prwatch_t *);extern void Lsync(struct ps_lwphandle *);extern int Lstack(struct ps_lwphandle *, stack_t *);extern int Lmain_stack(struct ps_lwphandle *, stack_t *);extern int Lalt_stack(struct ps_lwphandle *, stack_t *);/* * Function prototypes for system calls forced on the victim process. */extern int pr_open(struct ps_prochandle *, const char *, int, mode_t);extern int pr_creat(struct ps_prochandle *, const char *, mode_t);extern int pr_close(struct ps_prochandle *, int);extern int pr_access(struct ps_prochandle *, const char *, int);extern int pr_door_info(struct ps_prochandle *, int, struct door_info *);extern void *pr_mmap(struct ps_prochandle *, void *, size_t, int, int, int, off_t);extern void *pr_zmap(struct ps_prochandle *, void *, size_t, int, int);extern int pr_munmap(struct ps_prochandle *, void *, size_t);extern int pr_memcntl(struct ps_prochandle *, caddr_t, size_t, int, caddr_t, int, int);extern int pr_meminfo(struct ps_prochandle *, const uint64_t *addrs, int addr_count, const uint_t *info, int info_count, uint64_t *outdata, uint_t *validity);extern int pr_sigaction(struct ps_prochandle *, int, const struct sigaction *, struct sigaction *);extern int pr_getitimer(struct ps_prochandle *, int, struct itimerval *);extern int pr_setitimer(struct ps_prochandle *, int, const struct itimerval *, struct itimerval *);extern int pr_ioctl(struct ps_prochandle *, int, int, void *, size_t);extern int pr_fcntl(struct ps_prochandle *, int, int, void *);extern int pr_stat(struct ps_prochandle *, const char *, struct stat *);extern int pr_lstat(struct ps_prochandle *, const char *, struct stat *);extern int pr_fstat(struct ps_prochandle *, int, struct stat *);extern int pr_stat64(struct ps_prochandle *, const char *, struct stat64 *);extern int pr_lstat64(struct ps_prochandle *, const char *, struct stat64 *);extern int pr_fstat64(struct ps_prochandle *, int, struct stat64 *);extern int pr_statvfs(struct ps_prochandle *, const char *, statvfs_t *);extern int pr_fstatvfs(struct ps_prochandle *, int, statvfs_t *);extern projid_t pr_getprojid(struct ps_prochandle *Pr);extern taskid_t pr_gettaskid(struct ps_prochandle *Pr);extern taskid_t pr_settaskid(struct ps_prochandle *Pr, projid_t project, int flags);extern zoneid_t pr_getzoneid(struct ps_prochandle *Pr);extern int pr_getrctl(struct ps_prochandle *, const char *, rctlblk_t *, rctlblk_t *, int);extern int pr_setrctl(struct ps_prochandle *, const char *, rctlblk_t *, rctlblk_t *, int);extern int pr_getrlimit(struct ps_prochandle *, int, struct rlimit *);extern int pr_setrlimit(struct ps_prochandle *, int, const struct rlimit *);#if defined(_LARGEFILE64_SOURCE)extern int pr_getrlimit64(struct ps_prochandle *, int, struct rlimit64 *);extern int pr_setrlimit64(struct ps_prochandle *, int, const struct rlimit64 *);#endif /* _LARGEFILE64_SOURCE */extern int pr_lwp_exit(struct ps_prochandle *);extern int pr_exit(struct ps_prochandle *, int);extern int pr_waitid(struct ps_prochandle *, idtype_t, id_t, siginfo_t *, int);extern off_t pr_lseek(struct ps_prochandle *, int, off_t, int);extern offset_t pr_llseek(struct ps_prochandle *, int, offset_t, int);extern int pr_rename(struct ps_prochandle *, const char *, const char *);extern int pr_link(struct ps_prochandle *, const char *, const char *);extern int pr_unlink(struct ps_prochandle *, const char *);extern int pr_getpeername(struct ps_prochandle *, int, struct sockaddr *, socklen_t *);extern int pr_getsockname(struct ps_prochandle *, int, struct sockaddr *, socklen_t *);extern int pr_getsockopt(struct ps_prochandle *, int, int, int, void *, int *);extern int pr_processor_bind(struct ps_prochandle *, idtype_t, id_t, int, int *);extern int pr_pset_bind(struct ps_prochandle *, int, idtype_t, id_t, int *);/* * Function prototypes for accessing per-LWP register information. */extern int Plwp_getregs(struct ps_prochandle *, lwpid_t, prgregset_t);extern int Plwp_setregs(struct ps_prochandle *, lwpid_t, const prgregset_t);extern int Plwp_getfpregs(struct ps_prochandle *, lwpid_t, prfpregset_t *);extern int Plwp_setfpregs(struct ps_prochandle *, lwpid_t,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -