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