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