xref: /titanic_51/usr/src/lib/libtnfctl/prb_proc.h (revision 1e49577a7fcde812700ded04431b49d67cc57d6d)
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 /*
23  * Copyright (c) 1994, by Sun Microsytems, Inc.
24  */
25 
26 #ifndef _PRB_PROC_H
27 #define	_PRB_PROC_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 /*
36  * Header file that gives the interfaces to the proc layer.  These are the
37  * interfaces for "native" /proc i.e. when libtnfctl uses /proc directly
38  * on the target process (tnfctl_exec_open() and tnfctl_pid_open())
39  */
40 
41 /*
42  * Includes
43  */
44 
45 #include <sys/types.h>
46 #include <sys/syscall.h>
47 #include <sys/procfs.h>
48 #include <signal.h>
49 #include <note.h>
50 
51 #include <tnf/probe.h>
52 
53 /*
54  * Typedefs
55  */
56 
57 typedef enum prb_status {
58 	/* successful status */
59 	PRB_STATUS_OK = 0,
60 
61 	/* errors */
62 	/*
63 	 * Status values in the range 1 to -1023 are reserved for mapping
64 	 * standard errno values.
65 	 */
66 	PRB_STATUS_MINERRNO = 1,	/* minimum errno value */
67 	PRB_STATUS_MAXERRNO = 1023,	/* maximum errno value */
68 
69 	PRB_STATUS_ALLOCFAIL,		/* memory allocation failed */
70 	PRB_STATUS_BADARG,		/* bad input argument */
71 	PRB_STATUS_BADSYNC,		/* couldn't sync with rtld */
72 	PRB_STATUS_BADLMAPSTATE		/* inconsistent link map */
73 } prb_status_t;
74 
75 typedef enum prb_syscall_op {
76 	PRB_SYS_ALL,		/* turn on all system calls	 */
77 	PRB_SYS_NONE,		/* clears all system calls	 */
78 	PRB_SYS_ADD,		/* add a system call		 */
79 	PRB_SYS_DEL		/* delete a system call		 */
80 } prb_syscall_op_t;
81 
82 /*
83  * status of /proc file descriptor
84  */
85 typedef struct prb_proc_state {
86 	boolean_t	ps_isstopped;
87 	boolean_t	ps_isinsys;
88 	boolean_t	ps_isrequested;
89 	boolean_t	ps_issysexit;
90 	boolean_t	ps_issysentry;
91 	boolean_t	ps_isbptfault;
92 	long		ps_syscallnum;
93 } prb_proc_state_t;
94 
95 NOTE(SCHEME_PROTECTS_DATA("one thread per handle", prb_proc_state))
96 
97 /*
98  * Opaque /proc handle
99  */
100 typedef struct prb_proc_ctl prb_proc_ctl_t;
101 
102 /*
103  * prb_dbgaddr() has to be called with the address of DT_DEBUG before
104  * most other interfaces in the prb layer can be used.
105  */
106 void		prb_dbgaddr(prb_proc_ctl_t *proc_p, uintptr_t dbgaddr);
107 
108 /*
109  * loadobject iteration callback specification
110  * WARNING: keep this structure in sync with tnfctl_ind_obj_info_t
111  */
112 typedef struct prb_loadobj {
113 	int			objfd;
114 	uintptr_t		text_base;
115 	uintptr_t		data_base;
116 	const char		*objname;
117 } prb_loadobj_t;
118 
119 typedef int prb_loadobj_f(prb_proc_ctl_t *proc_p, const prb_loadobj_t *obj,
120 				void *calldata);
121 prb_status_t	prb_loadobj_iter(prb_proc_ctl_t *, prb_loadobj_f *, void *);
122 prb_status_t	prb_mainobj_get(prb_proc_ctl_t *proc_p, int *objfd,
123 						uintptr_t *baseaddr);
124 
125 const char	*prb_status_str(prb_status_t prbstat);
126 
127 pid_t		prb_proc_pid_get(prb_proc_ctl_t *proc_p);
128 
129 /* rtld interfaces */
130 prb_status_t	prb_rtld_sync_if_needed(prb_proc_ctl_t *proc_p);
131 prb_status_t	prb_rtld_stalk(prb_proc_ctl_t *proc_p);
132 prb_status_t	prb_rtld_unstalk(prb_proc_ctl_t *proc_p);
133 prb_status_t	prb_rtld_advance(prb_proc_ctl_t *proc_p);
134 
135 /* generic /proc wrapper interfaces */
136 prb_status_t	prb_proc_open(pid_t pid, prb_proc_ctl_t **proc_pp);
137 prb_status_t	prb_proc_reopen(pid_t pid, prb_proc_ctl_t **proc_pp);
138 prb_status_t	prb_proc_close(prb_proc_ctl_t *proc_p);
139 prb_status_t	prb_proc_stop(prb_proc_ctl_t *proc_p);
140 prb_status_t	prb_proc_wait(prb_proc_ctl_t *proc_p, boolean_t use_sigmask,
141 					sigset_t *oldmask);
142 prb_status_t	prb_proc_cont(prb_proc_ctl_t *proc_p);
143 prb_status_t	prb_proc_state(prb_proc_ctl_t *proc_p,
144 					prb_proc_state_t * state_p);
145 prb_status_t	prb_proc_setrlc(prb_proc_ctl_t *proc_p, boolean_t rlc);
146 prb_status_t	prb_proc_setklc(prb_proc_ctl_t *proc_p, boolean_t klc);
147 prb_status_t	prb_proc_exit(prb_proc_ctl_t *proc_p, uint_t syscall,
148 					prb_syscall_op_t op);
149 prb_status_t	prb_proc_entry(prb_proc_ctl_t *proc_p, uint_t syscall,
150 					prb_syscall_op_t op);
151 prb_status_t	prb_proc_read(prb_proc_ctl_t *proc_p, uintptr_t addr,
152 	void *buf, size_t size);
153 prb_status_t	prb_proc_write(prb_proc_ctl_t *proc_p, uintptr_t addr,
154 	void *buf, size_t size);
155 prb_status_t    prb_proc_setfork(prb_proc_ctl_t *proc_p, boolean_t inhfork);
156 prb_status_t	prb_proc_get_r0_r1(prb_proc_ctl_t *proc_p,
157     prgreg_t *r0, prgreg_t *r1);
158 
159 /* exec a child */
160 prb_status_t	prb_child_create(const char *cmdname, char * const *cmdargs,
161 	const char *loption, const char *libtnfprobe_path,
162 	char * const *envp, prb_proc_ctl_t **ret_val);
163 
164 #ifdef __cplusplus
165 }
166 #endif
167 
168 #endif	/* _PRB_PROC_H */
169