summaryrefslogtreecommitdiff
path: root/usr/src/man/man3tnf/tnfctl_indirect_open.3tnf
blob: 4457f8d54aa09b47579fe8b1474e565cf6162b85 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
'\" te
.\"  Copyright (c) 2004 Sun Microsystems, Inc.  All Rights Reserved
.\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
.\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
.TH TNFCTL_INDIRECT_OPEN 3TNF "August 29, 2021"
.SH NAME
tnfctl_indirect_open, tnfctl_check_libs \- control probes of another process
where caller provides /proc functionality
.SH SYNOPSIS
.nf
\fBcc\fR [ \fIflag\fR ... ] \fIfile\fR ... \fB-ltnfctl\fR [ \fIlibrary\fR ... ]
#include <tnf/tnfctl.h>

\fBtnfctl_errcode_t\fR \fBtnfctl_indirect_open\fR(\fBvoid *\fR\fIprochandle\fR,
     \fBtnfctl_ind_config_t *\fR\fIconfig\fR, \fBtnfctl_handle_t **\fR\fIret_val\fR);
.fi

.LP
.nf
\fBtnfctl_errcode_t\fR \fBtnfctl_check_libs\fR(\fBtnfctl_handle_t *\fR\fIhndl\fR);
.fi

.SH DESCRIPTION
The interfaces  \fBtnfctl_indirect_open()\fR and \fBtnfctl_check_libs()\fR are
used to control probes in another process where the \fBlibtnfctl\fR(3TNF)
client has already opened  \fBproc\fR(4) on the target process. An example of
this is when the client is a debugger. Since these clients already use
\fB/proc\fR on the target, \fBlibtnfctl\fR(3TNF) cannot use \fB/proc\fR
directly.  Therefore, these clients must provide callback functions that can be
used to inspect and to update the target process.   The target process must
load \fBlibtnfprobe.so.1\fR (defined in \fB<tnf/tnfctl.h>\fR as macro
\fBTNFCTL_LIBTNFPROBE).\fR
.sp
.LP
The first argument \fIprochandle\fR is a pointer to an opaque structure that is
used in the callback functions that inspect and update the target process.
This structure should encapsulate the state that the caller needs to use
\fB/proc\fR on the target process (the  \fB/proc\fR file descriptor). The
second argument, \fIconfig\fR, is a pointer to
.sp
.in +2
.nf
typedef
struct tnfctl_ind_config {
	int (*p_read)(void *prochandle, paddr_t addr, char *buf,
					size_t size);
	int (*p_write)(void *prochandle, paddr_t addr, char *buf,
					size_t size);
	pid_t (*p_getpid)(void *prochandle);
	int (*p_obj_iter)(void *prochandle, tnfctl_ind_obj_f *func,
					void *client_data);
} tnfctl_ind_config_t;
.fi
.in -2

.sp
.LP
The first field  \fIp_read\fR is the address of a function that can read
\fBsize\fR bytes at address \fIaddr\fR in the target image into the buffer
\fIbuf\fR. The function should return  \fB0\fR upon success. The second field
\fIp_write\fR is the address of a function that can write  \fBsize\fR bytes at
address \fIaddr\fR in the target image from the buffer \fIbuf\fR. The function
should return \fB0\fR upon success. The third field \fIp_getpid\fR is the
address of a function that should return the process id of the target process
(\fIprochandle\fR). The fourth field  \fIp_obj_iter\fR is the address of a
function that iterates over all load objects  and the executable by calling the
callback function  \fIfunc\fR with  \fIclient_data\fR. If \fIfunc\fR returns
\fB0\fR, \fIp_obj_iter\fR should continue processing link objects.  If
\fIfunc\fR returns any other value, \fIp_obj_iter\fR should stop calling the
callback function and return that value. \fIp_obj_iter\fR should return
\fB0\fR if it iterates over all load objects.
.sp
.LP
If a failure is returned by any of the functions in \fIconfig\fR, the error is
propagated back as \fBPREX_ERR_INTERNAL\fR by the \fBlibtnfctl\fR interface
that called it.
.sp
.LP
The definition of  \fBtnfctl_ind_obj_f\fR is:
.sp
.in +2
.nf
typedef int
tnfctl_ind_obj_f(void *prochandle,
	const struct tnfctl_ind_obj_info *obj
	void *client_data);
typedef struct tnfctl_ind_obj_info {
	int     objfd;			/* -1 indicates fd not available */
	paddr_t text_base;		/* virtual addr of text segment */
	paddr_t data_base;		/* virtual addr of data segment */
	const char *objname;		/* null-term. pathname to loadobj */
} tnfctl_ind_obj_info_t;
.fi
.in -2

.sp
.LP
\fIobjfd\fR should be the file descriptor of the load object or executable.  If
it is \fB\(mi1\fR, then \fIobjname\fR should be an absolute pathname to the
load object or executable. If \fIobjfd\fR is not closed by  \fBlibtnfctl\fR, it
should be closed by the load object iterator function. \fItext_base\fR and
\fIdata_base\fR are the addresses where the text and data segments of the load
object are mapped in the target process.
.sp
.LP
Whenever the target process opens  or closes  a dynamic object, the set of
available probes may change.   See \fBdlopen\fR(3C) and \fBdlclose\fR(3C). In
indirect mode, call \fBtnfctl_check_libs()\fR when such events occur to make
\fBlibtnfctl\fR aware of any changes.  In other modes this is unnecessary but
harmless. It is also harmless to call \fBtnfctl_check_libs()\fR when no such
events have occurred.
.SH RETURN VALUES
\fBtnfctl_indirect_open()\fR and \fBtnfctl_check_libs()\fR return
\fBTNFCTL_ERR_NONE\fR upon success.
.SH ERRORS
The following error codes apply to  \fBtnfctl_indirect_open()\fR:
.sp
.ne 2
.na
\fB\fBTNFCTL_ERR_ALLOCFAIL\fR\fR
.ad
.RS 28n
A memory allocation failure occurred.
.RE

.sp
.ne 2
.na
\fB\fBTNFCTL_ERR_BUSY\fR\fR
.ad
.RS 28n
Internal tracing is being used.
.RE

.sp
.ne 2
.na
\fB\fBTNFCTL_ERR_NOLIBTNFPROBE\fR\fR
.ad
.RS 28n
\fBlibtnfprobe.so.1\fR is not loaded in the target process.
.RE

.sp
.ne 2
.na
\fB\fBTNFCTL_ERR_INTERNAL\fR\fR
.ad
.RS 28n
An internal error occurred.
.RE

.sp
.LP
The following error codes apply to  \fBtnfctl_check_libs()\fR:
.sp
.ne 2
.na
\fB\fBTNFCTL_ERR_ALLOCFAIL\fR\fR
.ad
.RS 24n
A memory allocation failure occurred.
.RE

.sp
.ne 2
.na
\fB\fBTNFCTL_ERR_INTERNAL\fR\fR
.ad
.RS 24n
An internal error occurred.
.RE

.SH ATTRIBUTES
See \fBattributes\fR(5) for descriptions of the following attributes:
.sp

.sp
.TS
box;
c | c
l | l .
ATTRIBUTE TYPE	ATTRIBUTE VALUE
_
MT Level	MT-Safe
.TE

.SH SEE ALSO
\fBprex\fR(1), \fBTNF_PROBE\fR(3TNF), \fBdlclose\fR(3C), \fBdlopen\fR(3C),
\fBlibtnfctl\fR(3TNF), \fBtnfctl_probe_enable\fR(3TNF),
\fBtnfctl_probe_trace\fR(3TNF), \fBtracing\fR(3TNF), \fBproc\fR(4),
\fBattributes\fR(5)
.sp
.LP
\fILinker and Libraries Guide\fR
.SH NOTES
\fBtnfctl_indirect_open()\fR should only be called after the dynamic linker has
mapped in all the libraries (rtld sync point) and called only after the process
is stopped. Indirect process probe control assumes the target process is
stopped whenever any \fBlibtnfctl\fR interface is used on it.  For example,
when used for indirect process probe control,  \fBtnfctl_probe_enable\fR(3TNF)
and \fBtnfctl_probe_trace\fR(3TNF) should be called only for a process that is
stopped.