Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/agent/src/os/solaris/proc/libproc.h
38840 views
/*1* Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324/*25* Interfaces available from the process control library, libproc.26*27* libproc provides process control functions for the /proc tools28* (commands in /usr/proc/bin), /usr/bin/truss, and /usr/bin/gcore.29* libproc is a private support library for these commands only.30* It is _not_ a public interface, although it might become one31* in the fullness of time, when the interfaces settle down.32*33* In the meantime, be aware that any program linked with libproc in this34* release of Solaris is almost guaranteed to break in the next release.35*36* In short, do not use this header file or libproc for any purpose.37*/3839#ifndef _LIBPROC_H40#define _LIBPROC_H4142#include <stdlib.h>43#include <unistd.h>44#include <fcntl.h>45#include <nlist.h>46#include <door.h>47#include <gelf.h>48#include <proc_service.h>49#include <rtld_db.h>50#include <procfs.h>51#include <sys/stat.h>52#include <sys/statvfs.h>53#include <sys/auxv.h>54#include <sys/resource.h>55#include <sys/socket.h>56#include <sys/utsname.h>5758#ifdef __cplusplus59extern "C" {60#endif6162/*63* Opaque structure tag reference to a process control structure.64* Clients of libproc cannot look inside the process control structure.65* The implementation of struct ps_prochandle can change w/o affecting clients.66*/67struct ps_prochandle;6869extern int _libproc_debug; /* set non-zero to enable debugging fprintfs */7071#if defined(sparc) || defined(__sparc)72#define R_RVAL1 R_O0 /* register holding a function return value */73#define R_RVAL2 R_O1 /* 32 more bits for a 64-bit return value */74#define SYSCALL32 0x91d02008 /* 32-bit syscall (ta 8) instruction */75#define SYSCALL64 0x91d02040 /* 64-bit syscall (ta 64) instruction */76typedef uint32_t syscall_t; /* holds a syscall instruction */77#endif /* sparc */7879#if defined(__i386) || defined(__ia64)80#define R_PC EIP81#define R_SP UESP82#define R_RVAL1 EAX /* register holding a function return value */83#define R_RVAL2 EDX /* 32 more bits for a 64-bit return value */84#define SYSCALL 0x9a /* syscall (lcall) instruction opcode */85typedef uchar_t syscall_t[7]; /* holds a syscall instruction */86#endif /* __i386 || __ia64 */8788#define R_RVAL R_RVAL1 /* simple function return value register */8990/* maximum sizes of things */91#define PRMAXSIG (32 * sizeof (sigset_t) / sizeof (uint32_t))92#define PRMAXFAULT (32 * sizeof (fltset_t) / sizeof (uint32_t))93#define PRMAXSYS (32 * sizeof (sysset_t) / sizeof (uint32_t))9495/* State values returned by Pstate() */96#define PS_RUN 1 /* process is running */97#define PS_STOP 2 /* process is stopped */98#define PS_LOST 3 /* process is lost to control (EAGAIN) */99#define PS_UNDEAD 4 /* process is terminated (zombie) */100#define PS_DEAD 5 /* process is terminated (core file) */101102/* Flags accepted by Pgrab() */103#define PGRAB_RETAIN 0x01 /* Retain tracing flags, else clear flags */104#define PGRAB_FORCE 0x02 /* Open the process w/o O_EXCL */105#define PGRAB_RDONLY 0x04 /* Open the process or core w/ O_RDONLY */106#define PGRAB_NOSTOP 0x08 /* Open the process but do not stop it */107108/* Error codes from Pcreate() */109#define C_STRANGE -1 /* Unanticipated error, errno is meaningful */110#define C_FORK 1 /* Unable to fork */111#define C_PERM 2 /* No permission (file set-id or unreadable) */112#define C_NOEXEC 3 /* Cannot find executable file */113#define C_INTR 4 /* Interrupt received while creating */114#define C_LP64 5 /* Program is _LP64, self is _ILP32 */115116/* Error codes from Pgrab(), Pfgrab_core(), and Pgrab_core() */117#define G_STRANGE -1 /* Unanticipated error, errno is meaningful */118#define G_NOPROC 1 /* No such process */119#define G_NOCORE 2 /* No such core file */120#define G_NOPROCORCORE 3 /* No such proc or core (for proc_arg_grab) */121#define G_NOEXEC 4 /* Cannot locate executable file */122#define G_ZOMB 5 /* Zombie process */123#define G_PERM 6 /* No permission */124#define G_BUSY 7 /* Another process has control */125#define G_SYS 8 /* System process */126#define G_SELF 9 /* Process is self */127#define G_INTR 10 /* Interrupt received while grabbing */128#define G_LP64 11 /* Process is _LP64, self is ILP32 */129#define G_FORMAT 12 /* File is not an ELF format core file */130#define G_ELF 13 /* Libelf error, elf_errno() is meaningful */131#define G_NOTE 14 /* Required PT_NOTE Phdr not present in core */132133/* Flags accepted by Prelease */134#define PRELEASE_CLEAR 0x10 /* Clear all tracing flags */135#define PRELEASE_RETAIN 0x20 /* Retain final tracing flags */136#define PRELEASE_HANG 0x40 /* Leave the process stopped */137#define PRELEASE_KILL 0x80 /* Terminate the process */138139typedef struct { /* argument descriptor for system call (Psyscall) */140long arg_value; /* value of argument given to system call */141void *arg_object; /* pointer to object in controlling process */142char arg_type; /* AT_BYVAL, AT_BYREF */143char arg_inout; /* AI_INPUT, AI_OUTPUT, AI_INOUT */144ushort_t arg_size; /* if AT_BYREF, size of object in bytes */145} argdes_t;146147typedef struct { /* return values from system call (Psyscall) */148int sys_errno; /* syscall error number */149long sys_rval1; /* primary return value from system call */150long sys_rval2; /* second return value from system call */151} sysret_t;152153/* values for type */154#define AT_BYVAL 1155#define AT_BYREF 2156157/* values for inout */158#define AI_INPUT 1159#define AI_OUTPUT 2160#define AI_INOUT 3161162/* maximum number of syscall arguments */163#define MAXARGS 8164165/* maximum size in bytes of a BYREF argument */166#define MAXARGL (4*1024)167168/* Kludges to make things work on Solaris 2.6 */169#if !defined(_LP64) && !defined(PR_MODEL_UNKNOWN)170#define PR_MODEL_UNKNOWN 0171#define PR_MODEL_ILP32 0 /* process data model is ILP32 */172#define PR_MODEL_LP64 2 /* process data model is LP64 */173#define PR_MODEL_NATIVE PR_MODEL_ILP32174#define pr_dmodel pr_filler[0]175#define STACK_BIAS 0176#endif177178/*179* Function prototypes for routines in the process control package.180*/181extern struct ps_prochandle *Pcreate(const char *, char *const *,182int *, char *, size_t);183184extern const char *Pcreate_error(int);185186extern struct ps_prochandle *Pgrab(pid_t, int, int *);187extern struct ps_prochandle *Pgrab_core(const char *, const char *, int, int *);188extern struct ps_prochandle *Pfgrab_core(int, const char *, int *);189190extern const char *Pgrab_error(int);191192extern int Preopen(struct ps_prochandle *);193extern void Prelease(struct ps_prochandle *, int);194extern void Pfree(struct ps_prochandle *);195196extern int Pasfd(struct ps_prochandle *);197extern int Pctlfd(struct ps_prochandle *);198extern int Pcreate_agent(struct ps_prochandle *);199extern void Pdestroy_agent(struct ps_prochandle *);200extern int Pwait(struct ps_prochandle *, uint_t);201extern int Pstop(struct ps_prochandle *, uint_t);202extern int Pstate(struct ps_prochandle *);203extern const psinfo_t *Ppsinfo(struct ps_prochandle *);204extern const pstatus_t *Pstatus(struct ps_prochandle *);205extern int Pcred(struct ps_prochandle *, prcred_t *, int);206extern int Pgetareg(struct ps_prochandle *, int, prgreg_t *);207extern int Pputareg(struct ps_prochandle *, int, prgreg_t);208extern int Psetrun(struct ps_prochandle *, int, int);209extern ssize_t Pread(struct ps_prochandle *, void *, size_t, uintptr_t);210extern ssize_t Pread_string(struct ps_prochandle *, char *, size_t, uintptr_t);211extern ssize_t Pwrite(struct ps_prochandle *, const void *, size_t, uintptr_t);212extern int Pclearsig(struct ps_prochandle *);213extern int Pclearfault(struct ps_prochandle *);214extern int Psetbkpt(struct ps_prochandle *, uintptr_t, ulong_t *);215extern int Pdelbkpt(struct ps_prochandle *, uintptr_t, ulong_t);216extern int Pxecbkpt(struct ps_prochandle *, ulong_t);217extern int Psetflags(struct ps_prochandle *, long);218extern int Punsetflags(struct ps_prochandle *, long);219extern int Psignal(struct ps_prochandle *, int, int);220extern int Pfault(struct ps_prochandle *, int, int);221extern int Psysentry(struct ps_prochandle *, int, int);222extern int Psysexit(struct ps_prochandle *, int, int);223extern void Psetsignal(struct ps_prochandle *, const sigset_t *);224extern void Psetfault(struct ps_prochandle *, const fltset_t *);225extern void Psetsysentry(struct ps_prochandle *, const sysset_t *);226extern void Psetsysexit(struct ps_prochandle *, const sysset_t *);227extern void Psync(struct ps_prochandle *);228extern sysret_t Psyscall(struct ps_prochandle *, int, uint_t, argdes_t *);229extern int Pisprocdir(struct ps_prochandle *, const char *);230231/*232* Function prototypes for system calls forced on the victim process.233*/234extern int pr_open(struct ps_prochandle *, const char *, int, mode_t);235extern int pr_creat(struct ps_prochandle *, const char *, mode_t);236extern int pr_close(struct ps_prochandle *, int);237extern int pr_door_info(struct ps_prochandle *, int, struct door_info *);238extern void *pr_mmap(struct ps_prochandle *,239void *, size_t, int, int, int, off_t);240extern void *pr_zmap(struct ps_prochandle *,241void *, size_t, int, int);242extern int pr_munmap(struct ps_prochandle *, void *, size_t);243extern int pr_memcntl(struct ps_prochandle *,244caddr_t, size_t, int, caddr_t, int, int);245extern int pr_sigaction(struct ps_prochandle *,246int, const struct sigaction *, struct sigaction *);247extern int pr_getitimer(struct ps_prochandle *,248int, struct itimerval *);249extern int pr_setitimer(struct ps_prochandle *,250int, const struct itimerval *, struct itimerval *);251extern int pr_ioctl(struct ps_prochandle *, int, int, void *, size_t);252extern int pr_fcntl(struct ps_prochandle *, int, int, void *);253extern int pr_stat(struct ps_prochandle *, const char *, struct stat *);254extern int pr_lstat(struct ps_prochandle *, const char *, struct stat *);255extern int pr_fstat(struct ps_prochandle *, int, struct stat *);256extern int pr_statvfs(struct ps_prochandle *, const char *, statvfs_t *);257extern int pr_fstatvfs(struct ps_prochandle *, int, statvfs_t *);258extern int pr_getrlimit(struct ps_prochandle *,259int, struct rlimit *);260extern int pr_setrlimit(struct ps_prochandle *,261int, const struct rlimit *);262#if defined(_LARGEFILE64_SOURCE)263extern int pr_getrlimit64(struct ps_prochandle *,264int, struct rlimit64 *);265extern int pr_setrlimit64(struct ps_prochandle *,266int, const struct rlimit64 *);267#endif /* _LARGEFILE64_SOURCE */268extern int pr_lwp_exit(struct ps_prochandle *);269extern int pr_exit(struct ps_prochandle *, int);270extern int pr_waitid(struct ps_prochandle *,271idtype_t, id_t, siginfo_t *, int);272extern off_t pr_lseek(struct ps_prochandle *, int, off_t, int);273extern offset_t pr_llseek(struct ps_prochandle *, int, offset_t, int);274extern int pr_rename(struct ps_prochandle *, const char *, const char *);275extern int pr_link(struct ps_prochandle *, const char *, const char *);276extern int pr_unlink(struct ps_prochandle *, const char *);277extern int pr_getpeername(struct ps_prochandle *,278int, struct sockaddr *, socklen_t *);279extern int pr_getsockname(struct ps_prochandle *,280int, struct sockaddr *, socklen_t *);281282/*283* Function prototypes for accessing per-LWP register information.284*/285extern int Plwp_getregs(struct ps_prochandle *, lwpid_t, prgregset_t);286extern int Plwp_setregs(struct ps_prochandle *, lwpid_t, const prgregset_t);287288extern int Plwp_getfpregs(struct ps_prochandle *, lwpid_t, prfpregset_t *);289extern int Plwp_setfpregs(struct ps_prochandle *, lwpid_t,290const prfpregset_t *);291292#if defined(sparc) || defined(__sparc)293294extern int Plwp_getxregs(struct ps_prochandle *, lwpid_t, prxregset_t *);295extern int Plwp_setxregs(struct ps_prochandle *, lwpid_t, const prxregset_t *);296297#if defined(__sparcv9)298extern int Plwp_getasrs(struct ps_prochandle *, lwpid_t, asrset_t);299extern int Plwp_setasrs(struct ps_prochandle *, lwpid_t, const asrset_t);300#endif /* __sparcv9 */301302#endif /* __sparc */303304extern int Plwp_getpsinfo(struct ps_prochandle *, lwpid_t, lwpsinfo_t *);305306/*307* LWP iteration interface.308*/309typedef int proc_lwp_f(void *, const lwpstatus_t *);310extern int Plwp_iter(struct ps_prochandle *, proc_lwp_f *, void *);311312/*313* Symbol table interfaces.314*/315316/*317* Pseudo-names passed to Plookup_by_name() for well-known load objects.318* NOTE: It is required that PR_OBJ_EXEC and PR_OBJ_LDSO exactly match319* the definitions of PS_OBJ_EXEC and PS_OBJ_LDSO from <proc_service.h>.320*/321#define PR_OBJ_EXEC ((const char *)0) /* search the executable file */322#define PR_OBJ_LDSO ((const char *)1) /* search ld.so.1 */323#define PR_OBJ_EVERY ((const char *)-1) /* search every load object */324325/*326* 'object_name' is the name of a load object obtained from an327* iteration over the process's address space mappings (Pmapping_iter),328* or an iteration over the process's mapped objects (Pobject_iter),329* or else it is one of the special PR_OBJ_* values above.330*/331extern int Plookup_by_name(struct ps_prochandle *,332const char *, const char *, GElf_Sym *);333334extern int Plookup_by_addr(struct ps_prochandle *,335uintptr_t, char *, size_t, GElf_Sym *);336337typedef int proc_map_f(void *, const prmap_t *, const char *);338339extern int Pmapping_iter(struct ps_prochandle *, proc_map_f *, void *);340extern int Pobject_iter(struct ps_prochandle *, proc_map_f *, void *);341342extern const prmap_t *Paddr_to_map(struct ps_prochandle *, uintptr_t);343extern const prmap_t *Paddr_to_text_map(struct ps_prochandle *, uintptr_t);344extern const prmap_t *Pname_to_map(struct ps_prochandle *, const char *);345346extern char *Pplatform(struct ps_prochandle *, char *, size_t);347extern int Puname(struct ps_prochandle *, struct utsname *);348349extern char *Pexecname(struct ps_prochandle *, char *, size_t);350extern char *Pobjname(struct ps_prochandle *, uintptr_t, char *, size_t);351352extern char *Pgetenv(struct ps_prochandle *, const char *, char *, size_t);353extern long Pgetauxval(struct ps_prochandle *, int);354355/*356* Symbol table iteration interface.357*/358typedef int proc_sym_f(void *, const GElf_Sym *, const char *);359360extern int Psymbol_iter(struct ps_prochandle *,361const char *, int, int, proc_sym_f *, void *);362363/*364* 'which' selects which symbol table and can be one of the following.365*/366#define PR_SYMTAB 1367#define PR_DYNSYM 2368/*369* 'type' selects the symbols of interest by binding and type. It is a bit-370* mask of one or more of the following flags, whose order MUST match the371* order of STB and STT constants in <sys/elf.h>.372*/373#define BIND_LOCAL 0x0001374#define BIND_GLOBAL 0x0002375#define BIND_WEAK 0x0004376#define BIND_ANY (BIND_LOCAL|BIND_GLOBAL|BIND_WEAK)377#define TYPE_NOTYPE 0x0100378#define TYPE_OBJECT 0x0200379#define TYPE_FUNC 0x0400380#define TYPE_SECTION 0x0800381#define TYPE_FILE 0x1000382#define TYPE_ANY (TYPE_NOTYPE|TYPE_OBJECT|TYPE_FUNC|TYPE_SECTION|TYPE_FILE)383384/*385* This returns the rtld_db agent handle for the process.386* The handle will become invalid at the next successful exec() and387* must not be used beyond that point (see Preset_maps(), below).388*/389extern rd_agent_t *Prd_agent(struct ps_prochandle *);390391/*392* This should be called when an RD_DLACTIVITY event with the393* RD_CONSISTENT state occurs via librtld_db's event mechanism.394* This makes libproc's address space mappings and symbol tables current.395*/396extern void Pupdate_maps(struct ps_prochandle *);397398/*399* This must be called after the victim process performs a successful400* exec() if any of the symbol table interface functions have been called401* prior to that point. This is essential because an exec() invalidates402* all previous symbol table and address space mapping information.403* It is always safe to call, but if it is called other than after an404* exec() by the victim process it just causes unnecessary overhead.405*406* The rtld_db agent handle obtained from a previous call to Prd_agent() is407* made invalid by Preset_maps() and Prd_agent() must be called again to get408* the new handle.409*/410extern void Preset_maps(struct ps_prochandle *);411412/*413* Given an address, Ppltdest() determines if this is part of a PLT, and if414* so returns the target address of this PLT entry and a flag indicating415* whether or not this PLT entry has been bound by the run-time linker.416*/417extern uintptr_t Ppltdest(struct ps_prochandle *, uintptr_t, int *);418419/*420* Stack frame iteration interface.421*/422#ifdef SOLARIS_11_B159_OR_LATER423/* building on Nevada-B159 or later so define the new callback */424typedef int proc_stack_f(425void *, /* the cookie given to Pstack_iter() */426const prgregset_t, /* the frame's registers */427uint_t, /* argc for the frame's function */428const long *, /* argv for the frame's function */429int, /* bitwise flags describing the frame (see below) */430int); /* a signal number */431432#define PR_SIGNAL_FRAME 1 /* called by a signal handler */433#define PR_FOUND_SIGNAL 2 /* we found the corresponding signal number */434#else435/* building on Nevada-B158 or earlier so define the old callback */436typedef int proc_stack_f(void *, const prgregset_t, uint_t, const long *);437#endif438439extern int Pstack_iter(struct ps_prochandle *,440const prgregset_t, proc_stack_f *, void *);441442/*443* Compute the full pathname of a named directory without using chdir().444* This is useful for dealing with /proc/<pid>/cwd.445*/446extern char *proc_dirname(const char *, char *, size_t);447448/*449* Remove unprintable characters from psinfo.pr_psargs and replace with450* whitespace characters so it is safe for printing.451*/452extern void proc_unctrl_psinfo(psinfo_t *);453454/*455* Utility functions for processing arguments which should be /proc files,456* pids, and/or core files. The returned error code can be passed to457* Pgrab_error() in order to convert it to an error string.458*/459#define PR_ARG_PIDS 0x1 /* Allow pid and /proc file arguments */460#define PR_ARG_CORES 0x2 /* Allow core file arguments */461462#define PR_ARG_ANY (PR_ARG_PIDS | PR_ARG_CORES)463464extern struct ps_prochandle *proc_arg_grab(const char *, int, int, int *);465extern pid_t proc_arg_psinfo(const char *, int, psinfo_t *, int *);466467/*468* Utility functions for obtaining information via /proc without actually469* performing a Pcreate() or Pgrab():470*/471extern int proc_get_auxv(pid_t, auxv_t *, int);472extern int proc_get_cred(pid_t, prcred_t *, int);473extern int proc_get_psinfo(pid_t, psinfo_t *);474extern int proc_get_status(pid_t, pstatus_t *);475476/*477* Utility functions for debugging tools to convert numeric fault,478* signal, and system call numbers to symbolic names:479*/480extern char *proc_fltname(int, char *, size_t);481extern char *proc_signame(int, char *, size_t);482extern char *proc_sysname(int, char *, size_t);483484#ifdef __cplusplus485}486#endif487488#endif /* _LIBPROC_H */489490491