libproc.h revision d7755b5a0365927a64271a9fb2dfd1616f8b0820
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (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
* 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
*/
/*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Interfaces available from the process control library, libproc.
*
* libproc provides process control functions for the /proc tools
* 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 "%Z%%M% %I% %E% 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/resource.h>
#endif
#ifdef __cplusplus
extern "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 */
extern int _libproc_no_qsort; /* set non-zero to inhibit sorting */
/* of symbol tables */
#if defined(__sparc)
#endif /* __sparc */
#if defined(__amd64)
#endif /* __amd64 || __i386 */
/* maximum sizes of things */
/* State values returned by Pstate() */
/* Flags accepted by Pgrab() */
/* Error codes from Pcreate() */
/* Error codes from Pgrab(), Pfgrab_core(), and Pgrab_core() */
/* Flags accepted by Prelease */
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 */
} 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 */
/*
* 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_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 Pdstop(struct ps_prochandle *);
extern int Pstate(struct ps_prochandle *);
extern void *Pprivinfo(struct ps_prochandle *);
extern int Psetrun(struct ps_prochandle *, int, int);
extern int Pclearsig(struct ps_prochandle *);
extern int Pclearfault(struct ps_prochandle *);
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 Psync(struct ps_prochandle *);
extern int Pisprocdir(struct ps_prochandle *, const char *);
/*
* Function prototypes for lwp-specific operations.
*/
extern const char *Lgrab_error(int);
extern void Lfree(struct ps_lwphandle *);
extern int Lctlfd(struct ps_lwphandle *);
extern int Ldstop(struct ps_lwphandle *);
extern int Lstate(struct ps_lwphandle *);
extern int Lsetrun(struct ps_lwphandle *, int, int);
extern int Lclearsig(struct ps_lwphandle *);
extern int Lclearfault(struct ps_lwphandle *);
extern void Lsync(struct ps_lwphandle *);
/*
* Function prototypes for system calls forced on the victim process.
*/
extern int pr_close(struct ps_prochandle *, int);
extern int pr_access(struct ps_prochandle *, const char *, int);
extern void *pr_mmap(struct ps_prochandle *,
extern void *pr_zmap(struct ps_prochandle *,
void *, size_t, int, int);
extern int pr_memcntl(struct ps_prochandle *,
extern int pr_sigaction(struct ps_prochandle *,
extern int pr_getitimer(struct ps_prochandle *,
int, struct itimerval *);
extern int pr_setitimer(struct ps_prochandle *,
extern int pr_fcntl(struct ps_prochandle *, int, int, void *);
extern int pr_stat64(struct ps_prochandle *, const char *,
struct stat64 *);
extern int pr_lstat64(struct ps_prochandle *, const char *,
struct stat64 *);
int flags);
extern int pr_getrctl(struct ps_prochandle *,
extern int pr_setrctl(struct ps_prochandle *,
extern int pr_getrlimit(struct ps_prochandle *,
int, struct rlimit *);
extern int pr_setrlimit(struct ps_prochandle *,
int, const struct rlimit *);
extern int pr_setprojrctl(struct ps_prochandle *, const char *,
#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 *,
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 *,
extern int pr_getsockname(struct ps_prochandle *,
extern int pr_getsockopt(struct ps_prochandle *,
int, int, int, void *, int *);
extern int pr_processor_bind(struct ps_prochandle *,
extern int pr_pset_bind(struct ps_prochandle *,
/*
* Function prototypes for accessing per-LWP register information.
*/
const prfpregset_t *);
#if defined(__sparc)
#if defined(__sparcv9)
#endif /* __sparcv9 */
#endif /* __sparc */
#endif /* __i386 || __amd64 */
/*
* LWP iteration interface; iterate over all active LWPs.
*/
typedef int proc_lwp_f(void *, const lwpstatus_t *);
/*
* LWP iteration interface; iterate over all LWPs, active and zombie.
*/
/*
* Process iteration interface; iterate over all active processes.
*/
extern int proc_walk(proc_walk_f *, void *, int);
#define PR_WALK_PROC 0 /* walk processes only */
/*
* Determine if an lwp is in a set as returned from proc_arg_xgrab().
*/
extern int proc_lwp_in_set(const char *, lwpid_t);
extern int proc_lwp_range_valid(const char *);
/*
* Symbol table interfaces.
*/
/*
* Pseudo-names passed to Plookup_by_name() for well-known load objects.
* NOTE: It is required that PR_OBJ_EXEC and PR_OBJ_LDSO exactly match
* the definitions of PS_OBJ_EXEC and PS_OBJ_LDSO from <proc_service.h>.
*/
#define PR_OBJ_EXEC ((const char *)0) /* search the executable file */
/*
* Special Lmid_t passed to Plookup_by_lmid() to search all link maps. The
* special values LM_ID_BASE and LM_ID_LDSO from <link.h> may also be used.
* If PR_OBJ_EXEC is used as the object name, the lmid must be PR_LMID_EVERY
* or LM_ID_BASE in order to return a match. If PR_OBJ_LDSO is used as the
* object name, the lmid must be PR_LMID_EVERY or LM_ID_LDSO to return a match.
*/
/*
* 'object_name' is the name of a load object obtained from an
* iteration over the process's address space mappings (Pmapping_iter),
* or an iteration over the process's mapped objects (Pobject_iter),
* or else it is one of the special PR_OBJ_* values above.
*/
extern int Plookup_by_name(struct ps_prochandle *,
const char *, const char *, GElf_Sym *);
extern int Plookup_by_addr(struct ps_prochandle *,
typedef struct prsyminfo {
const char *prs_object; /* object name */
const char *prs_name; /* symbol name */
} prsyminfo_t;
extern int Pxlookup_by_name(struct ps_prochandle *,
extern int Pxlookup_by_addr(struct ps_prochandle *,
typedef int proc_map_f(void *, const prmap_t *, const char *);
Lmid_t, const char *);
const char *);
Lmid_t, const char *);
extern long Pgetauxval(struct ps_prochandle *, int);
extern void Pset_procfs_path(const char *);
/*
* Symbol table iteration interface. The special lmid constants LM_ID_BASE,
* LM_ID_LDSO, and PR_LMID_EVERY may be used with Psymbol_iter_by_lmid.
*/
typedef int proc_sym_f(void *, const GElf_Sym *, const char *);
typedef int proc_xsym_f(void *, const GElf_Sym *, const char *,
const prsyminfo_t *);
extern int Psymbol_iter(struct ps_prochandle *,
const char *, int, int, proc_sym_f *, void *);
extern int Psymbol_iter_by_addr(struct ps_prochandle *,
const char *, int, int, proc_sym_f *, void *);
extern int Psymbol_iter_by_name(struct ps_prochandle *,
const char *, int, int, proc_sym_f *, void *);
extern int Psymbol_iter_by_lmid(struct ps_prochandle *,
Lmid_t, const char *, int, int, proc_sym_f *, void *);
extern int Pxsymbol_iter(struct ps_prochandle *,
Lmid_t, const char *, int, int, proc_xsym_f *, void *);
/*
* 'which' selects which symbol table and can be one of the following.
*/
#define PR_SYMTAB 1
#define PR_DYNSYM 2
/*
* 'type' selects the symbols of interest by binding and type. It is a bit-
* mask of one or more of the following flags, whose order MUST match the
*/
#define BIND_LOCAL 0x0001
#define BIND_GLOBAL 0x0002
#define BIND_WEAK 0x0004
#define TYPE_NOTYPE 0x0100
#define TYPE_OBJECT 0x0200
#define TYPE_FUNC 0x0400
#define TYPE_SECTION 0x0800
#define TYPE_FILE 0x1000
/*
* This returns the rtld_db agent handle for the process.
* The handle will become invalid at the next successful exec() and
* must not be used beyond that point (see Preset_maps(), below).
*/
/*
* This should be called when an RD_DLACTIVITY event with the
* RD_CONSISTENT state occurs via librtld_db's event mechanism.
* This makes libproc's address space mappings and symbol tables current.
* The variant Pupdate_syms() can be used to preload all symbol tables as well.
*/
extern void Pupdate_maps(struct ps_prochandle *);
extern void Pupdate_syms(struct ps_prochandle *);
/*
* This must be called after the victim process performs a successful
* exec() if any of the symbol table interface functions have been called
* prior to that point. This is essential because an exec() invalidates
* all previous symbol table and address space mapping information.
* It is always safe to call, but if it is called other than after an
* exec() by the victim process it just causes unnecessary overhead.
*
* The rtld_db agent handle obtained from a previous call to Prd_agent() is
* made invalid by Preset_maps() and Prd_agent() must be called again to get
* the new handle.
*/
extern void Preset_maps(struct ps_prochandle *);
/*
* Given an address, Ppltdest() determines if this is part of a PLT, and if
* so returns a pointer to the symbol name that will be used for resolution.
* If the specified address is not part of a PLT, the function returns NULL.
*/
/*
* See comments for Pissyscall(), in Pisadep.h
*/
/*
* Stack frame iteration interface.
*/
extern int Pstack_iter(struct ps_prochandle *,
const prgregset_t, proc_stack_f *, void *);
/*
* The following functions define a set of passive interfaces: libproc provides
* default, empty definitions that are called internally. If a client wishes
* to override these definitions, it can simply provide its own version with
* the same signature that interposes on the libproc definition.
*
* If the client program wishes to report additional error information, it
* can provide its own version of Perror_printf.
*
* If the client program wishes to receive a callback after Pcreate forks
* but before it execs, it can provide its own version of Pcreate_callback.
*/
extern void Pcreate_callback(struct ps_prochandle *);
/*
* Remove unprintable characters from psinfo.pr_psargs and replace with
* whitespace characters so it is safe for printing.
*/
extern void proc_unctrl_psinfo(psinfo_t *);
/*
* Utility functions for processing arguments which should be /proc files,
* Pgrab_error() in order to convert it to an error string.
*/
extern struct ps_prochandle *proc_arg_grab(const char *, int, int, int *);
extern struct ps_prochandle *proc_arg_xgrab(const char *, const char *, int,
int, int *, const char **);
const char **);
/*
* Utility functions for obtaining information via /proc without actually
* performing a Pcreate() or Pgrab():
*/
/*
* Utility functions for debugging tools to convert numeric fault,
* signal, and system call numbers to symbolic names:
*/
extern char *proc_fltname(int, char *, size_t);
extern char *proc_signame(int, char *, size_t);
extern char *proc_sysname(int, char *, size_t);
/*
* Utility functions for debugging tools to convert fault, signal, and system
* call names back to the numeric constants:
*/
extern int proc_str2flt(const char *, int *);
extern int proc_str2sig(const char *, int *);
extern int proc_str2sys(const char *, int *);
/*
* Utility functions for debugging tools to convert a fault, signal or system
* call set to a string representation (e.g. "BUS,SEGV" or "open,close,read").
*/
extern char *proc_fltset2str(const fltset_t *, const char *, int,
char *, size_t);
extern char *proc_sigset2str(const sigset_t *, const char *, int,
char *, size_t);
extern char *proc_sysset2str(const sysset_t *, const char *, int,
char *, size_t);
/*
* Utility functions for debugging tools to convert a string representation of
* a fault, signal or system call set back to the numeric value of the
* corresponding set type.
*/
extern char *proc_str2fltset(const char *, const char *, int, fltset_t *);
extern char *proc_str2sigset(const char *, const char *, int, sigset_t *);
extern char *proc_str2sysset(const char *, const char *, int, sysset_t *);
/*
* Utility functions for converting between strings and core_content_t.
*/
extern int proc_str2content(const char *, core_content_t *);
/*
* Utility functions for buffering output to stdout, stderr while
* process is grabbed. Prevents deadlocks due to pfiles `pgrep xterm`
* and other varients.
*/
extern int proc_initstdio(void);
extern int proc_flushstdio(void);
extern int proc_finistdio(void);
#ifdef __cplusplus
}
#endif
#endif /* _LIBPROC_H */