xref: /titanic_52/usr/src/lib/libproc/common/llib-lproc (revision 06e46062ef4f5f4b687cbafb4518fb123fe23920)
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, Version 1.0 only
6 * (the "License").  You may not use this file except in compliance
7 * with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22/* LINTLIBRARY */
23/* PROTOLIB1 */
24
25/*
26 * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
27 * Use is subject to license terms.
28 */
29#pragma ident	"%Z%%M%	%I%	%E% SMI"
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);
52ssize_t	Ppriv(struct ps_prochandle *Pr, prpriv_t *pprivp, size_t);
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	Pobject_iter(struct ps_prochandle *Pr, proc_map_f *func, void *cd);
199char	*Pobjname(struct ps_prochandle *Pr, uintptr_t addr,
200		char *buffer, size_t bufsize);
201int	Plmid(struct ps_prochandle *Pr, uintptr_t addr, Lmid_t *lmidp);
202int	Psymbol_iter(struct ps_prochandle *Pr, const char *object_name,
203		int which, int type, proc_sym_f *func, void *cd);
204int	Psymbol_iter_by_lmid(struct ps_prochandle *Pr, Lmid_t lmid,
205		const char *object_name, int which, int type,
206		proc_sym_f *func, void *cd);
207char	*Pgetenv(struct ps_prochandle *Pr, const char *name,
208		char *buffer, size_t bufsize);
209char	*Pplatform(struct ps_prochandle *Pr, char *s, size_t n);
210int	Puname(struct ps_prochandle *Pr, struct utsname *u);
211char	*Pzonename(struct ps_prochandle *Pr, char *s, size_t n);
212char	*Pexecname(struct ps_prochandle *Pr, char *buffer, size_t bufsize);
213void	Preset_maps(struct ps_prochandle *Pr);
214
215ps_err_e ps_pglobal_lookup(struct ps_prochandle *Pr,
216		const char *object_name, const char *sym_name,
217		psaddr_t *sym_addr);
218
219ps_err_e ps_pglobal_sym(struct ps_prochandle *Pr,
220		const char *object_name, const char *sym_name,
221		ps_sym_t *symp);
222
223long	Pgetauxval(struct ps_prochandle *Pr, int type);
224const auxv_t *Pgetauxvec(struct ps_prochandle *Pr);
225ps_err_e ps_pauxv(struct ps_prochandle *Pr, const auxv_t **aux);
226
227/* Putil.c */
228void	Perror_printf(struct ps_prochandle *Pr, const char *format, ...);
229
230/* pr_door.c */
231int	pr_door_info(struct ps_prochandle *Pr, int did, door_info_t *di);
232
233/* pr_exit.c */
234int	pr_exit(struct ps_prochandle *Pr, int status);
235int	pr_lwp_exit(struct ps_prochandle *Pr);
236
237/* pr_fcntl.c */
238int	pr_fcntl(struct ps_prochandle *Pr, int fd, int cmd, void *argp);
239
240/* pr_getitimer.c */
241int	pr_getitimer(struct ps_prochandle *Pr,
242		int which, struct itimerval *itv);
243int	pr_setitimer(struct ps_prochandle *Pr,
244		int which, const struct itimerval *itv, struct itimerval *oitv);
245
246/* pr_getrctl.c */
247int	pr_getrctl(struct ps_prochandle *Pr, const char *rname,
248		rctlblk_t *old_blk, rctlblk_t *new_blk, int rflag);
249int   pr_setrctl(struct ps_prochandle *Pr, const char *rname,
250		rctlblk_t *old_blk, rctlblk_t *new_blk, int rflag);
251
252/* pr_getrlimit.c */
253int	pr_getrlimit(struct ps_prochandle *Pr,
254		int resource, struct rlimit *rlp);
255int	pr_setrlimit(struct ps_prochandle *Pr,
256		int resource, const struct rlimit *rlp);
257int	pr_getrlimit64(struct ps_prochandle *Pr,
258		int resource, struct rlimit64 *rlp);
259int	pr_setrlimit64(struct ps_prochandle *Pr,
260		int resource, const struct rlimit64 *rlp);
261
262/* pr_getsockname.c */
263int	pr_getsockname(struct ps_prochandle *Pr,
264		int sock, struct sockaddr *name, socklen_t *namelen);
265int	pr_getpeername(struct ps_prochandle *Pr,
266		int sock, struct sockaddr *name, socklen_t *namelen);
267
268/* pr_ioctl.c */
269int	pr_ioctl(struct ps_prochandle *Pr,
270		int fd, int code, void *buf, size_t size);
271
272/* pr_lseek.c */
273off_t	pr_lseek(struct ps_prochandle *Pr,
274		int filedes, off_t offset, int whence);
275offset_t pr_llseek(struct ps_prochandle *Pr,
276		int filedes, offset_t offset, int whence);
277
278/* pr_memcntl.c */
279int	pr_memcntl(struct ps_prochandle *Pr,
280	caddr_t addr, size_t len, int cmd, caddr_t arg, int attr, int mask);
281
282/* pr_mmap.c */
283void	*pr_mmap(struct ps_prochandle *Pr,
284		void *addr, size_t len, int prot, int flags, int fd, off_t off);
285int	pr_munmap(struct ps_prochandle *Pr,
286		void *addr, size_t len);
287void	*pr_zmap(struct ps_prochandle *Pr,
288		void *addr, size_t len, int prot, int flags);
289
290/* pr_open.c */
291int	pr_open(struct ps_prochandle *Pr,
292		const char *filename, int flags, mode_t mode);
293int	pr_creat(struct ps_prochandle *Pr,
294		const char *filename, mode_t mode);
295int	pr_close(struct ps_prochandle *Pr, int fd);
296int	pr_access(struct ps_prochandle *Pr, const char *path, int amode);
297
298/* pr_pbind.c */
299int	pr_processor_bind(struct ps_prochandle *Pr, idtype_t, id_t, int, int *);
300int	pr_pset_bind(struct ps_prochandle *Pr, int, idtype_t, id_t, int *);
301
302/* pr_rename.c */
303int	pr_rename(struct ps_prochandle *Pr, const char *old, const char *new);
304int	pr_link(struct ps_prochandle *Pr, const char *exist, const char *new);
305int	pr_unlink(struct ps_prochandle *Pr, const char *);
306
307/* pr_sigaction.c */
308int	pr_sigaction(struct ps_prochandle *Pr,
309		int sig, const struct sigaction *act, struct sigaction *oact);
310
311/* pr_stat.c */
312int	pr_stat(struct ps_prochandle *Pr, const char *path, struct stat *buf);
313int	pr_lstat(struct ps_prochandle *Pr, const char *path, struct stat *buf);
314int	pr_fstat(struct ps_prochandle *Pr, int fd, struct stat *buf);
315int	pr_stat64(struct ps_prochandle *Pr, const char *path,
316		struct stat64 *buf);
317int	pr_lstat64(struct ps_prochandle *Pr, const char *path,
318		struct stat64 *buf);
319int	pr_fstat64(struct ps_prochandle *Pr, int fd, struct stat64 *buf);
320
321/* pr_statvfs.c */
322int	pr_statvfs(struct ps_prochandle *Pr, const char *path, statvfs_t *buf);
323int	pr_fstatvfs(struct ps_prochandle *Pr, int fd, statvfs_t *buf);
324
325/* pr_tasksys.c */
326projid_t pr_getprojid(struct ps_prochandle *Pr);
327taskid_t pr_gettaskid(struct ps_prochandle *Pr);
328taskid_t pr_settaskid(struct ps_prochandle *Pr, projid_t project, int flags);
329
330/* pr_waitid.c */
331int	pr_waitid(struct ps_prochandle *Pr,
332		idtype_t idtype, id_t id, siginfo_t *infop, int options);
333
334/* proc_get_info.c */
335int	proc_get_cred(pid_t pid, prcred_t *credp, int ngroups);
336prpriv_t *proc_get_priv(pid_t pid);
337int	proc_get_psinfo(pid_t pid, psinfo_t *psp);
338int	proc_get_status(pid_t pid, pstatus_t *psp);
339int	proc_get_auxv(pid_t pid, auxv_t *pauxv, int naux);
340
341/* proc_names.c */
342char	*proc_fltname(int flt, char *buf, size_t bufsz);
343char	*proc_signame(int sig, char *buf, size_t bufsz);
344char	*proc_sysname(int sys, char *buf, size_t bufsz);
345
346int	proc_str2flt(const char *str, int *fltnum);
347int	proc_str2sig(const char *str, int *signum);
348int	proc_str2sys(const char *str, int *sysnum);
349
350char	*proc_fltset2str(const fltset_t *set, const char *delim, int members,
351		char *buf, size_t nbytes);
352char	*proc_sigset2str(const sigset_t *set, const char *delim, int members,
353		char *buf, size_t nbytes);
354char	*proc_sysset2str(const sysset_t *set, const char *delim, int members,
355		char *buf, size_t nbytes);
356
357char	*proc_str2fltset(const char *str, const char *delim, int members,
358		fltset_t *set);
359char	*proc_str2sigset(const char *str, const char *delim, int members,
360		sigset_t *set);
361char	*proc_str2sysset(const char *str, const char *delim, int members,
362		sysset_t *set);
363
364int	proc_walk(proc_walk_f *func, void *arg, int flags);
365
366/* proc_arg.c */
367struct ps_prochandle *proc_arg_grab(const char *arg,
368	int oflag, int gflag, int *perr);
369
370pid_t	proc_arg_psinfo(const char *arg, int oflag, psinfo_t *psp, int *perr);
371void	proc_unctrl_psinfo(psinfo_t *psp);
372
373/* proc_set.c */
374int	Psetcred(struct ps_prochandle *Pr, const prcred_t *pcred);
375
376/* Pstack.c */
377int	Pstack_iter(struct ps_prochandle *Pr,
378		const prgregset_t regs, proc_stack_f *func, void *arg);
379
380/* Pisadep.c */
381const char *Ppltdest(struct ps_prochandle *Pr, uintptr_t addr);
382