xref: /titanic_51/usr/src/lib/libproc/common/llib-lproc (revision bbaa8b60dd95d714741fc474adad3cf710ef4efd)
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21/* LINTLIBRARY */
22/* PROTOLIB1 */
23
24/*
25 * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
26 * Use is subject to license terms.
27 */
28/*
29 * Copyright (c) 2013 by Delphix. All rights reserved.
30 */
31#include "libproc.h"
32
33/*
34 * usr/src/lib/libproc
35 */
36
37/* Pcontrol.c */
38int	_libproc_debug;
39struct ps_prochandle *Pcreate(const char *file, char *const *argv,
40		int *perr, char *path, size_t len);
41const char *Pcreate_error(int error);
42void	Pcreate_callback(struct ps_prochandle *Pr);
43struct ps_prochandle *Pgrab(pid_t pid, int gflag, int *perr);
44const char *Pgrab_error(int error);
45void	Pfree(struct ps_prochandle *Pr);
46int	Pstate(struct ps_prochandle *Pr);
47int	Pasfd(struct ps_prochandle *Pr);
48int	Pctlfd(struct ps_prochandle *Pr);
49const psinfo_t *Ppsinfo(struct ps_prochandle *Pr);
50const pstatus_t *Pstatus(struct ps_prochandle *Pr);
51int	Pcred(struct ps_prochandle *Pr, prcred_t *pcrp, int ngroups);
52int	Ppriv(struct ps_prochandle *Pr, prpriv_t **pprivp);
53void	Psync(struct ps_prochandle *Pr);
54int	Pcreate_agent(struct ps_prochandle *Pr);
55void	Pdestroy_agent(struct ps_prochandle *Pr);
56int	Preopen(struct ps_prochandle *Pr);
57void	Prelease(struct ps_prochandle *Pr, int flags);
58int	Pstopstatus(struct ps_prochandle *Pr, long cmd, uint_t msec);
59int	Pwait(struct ps_prochandle *Pr, uint_t msec);
60int	Pstop(struct ps_prochandle *Pr, uint_t msec);
61int	Pdstop(struct ps_prochandle *Pr);
62int	Pgetareg(struct ps_prochandle *Pr, int regno, prgreg_t *preg);
63int	Pputareg(struct ps_prochandle *Pr, int regno, prgreg_t reg);
64int	Psetrun(struct ps_prochandle *Pr, int sig, int flags);
65ssize_t	Pread(struct ps_prochandle *Pr,
66		void *buf, size_t nbyte, uintptr_t address);
67ssize_t	Pread_string(struct ps_prochandle *Pr,
68		char *buf, size_t nbyte, uintptr_t address);
69ssize_t	Pwrite(struct ps_prochandle *Pr,
70		const void *buf, size_t nbyte, uintptr_t address);
71int	Pclearsig(struct ps_prochandle *Pr);
72int	Pclearfault(struct ps_prochandle *Pr);
73int	Psetbkpt(struct ps_prochandle *Pr, uintptr_t address, ulong_t *saved);
74int	Pdelbkpt(struct ps_prochandle *Pr, uintptr_t address, ulong_t saved);
75int	Pxecbkpt(struct ps_prochandle *Pr, ulong_t saved);
76int	Psetwapt(struct ps_prochandle *Pr, const prwatch_t *wp);
77int	Pdelwapt(struct ps_prochandle *Pr, const prwatch_t *wp);
78int	Pxecwapt(struct ps_prochandle *Pr, const prwatch_t *wp);
79int	Psetflags(struct ps_prochandle *Pr, long flags);
80int	Punsetflags(struct ps_prochandle *Pr, long flags);
81int	Psignal(struct ps_prochandle *Pr, int which, int stop);
82void	Psetsignal(struct ps_prochandle *Pr, const sigset_t *set);
83int	Pfault(struct ps_prochandle *Pr, int which, int stop);
84void	Psetfault(struct ps_prochandle *Pr, const fltset_t *set);
85int	Psysentry(struct ps_prochandle *Pr, int which, int stop);
86void	Psetsysentry(struct ps_prochandle *Pr, const sysset_t *set);
87int	Psysexit(struct ps_prochandle *Pr, int which, int stop);
88void	Psetsysexit(struct ps_prochandle *Pr, const sysset_t *set);
89int	Plwp_iter(struct ps_prochandle *Pr, proc_lwp_f *func, void *cd);
90int	Psyscall(struct ps_prochandle *Pr, sysret_t *,
91		int sysindex, uint_t nargs, argdes_t *argp);
92
93struct ps_lwphandle *Lgrab(struct ps_prochandle *P, lwpid_t lwpid, int *perr);
94const char *Lgrab_error(int error);
95struct ps_prochandle *Lprochandle(struct ps_lwphandle *Lwp);
96void	Lfree(struct ps_lwphandle *Lwp);
97int	Lctlfd(struct ps_lwphandle *Lwp);
98int	Lwait(struct ps_lwphandle *Lwp, uint_t msec);
99int	Lstop(struct ps_lwphandle *Lwp, uint_t msec);
100int	Ldstop(struct ps_lwphandle *Lwp);
101int	Lstate(struct ps_lwphandle *Lwp);
102const lwpsinfo_t *Lpsinfo(struct ps_lwphandle *Lwp);
103const lwpstatus_t *Lstatus(struct ps_lwphandle *Lwp);
104int	Lgetareg(struct ps_lwphandle *Lwp, int regno, prgreg_t *preg);
105int	Lputareg(struct ps_lwphandle *Lwp, int regno, prgreg_t reg);
106int	Lsetrun(struct ps_lwphandle *Lwp, int sig, int flags);
107int	Lclearsig(struct ps_lwphandle *Lwp);
108int	Lclearfault(struct ps_lwphandle *Lwp);
109int	Lxecbkpt(struct ps_lwphandle *Lwp, ulong_t saved);
110int	Lxecwapt(struct ps_lwphandle *Lwp, const prwatch_t *wp);
111void	Lsync(struct ps_lwphandle *Lwp);
112
113/* Plwpregs.c */
114int Plwp_getregs(struct ps_prochandle *Pr, lwpid_t i, prgregset_t gr);
115int Plwp_setregs(struct ps_prochandle *Pr, lwpid_t i, const prgregset_t gr);
116int Plwp_getfpregs(struct ps_prochandle *Pr, lwpid_t i, prfpregset_t *fp);
117int Plwp_setfpregs(struct ps_prochandle *Pr, lwpid_t i, const prfpregset_t *fp);
118#if defined(sparc) || defined(__sparc)
119int Plwp_getxregs(struct ps_prochandle *Pr, lwpid_t i, prxregset_t *xr);
120int Plwp_setxregs(struct ps_prochandle *Pr, lwpid_t i, const prxregset_t *xr);
121#if defined(__sparcv9)
122int Plwp_getasrs(struct ps_prochandle *Pr, lwpid_t i, asrset_t asrs);
123int Plwp_setasrs(struct ps_prochandle *Pr, lwpid_t i, const asrset_t asrs);
124#endif  /* __sparcv9 */
125#endif  /* __sparc */
126int Plwp_getpsinfo(struct ps_prochandle *Pr, lwpid_t i, lwpsinfo_t *lps);
127
128/* Pcore.c */
129struct ps_prochandle *Pfgrab_core(int fd, const char *aout, int *perr);
130struct ps_prochandle *Pgrab_core(const char *core, const char *aout,
131	int gflag, int *perr);
132
133/* Pisprocdir.c */
134int	Pisprocdir(struct ps_prochandle *Pr, const char *dir);
135
136/* Pservice.c */
137ps_err_e ps_pdmodel(struct ps_prochandle *Pr, int *modelp);
138ps_err_e ps_pread(struct ps_prochandle *Pr,
139		psaddr_t addr, void *buf, size_t size);
140ps_err_e ps_pwrite(struct ps_prochandle *Pr,
141		psaddr_t addr, const void *buf, size_t size);
142ps_err_e ps_pdread(struct ps_prochandle *Pr,
143		psaddr_t addr, void *buf, size_t size);
144ps_err_e ps_pdwrite(struct ps_prochandle *Pr,
145		psaddr_t addr, const void *buf, size_t size);
146ps_err_e ps_ptread(struct ps_prochandle *Pr,
147		psaddr_t addr, void *buf, size_t size);
148ps_err_e ps_ptwrite(struct ps_prochandle *Pr,
149		psaddr_t addr, const void *buf, size_t size);
150ps_err_e ps_pstop(struct ps_prochandle *Pr);
151ps_err_e ps_pcontinue(struct ps_prochandle *Pr);
152ps_err_e ps_lstop(struct ps_prochandle *Pr, lwpid_t lwpid);
153ps_err_e ps_lcontinue(struct ps_prochandle *Pr, lwpid_t lwpid);
154ps_err_e ps_lgetregs(struct ps_prochandle *Pr,
155		lwpid_t lwpid, prgregset_t regs);
156ps_err_e ps_lsetregs(struct ps_prochandle *Pr,
157		lwpid_t lwpid, const prgregset_t regs);
158ps_err_e ps_lgetfpregs(struct ps_prochandle *Pr,
159		lwpid_t lwpid, prfpregset_t *regs);
160ps_err_e ps_lsetfpregs(struct ps_prochandle *Pr,
161		lwpid_t lwpid, const prfpregset_t *regs);
162#if defined(sparc) || defined(__sparc)
163ps_err_e ps_lgetxregsize(struct ps_prochandle *Pr,
164		lwpid_t lwpid, int *xrsize);
165ps_err_e ps_lgetxregs(struct ps_prochandle *Pr,
166		lwpid_t lwpid, caddr_t xregs);
167ps_err_e ps_lsetxregs(struct ps_prochandle *Pr,
168		lwpid_t lwpid, caddr_t xregs);
169#endif	/* sparc */
170#if defined(__i386) || defined(__amd64)
171ps_err_e ps_lgetLDT(struct ps_prochandle *Pr,
172		lwpid_t lwpid, struct ssd *ldt);
173#endif	/* __i386 || __amd6464 */
174void	ps_plog(const char *fmt, ...);
175
176/* Psymtab.c */
177void	Pupdate_maps(struct ps_prochandle *Pr);
178void	Pupdate_syms(struct ps_prochandle *Pr);
179rd_agent_t *Prd_agent(struct ps_prochandle *Pr);
180const prmap_t *Paddr_to_map(struct ps_prochandle *Pr, uintptr_t addr);
181const prmap_t *Paddr_to_text_map(struct ps_prochandle *Pr, uintptr_t addr);
182const prmap_t *Pname_to_map(struct ps_prochandle *Pr, const char *name);
183const prmap_t *Plmid_to_map(struct ps_prochandle *Pr, Lmid_t lmid,
184		const char *name);
185int	Plookup_by_addr(struct ps_prochandle *Pr, uintptr_t addr,
186		char *sym_name_buffer, size_t bufsize, GElf_Sym *symbolp);
187int	Plookup_by_name(struct ps_prochandle *Pr,
188		const char *object_name, const char *symbol_name,
189		GElf_Sym *sym);
190int	Plookup_by_lmid(struct ps_prochandle *Pr,
191		Lmid_t lmid, const char *object_name, const char *symbol_name,
192		GElf_Sym *sym);
193const rd_loadobj_t *Paddr_to_loadobj(struct ps_prochandle *, uintptr_t);
194const rd_loadobj_t *Pname_to_loadobj(struct ps_prochandle *, const char *);
195const rd_loadobj_t *Plmid_to_loadobj(struct ps_prochandle *, Lmid_t,
196		const char *);
197int	Pmapping_iter(struct ps_prochandle *Pr, proc_map_f *func, void *cd);
198int	Pmapping_iter_resolved(struct ps_prochandle *Pr, proc_map_f *func,
199		void *cd);
200int	Pobject_iter(struct ps_prochandle *Pr, proc_map_f *func, void *cd);
201int	Pobject_iter_resolved(struct ps_prochandle *Pr, proc_map_f *func,
202		void *cd);
203char	*Pobjname(struct ps_prochandle *Pr, uintptr_t addr,
204		char *buffer, size_t bufsize);
205char	*Pobjname_resolved(struct ps_prochandle *Pr, uintptr_t addr,
206		char *buffer, size_t bufsize);
207int	Plmid(struct ps_prochandle *Pr, uintptr_t addr, Lmid_t *lmidp);
208int	Psymbol_iter(struct ps_prochandle *Pr, const char *object_name,
209		int which, int type, proc_sym_f *func, void *cd);
210int	Psymbol_iter_by_lmid(struct ps_prochandle *Pr, Lmid_t lmid,
211		const char *object_name, int which, int type,
212		proc_sym_f *func, void *cd);
213char	*Pgetenv(struct ps_prochandle *Pr, const char *name,
214		char *buffer, size_t bufsize);
215char	*Pplatform(struct ps_prochandle *Pr, char *s, size_t n);
216int	Puname(struct ps_prochandle *Pr, struct utsname *u);
217char	*Pzonename(struct ps_prochandle *Pr, char *s, size_t n);
218char	*Pfindobj(struct ps_prochandle *Pr, const char *path,
219		char *s, size_t n);
220char	*Pexecname(struct ps_prochandle *Pr, char *buffer, size_t bufsize);
221void	Preset_maps(struct ps_prochandle *Pr);
222
223ps_err_e ps_pglobal_lookup(struct ps_prochandle *Pr,
224		const char *object_name, const char *sym_name,
225		psaddr_t *sym_addr);
226
227ps_err_e ps_pglobal_sym(struct ps_prochandle *Pr,
228		const char *object_name, const char *sym_name,
229		ps_sym_t *symp);
230
231long	Pgetauxval(struct ps_prochandle *Pr, int type);
232const auxv_t *Pgetauxvec(struct ps_prochandle *Pr);
233ps_err_e ps_pauxv(struct ps_prochandle *Pr, const auxv_t **aux);
234
235/* Putil.c */
236void	Perror_printf(struct ps_prochandle *Pr, const char *format, ...);
237
238/* pr_door.c */
239int	pr_door_info(struct ps_prochandle *Pr, int did, door_info_t *di);
240
241/* pr_exit.c */
242int	pr_exit(struct ps_prochandle *Pr, int status);
243int	pr_lwp_exit(struct ps_prochandle *Pr);
244
245/* pr_fcntl.c */
246int	pr_fcntl(struct ps_prochandle *Pr, int fd, int cmd, void *argp);
247
248/* pr_getitimer.c */
249int	pr_getitimer(struct ps_prochandle *Pr,
250		int which, struct itimerval *itv);
251int	pr_setitimer(struct ps_prochandle *Pr,
252		int which, const struct itimerval *itv, struct itimerval *oitv);
253
254/* pr_getrctl.c */
255int	pr_getrctl(struct ps_prochandle *Pr, const char *rname,
256		rctlblk_t *old_blk, rctlblk_t *new_blk, int rflag);
257int   pr_setrctl(struct ps_prochandle *Pr, const char *rname,
258		rctlblk_t *old_blk, rctlblk_t *new_blk, int rflag);
259int   pr_setprojrctl(struct ps_prochandle *Pr, const char *rname,
260		rctlblk_t *new_blk, size_t size, int rflag);
261
262/* pr_getrlimit.c */
263int	pr_getrlimit(struct ps_prochandle *Pr,
264		int resource, struct rlimit *rlp);
265int	pr_setrlimit(struct ps_prochandle *Pr,
266		int resource, const struct rlimit *rlp);
267int	pr_getrlimit64(struct ps_prochandle *Pr,
268		int resource, struct rlimit64 *rlp);
269int	pr_setrlimit64(struct ps_prochandle *Pr,
270		int resource, const struct rlimit64 *rlp);
271
272/* pr_getsockname.c */
273int	pr_getsockname(struct ps_prochandle *Pr,
274		int sock, struct sockaddr *name, socklen_t *namelen);
275int	pr_getpeername(struct ps_prochandle *Pr,
276		int sock, struct sockaddr *name, socklen_t *namelen);
277
278/* pr_ioctl.c */
279int	pr_ioctl(struct ps_prochandle *Pr,
280		int fd, int code, void *buf, size_t size);
281
282/* pr_lseek.c */
283off_t	pr_lseek(struct ps_prochandle *Pr,
284		int filedes, off_t offset, int whence);
285offset_t pr_llseek(struct ps_prochandle *Pr,
286		int filedes, offset_t offset, int whence);
287
288/* pr_memcntl.c */
289int	pr_memcntl(struct ps_prochandle *Pr,
290	caddr_t addr, size_t len, int cmd, caddr_t arg, int attr, int mask);
291
292/* pr_mmap.c */
293void	*pr_mmap(struct ps_prochandle *Pr,
294		void *addr, size_t len, int prot, int flags, int fd, off_t off);
295int	pr_munmap(struct ps_prochandle *Pr,
296		void *addr, size_t len);
297void	*pr_zmap(struct ps_prochandle *Pr,
298		void *addr, size_t len, int prot, int flags);
299
300/* pr_open.c */
301int	pr_open(struct ps_prochandle *Pr,
302		const char *filename, int flags, mode_t mode);
303int	pr_creat(struct ps_prochandle *Pr,
304		const char *filename, mode_t mode);
305int	pr_close(struct ps_prochandle *Pr, int fd);
306int	pr_access(struct ps_prochandle *Pr, const char *path, int amode);
307
308/* pr_pbind.c */
309int	pr_processor_bind(struct ps_prochandle *Pr, idtype_t, id_t, int, int *);
310
311/* pr_rename.c */
312int	pr_rename(struct ps_prochandle *Pr, const char *old, const char *new);
313int	pr_link(struct ps_prochandle *Pr, const char *exist, const char *new);
314int	pr_unlink(struct ps_prochandle *Pr, const char *);
315
316/* pr_sigaction.c */
317int	pr_sigaction(struct ps_prochandle *Pr,
318		int sig, const struct sigaction *act, struct sigaction *oact);
319
320/* pr_stat.c */
321int	pr_stat(struct ps_prochandle *Pr, const char *path, struct stat *buf);
322int	pr_lstat(struct ps_prochandle *Pr, const char *path, struct stat *buf);
323int	pr_fstat(struct ps_prochandle *Pr, int fd, struct stat *buf);
324int	pr_stat64(struct ps_prochandle *Pr, const char *path,
325		struct stat64 *buf);
326int	pr_lstat64(struct ps_prochandle *Pr, const char *path,
327		struct stat64 *buf);
328int	pr_fstat64(struct ps_prochandle *Pr, int fd, struct stat64 *buf);
329
330/* pr_statvfs.c */
331int	pr_statvfs(struct ps_prochandle *Pr, const char *path, statvfs_t *buf);
332int	pr_fstatvfs(struct ps_prochandle *Pr, int fd, statvfs_t *buf);
333
334/* pr_tasksys.c */
335projid_t pr_getprojid(struct ps_prochandle *Pr);
336taskid_t pr_gettaskid(struct ps_prochandle *Pr);
337taskid_t pr_settaskid(struct ps_prochandle *Pr, projid_t project, int flags);
338
339/* pr_waitid.c */
340int	pr_waitid(struct ps_prochandle *Pr,
341		idtype_t idtype, id_t id, siginfo_t *infop, int options);
342
343/* proc_get_info.c */
344int	proc_get_cred(pid_t pid, prcred_t *credp, int ngroups);
345prpriv_t *proc_get_priv(pid_t pid);
346int	proc_get_psinfo(pid_t pid, psinfo_t *psp);
347int	proc_get_status(pid_t pid, pstatus_t *psp);
348int	proc_get_auxv(pid_t pid, auxv_t *pauxv, int naux);
349
350/* proc_names.c */
351char	*proc_fltname(int flt, char *buf, size_t bufsz);
352char	*proc_signame(int sig, char *buf, size_t bufsz);
353char	*proc_sysname(int sys, char *buf, size_t bufsz);
354
355int	proc_str2flt(const char *str, int *fltnum);
356int	proc_str2sig(const char *str, int *signum);
357int	proc_str2sys(const char *str, int *sysnum);
358
359char	*proc_fltset2str(const fltset_t *set, const char *delim, int members,
360		char *buf, size_t nbytes);
361char	*proc_sigset2str(const sigset_t *set, const char *delim, int members,
362		char *buf, size_t nbytes);
363char	*proc_sysset2str(const sysset_t *set, const char *delim, int members,
364		char *buf, size_t nbytes);
365
366char	*proc_str2fltset(const char *str, const char *delim, int members,
367		fltset_t *set);
368char	*proc_str2sigset(const char *str, const char *delim, int members,
369		sigset_t *set);
370char	*proc_str2sysset(const char *str, const char *delim, int members,
371		sysset_t *set);
372
373int	proc_walk(proc_walk_f *func, void *arg, int flags);
374
375/* proc_arg.c */
376struct ps_prochandle *proc_arg_grab(const char *arg,
377	int oflag, int gflag, int *perr);
378
379pid_t	proc_arg_psinfo(const char *arg, int oflag, psinfo_t *psp, int *perr);
380void	proc_unctrl_psinfo(psinfo_t *psp);
381
382/* proc_set.c */
383int	Psetcred(struct ps_prochandle *Pr, const prcred_t *pcred);
384
385/* Pstack.c */
386int	Pstack_iter(struct ps_prochandle *Pr,
387		const prgregset_t regs, proc_stack_f *func, void *arg);
388
389/* Pisadep.c */
390const char *Ppltdest(struct ps_prochandle *Pr, uintptr_t addr);
391