1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate * CDDL HEADER START
3*0Sstevel@tonic-gate *
4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
7*0Sstevel@tonic-gate * with the License.
8*0Sstevel@tonic-gate *
9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate * and limitations under the License.
13*0Sstevel@tonic-gate *
14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate *
20*0Sstevel@tonic-gate * CDDL HEADER END
21*0Sstevel@tonic-gate */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate * Copyright (c) 1994, by Sun Microsytems, Inc.
24*0Sstevel@tonic-gate */
25*0Sstevel@tonic-gate
26*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
27*0Sstevel@tonic-gate
28*0Sstevel@tonic-gate /*
29*0Sstevel@tonic-gate * Published interfaces for probe control.
30*0Sstevel@tonic-gate */
31*0Sstevel@tonic-gate
32*0Sstevel@tonic-gate #ifndef DEBUG
33*0Sstevel@tonic-gate #define NDEBUG 1
34*0Sstevel@tonic-gate #endif
35*0Sstevel@tonic-gate
36*0Sstevel@tonic-gate #include <stdio.h>
37*0Sstevel@tonic-gate #include <stdlib.h>
38*0Sstevel@tonic-gate #include <unistd.h>
39*0Sstevel@tonic-gate #include <string.h>
40*0Sstevel@tonic-gate #include <assert.h>
41*0Sstevel@tonic-gate #include <stddef.h>
42*0Sstevel@tonic-gate
43*0Sstevel@tonic-gate #include "tnfctl_int.h"
44*0Sstevel@tonic-gate #include "kernel_int.h"
45*0Sstevel@tonic-gate #include "dbg.h"
46*0Sstevel@tonic-gate
47*0Sstevel@tonic-gate struct pr_func_args {
48*0Sstevel@tonic-gate tnfctl_probe_op_t func_p;
49*0Sstevel@tonic-gate void *calldata;
50*0Sstevel@tonic-gate };
51*0Sstevel@tonic-gate
52*0Sstevel@tonic-gate tnfctl_errcode_t _tnfctl_destructor_wrapper(tnfctl_handle_t *,
53*0Sstevel@tonic-gate prbctlref_t *, void *);
54*0Sstevel@tonic-gate tnfctl_errcode_t _tnfctl_creator_wrapper(tnfctl_handle_t *,
55*0Sstevel@tonic-gate prbctlref_t *, void *);
56*0Sstevel@tonic-gate static tnfctl_errcode_t apply_func(tnfctl_handle_t *, prbctlref_t *, void *);
57*0Sstevel@tonic-gate static tnfctl_errcode_t check_operation(tnfctl_handle_t *, tnfctl_probe_t *);
58*0Sstevel@tonic-gate
59*0Sstevel@tonic-gate tnfctl_errcode_t
tnfctl_register_funcs(tnfctl_handle_t * hndl,void * (* create_func)(tnfctl_handle_t *,tnfctl_probe_t *),void (* destroy_func)(void *))60*0Sstevel@tonic-gate tnfctl_register_funcs(tnfctl_handle_t *hndl,
61*0Sstevel@tonic-gate void *(*create_func)(tnfctl_handle_t *, tnfctl_probe_t *),
62*0Sstevel@tonic-gate void (*destroy_func)(void *))
63*0Sstevel@tonic-gate {
64*0Sstevel@tonic-gate tnfctl_errcode_t prexstat;
65*0Sstevel@tonic-gate
66*0Sstevel@tonic-gate if (hndl->destroy_func) {
67*0Sstevel@tonic-gate /*
68*0Sstevel@tonic-gate * not the first time the register_funcs() is being called
69*0Sstevel@tonic-gate * First call currently registered destroy_func on all
70*0Sstevel@tonic-gate * probes
71*0Sstevel@tonic-gate */
72*0Sstevel@tonic-gate prexstat = _tnfctl_probes_traverse(hndl,
73*0Sstevel@tonic-gate _tnfctl_destructor_wrapper, NULL);
74*0Sstevel@tonic-gate if (prexstat)
75*0Sstevel@tonic-gate return (prexstat);
76*0Sstevel@tonic-gate }
77*0Sstevel@tonic-gate
78*0Sstevel@tonic-gate /* set up new creator and destructor functions */
79*0Sstevel@tonic-gate hndl->create_func = create_func;
80*0Sstevel@tonic-gate hndl->destroy_func = destroy_func;
81*0Sstevel@tonic-gate
82*0Sstevel@tonic-gate /* call new creator function for all current probes */
83*0Sstevel@tonic-gate if (create_func) {
84*0Sstevel@tonic-gate prexstat = _tnfctl_probes_traverse(hndl,
85*0Sstevel@tonic-gate _tnfctl_creator_wrapper, NULL);
86*0Sstevel@tonic-gate if (prexstat)
87*0Sstevel@tonic-gate return (prexstat);
88*0Sstevel@tonic-gate }
89*0Sstevel@tonic-gate
90*0Sstevel@tonic-gate return (TNFCTL_ERR_NONE);
91*0Sstevel@tonic-gate }
92*0Sstevel@tonic-gate
93*0Sstevel@tonic-gate tnfctl_errcode_t
_tnfctl_destructor_wrapper(tnfctl_handle_t * hndl,prbctlref_t * probe,void * cd)94*0Sstevel@tonic-gate _tnfctl_destructor_wrapper(tnfctl_handle_t *hndl, prbctlref_t *probe, void *cd)
95*0Sstevel@tonic-gate {
96*0Sstevel@tonic-gate assert(hndl->destroy_func);
97*0Sstevel@tonic-gate hndl->destroy_func(probe->probe_handle->client_registered_data);
98*0Sstevel@tonic-gate
99*0Sstevel@tonic-gate return (TNFCTL_ERR_NONE);
100*0Sstevel@tonic-gate }
101*0Sstevel@tonic-gate
102*0Sstevel@tonic-gate tnfctl_errcode_t
_tnfctl_creator_wrapper(tnfctl_handle_t * hndl,prbctlref_t * probe,void * cd)103*0Sstevel@tonic-gate _tnfctl_creator_wrapper(tnfctl_handle_t *hndl, prbctlref_t *probe, void *cd)
104*0Sstevel@tonic-gate {
105*0Sstevel@tonic-gate tnfctl_probe_t *p_handle;
106*0Sstevel@tonic-gate
107*0Sstevel@tonic-gate assert(hndl->create_func);
108*0Sstevel@tonic-gate p_handle = probe->probe_handle;
109*0Sstevel@tonic-gate p_handle->client_registered_data = hndl->create_func(hndl, p_handle);
110*0Sstevel@tonic-gate
111*0Sstevel@tonic-gate return (TNFCTL_ERR_NONE);
112*0Sstevel@tonic-gate }
113*0Sstevel@tonic-gate
114*0Sstevel@tonic-gate tnfctl_errcode_t
tnfctl_probe_apply(tnfctl_handle_t * hndl,tnfctl_probe_op_t func_p,void * calldata)115*0Sstevel@tonic-gate tnfctl_probe_apply(tnfctl_handle_t *hndl, tnfctl_probe_op_t func_p,
116*0Sstevel@tonic-gate void *calldata)
117*0Sstevel@tonic-gate {
118*0Sstevel@tonic-gate struct pr_func_args pr_args;
119*0Sstevel@tonic-gate tnfctl_errcode_t prexstat;
120*0Sstevel@tonic-gate
121*0Sstevel@tonic-gate pr_args.func_p = func_p;
122*0Sstevel@tonic-gate pr_args.calldata = calldata;
123*0Sstevel@tonic-gate prexstat = _tnfctl_probes_traverse(hndl, apply_func, &pr_args);
124*0Sstevel@tonic-gate return (prexstat);
125*0Sstevel@tonic-gate }
126*0Sstevel@tonic-gate
127*0Sstevel@tonic-gate tnfctl_errcode_t
tnfctl_probe_apply_ids(tnfctl_handle_t * hndl,ulong_t probe_count,ulong_t * probe_ids,tnfctl_probe_op_t func_p,void * calldata)128*0Sstevel@tonic-gate tnfctl_probe_apply_ids(tnfctl_handle_t *hndl, ulong_t probe_count,
129*0Sstevel@tonic-gate ulong_t *probe_ids, tnfctl_probe_op_t func_p,
130*0Sstevel@tonic-gate void *calldata)
131*0Sstevel@tonic-gate {
132*0Sstevel@tonic-gate ulong_t *id_p;
133*0Sstevel@tonic-gate ulong_t i, pos;
134*0Sstevel@tonic-gate objlist_t *obj_p;
135*0Sstevel@tonic-gate prbctlref_t *probe;
136*0Sstevel@tonic-gate tnfctl_errcode_t prexstat = TNFCTL_ERR_NONE;
137*0Sstevel@tonic-gate boolean_t release_lock;
138*0Sstevel@tonic-gate
139*0Sstevel@tonic-gate /*LINTED statement has no consequent: else*/
140*0Sstevel@tonic-gate LOCK_SYNC(hndl, prexstat, release_lock);
141*0Sstevel@tonic-gate
142*0Sstevel@tonic-gate /* select probes based on numbers */
143*0Sstevel@tonic-gate id_p = probe_ids;
144*0Sstevel@tonic-gate for (i = 0; i < probe_count; i++, id_p++) {
145*0Sstevel@tonic-gate obj_p = hndl->objlist;
146*0Sstevel@tonic-gate while (obj_p) {
147*0Sstevel@tonic-gate if ((*id_p >= obj_p->min_probe_num) &&
148*0Sstevel@tonic-gate (*id_p < (obj_p->min_probe_num +
149*0Sstevel@tonic-gate obj_p->probecnt))) {
150*0Sstevel@tonic-gate break;
151*0Sstevel@tonic-gate }
152*0Sstevel@tonic-gate obj_p = obj_p->next;
153*0Sstevel@tonic-gate }
154*0Sstevel@tonic-gate if (obj_p == NULL) {
155*0Sstevel@tonic-gate prexstat = TNFCTL_ERR_INVALIDPROBE;
156*0Sstevel@tonic-gate goto end_of_func;
157*0Sstevel@tonic-gate }
158*0Sstevel@tonic-gate pos = *id_p - obj_p->min_probe_num;
159*0Sstevel@tonic-gate probe = &(obj_p->probes[pos]);
160*0Sstevel@tonic-gate prexstat = func_p(hndl, probe->probe_handle, calldata);
161*0Sstevel@tonic-gate if (prexstat)
162*0Sstevel@tonic-gate goto end_of_func;
163*0Sstevel@tonic-gate }
164*0Sstevel@tonic-gate
165*0Sstevel@tonic-gate end_of_func:
166*0Sstevel@tonic-gate /*LINTED statement has no consequent: else*/
167*0Sstevel@tonic-gate UNLOCK(hndl, release_lock);
168*0Sstevel@tonic-gate return (prexstat);
169*0Sstevel@tonic-gate }
170*0Sstevel@tonic-gate
171*0Sstevel@tonic-gate tnfctl_errcode_t
tnfctl_probe_state_get(tnfctl_handle_t * hndl,tnfctl_probe_t * probe_hndl,tnfctl_probe_state_t * state_p)172*0Sstevel@tonic-gate tnfctl_probe_state_get(tnfctl_handle_t *hndl, tnfctl_probe_t *probe_hndl,
173*0Sstevel@tonic-gate tnfctl_probe_state_t *state_p)
174*0Sstevel@tonic-gate {
175*0Sstevel@tonic-gate tnf_probe_control_t *prbctl_p;
176*0Sstevel@tonic-gate boolean_t release_lock;
177*0Sstevel@tonic-gate tnfctl_errcode_t prexstat = TNFCTL_ERR_NONE;
178*0Sstevel@tonic-gate char **func_names;
179*0Sstevel@tonic-gate uintptr_t *func_addrs;
180*0Sstevel@tonic-gate
181*0Sstevel@tonic-gate if (hndl->mode == KERNEL_MODE) {
182*0Sstevel@tonic-gate prexstat = _tnfctl_refresh_kernel(hndl);
183*0Sstevel@tonic-gate if (prexstat)
184*0Sstevel@tonic-gate return (prexstat);
185*0Sstevel@tonic-gate }
186*0Sstevel@tonic-gate
187*0Sstevel@tonic-gate /*LINTED statement has no consequent: else*/
188*0Sstevel@tonic-gate LOCK_SYNC(hndl, prexstat, release_lock);
189*0Sstevel@tonic-gate
190*0Sstevel@tonic-gate if (probe_hndl->valid == B_FALSE) {
191*0Sstevel@tonic-gate prexstat = TNFCTL_ERR_INVALIDPROBE;
192*0Sstevel@tonic-gate goto end_of_func;
193*0Sstevel@tonic-gate }
194*0Sstevel@tonic-gate
195*0Sstevel@tonic-gate state_p->id = probe_hndl->probe_p->probe_id;
196*0Sstevel@tonic-gate state_p->attr_string = probe_hndl->probe_p->attr_string;
197*0Sstevel@tonic-gate
198*0Sstevel@tonic-gate prbctl_p = &probe_hndl->probe_p->wrkprbctl;
199*0Sstevel@tonic-gate state_p->enabled = (prbctl_p->test_func) ? B_TRUE : B_FALSE;
200*0Sstevel@tonic-gate state_p->traced = (prbctl_p->commit_func ==
201*0Sstevel@tonic-gate (tnf_probe_func_t) hndl->commitfunc) ? B_TRUE : B_FALSE;
202*0Sstevel@tonic-gate state_p->new_probe = probe_hndl->probe_p->obj->new_probe;
203*0Sstevel@tonic-gate state_p->obj_name = probe_hndl->probe_p->obj->objname;
204*0Sstevel@tonic-gate state_p->client_registered_data = probe_hndl->client_registered_data;
205*0Sstevel@tonic-gate
206*0Sstevel@tonic-gate if (hndl->mode == KERNEL_MODE) {
207*0Sstevel@tonic-gate state_p->func_names = NULL;
208*0Sstevel@tonic-gate state_p->func_addrs = NULL;
209*0Sstevel@tonic-gate /* skip code upto label */
210*0Sstevel@tonic-gate goto end_of_func;
211*0Sstevel@tonic-gate }
212*0Sstevel@tonic-gate
213*0Sstevel@tonic-gate /* process mode - get the probe functions */
214*0Sstevel@tonic-gate prexstat = _tnfctl_comb_decode(hndl, (uintptr_t) prbctl_p->probe_func,
215*0Sstevel@tonic-gate &func_names, &func_addrs);
216*0Sstevel@tonic-gate if (prexstat)
217*0Sstevel@tonic-gate goto end_of_func;
218*0Sstevel@tonic-gate
219*0Sstevel@tonic-gate /* if there are any probe functions */
220*0Sstevel@tonic-gate if (func_names[0] != NULL) {
221*0Sstevel@tonic-gate state_p->func_names = (const char * const *) func_names;
222*0Sstevel@tonic-gate state_p->func_addrs = func_addrs;
223*0Sstevel@tonic-gate } else {
224*0Sstevel@tonic-gate state_p->func_names = NULL;
225*0Sstevel@tonic-gate state_p->func_addrs = NULL;
226*0Sstevel@tonic-gate }
227*0Sstevel@tonic-gate
228*0Sstevel@tonic-gate end_of_func:
229*0Sstevel@tonic-gate /*LINTED statement has no consequent: else*/
230*0Sstevel@tonic-gate UNLOCK(hndl, release_lock);
231*0Sstevel@tonic-gate return (prexstat);
232*0Sstevel@tonic-gate }
233*0Sstevel@tonic-gate
234*0Sstevel@tonic-gate static tnfctl_errcode_t
check_operation(tnfctl_handle_t * hndl,tnfctl_probe_t * probe_hndl)235*0Sstevel@tonic-gate check_operation(tnfctl_handle_t *hndl, tnfctl_probe_t *probe_hndl)
236*0Sstevel@tonic-gate {
237*0Sstevel@tonic-gate tnfctl_errcode_t prexstat;
238*0Sstevel@tonic-gate
239*0Sstevel@tonic-gate if (hndl->mode == KERNEL_MODE) {
240*0Sstevel@tonic-gate prexstat = _tnfctl_refresh_kernel(hndl);
241*0Sstevel@tonic-gate if (prexstat)
242*0Sstevel@tonic-gate return (prexstat);
243*0Sstevel@tonic-gate } else if (hndl->trace_buf_state == TNFCTL_BUF_NONE) {
244*0Sstevel@tonic-gate /* process tracing */
245*0Sstevel@tonic-gate return (TNFCTL_ERR_NOBUF);
246*0Sstevel@tonic-gate }
247*0Sstevel@tonic-gate
248*0Sstevel@tonic-gate if (hndl->trace_buf_state == TNFCTL_BUF_BROKEN)
249*0Sstevel@tonic-gate return (TNFCTL_ERR_BUFBROKEN);
250*0Sstevel@tonic-gate
251*0Sstevel@tonic-gate if (probe_hndl->valid == B_FALSE) {
252*0Sstevel@tonic-gate return (TNFCTL_ERR_INVALIDPROBE);
253*0Sstevel@tonic-gate }
254*0Sstevel@tonic-gate
255*0Sstevel@tonic-gate return (TNFCTL_ERR_NONE);
256*0Sstevel@tonic-gate }
257*0Sstevel@tonic-gate
258*0Sstevel@tonic-gate tnfctl_errcode_t
tnfctl_probe_enable(tnfctl_handle_t * hndl,tnfctl_probe_t * probe_hndl,void * cd)259*0Sstevel@tonic-gate tnfctl_probe_enable(tnfctl_handle_t *hndl, tnfctl_probe_t *probe_hndl, void *cd)
260*0Sstevel@tonic-gate {
261*0Sstevel@tonic-gate tnf_probe_control_t *prbctl_p;
262*0Sstevel@tonic-gate boolean_t release_lock;
263*0Sstevel@tonic-gate tnfctl_errcode_t prexstat;
264*0Sstevel@tonic-gate
265*0Sstevel@tonic-gate /*LINTED statement has no consequent: else*/
266*0Sstevel@tonic-gate LOCK_SYNC(hndl, prexstat, release_lock);
267*0Sstevel@tonic-gate
268*0Sstevel@tonic-gate prexstat = check_operation(hndl, probe_hndl);
269*0Sstevel@tonic-gate if (prexstat)
270*0Sstevel@tonic-gate goto end_of_func;
271*0Sstevel@tonic-gate
272*0Sstevel@tonic-gate prbctl_p = &probe_hndl->probe_p->wrkprbctl;
273*0Sstevel@tonic-gate prbctl_p->test_func = (tnf_probe_test_func_t) hndl->testfunc;
274*0Sstevel@tonic-gate prexstat = _tnfctl_flush_a_probe(hndl, probe_hndl->probe_p,
275*0Sstevel@tonic-gate offsetof(struct tnf_probe_control, test_func),
276*0Sstevel@tonic-gate sizeof (tnf_probe_test_func_t));
277*0Sstevel@tonic-gate end_of_func:
278*0Sstevel@tonic-gate /*LINTED statement has no consequent: else*/
279*0Sstevel@tonic-gate UNLOCK(hndl, release_lock);
280*0Sstevel@tonic-gate return (prexstat);
281*0Sstevel@tonic-gate }
282*0Sstevel@tonic-gate
283*0Sstevel@tonic-gate tnfctl_errcode_t
tnfctl_probe_disable(tnfctl_handle_t * hndl,tnfctl_probe_t * probe_hndl,void * cd)284*0Sstevel@tonic-gate tnfctl_probe_disable(tnfctl_handle_t *hndl, tnfctl_probe_t *probe_hndl,
285*0Sstevel@tonic-gate void *cd)
286*0Sstevel@tonic-gate {
287*0Sstevel@tonic-gate tnf_probe_control_t *prbctl_p;
288*0Sstevel@tonic-gate boolean_t release_lock;
289*0Sstevel@tonic-gate tnfctl_errcode_t prexstat;
290*0Sstevel@tonic-gate
291*0Sstevel@tonic-gate /*LINTED statement has no consequent: else*/
292*0Sstevel@tonic-gate LOCK_SYNC(hndl, prexstat, release_lock);
293*0Sstevel@tonic-gate
294*0Sstevel@tonic-gate prexstat = check_operation(hndl, probe_hndl);
295*0Sstevel@tonic-gate if (prexstat)
296*0Sstevel@tonic-gate goto end_of_func;
297*0Sstevel@tonic-gate
298*0Sstevel@tonic-gate prbctl_p = &probe_hndl->probe_p->wrkprbctl;
299*0Sstevel@tonic-gate prbctl_p->test_func = (tnf_probe_test_func_t) NULL;
300*0Sstevel@tonic-gate prexstat = _tnfctl_flush_a_probe(hndl, probe_hndl->probe_p,
301*0Sstevel@tonic-gate offsetof(struct tnf_probe_control, test_func),
302*0Sstevel@tonic-gate sizeof (tnf_probe_test_func_t));
303*0Sstevel@tonic-gate end_of_func:
304*0Sstevel@tonic-gate /*LINTED statement has no consequent: else*/
305*0Sstevel@tonic-gate UNLOCK(hndl, release_lock);
306*0Sstevel@tonic-gate return (prexstat);
307*0Sstevel@tonic-gate }
308*0Sstevel@tonic-gate
309*0Sstevel@tonic-gate tnfctl_errcode_t
tnfctl_probe_trace(tnfctl_handle_t * hndl,tnfctl_probe_t * probe_hndl,void * cd)310*0Sstevel@tonic-gate tnfctl_probe_trace(tnfctl_handle_t *hndl, tnfctl_probe_t *probe_hndl, void *cd)
311*0Sstevel@tonic-gate {
312*0Sstevel@tonic-gate tnf_probe_control_t *prbctl_p;
313*0Sstevel@tonic-gate boolean_t release_lock;
314*0Sstevel@tonic-gate tnfctl_errcode_t prexstat;
315*0Sstevel@tonic-gate
316*0Sstevel@tonic-gate /*LINTED statement has no consequent: else*/
317*0Sstevel@tonic-gate LOCK_SYNC(hndl, prexstat, release_lock);
318*0Sstevel@tonic-gate
319*0Sstevel@tonic-gate prexstat = check_operation(hndl, probe_hndl);
320*0Sstevel@tonic-gate if (prexstat)
321*0Sstevel@tonic-gate goto end_of_func;
322*0Sstevel@tonic-gate
323*0Sstevel@tonic-gate prbctl_p = &probe_hndl->probe_p->wrkprbctl;
324*0Sstevel@tonic-gate prbctl_p->commit_func = (tnf_probe_func_t) hndl->commitfunc;
325*0Sstevel@tonic-gate prexstat = _tnfctl_flush_a_probe(hndl, probe_hndl->probe_p,
326*0Sstevel@tonic-gate offsetof(struct tnf_probe_control, commit_func),
327*0Sstevel@tonic-gate sizeof (tnf_probe_func_t));
328*0Sstevel@tonic-gate
329*0Sstevel@tonic-gate end_of_func:
330*0Sstevel@tonic-gate /*LINTED statement has no consequent: else*/
331*0Sstevel@tonic-gate UNLOCK(hndl, release_lock);
332*0Sstevel@tonic-gate return (prexstat);
333*0Sstevel@tonic-gate }
334*0Sstevel@tonic-gate
335*0Sstevel@tonic-gate tnfctl_errcode_t
tnfctl_probe_untrace(tnfctl_handle_t * hndl,tnfctl_probe_t * probe_hndl,void * cd)336*0Sstevel@tonic-gate tnfctl_probe_untrace(tnfctl_handle_t *hndl, tnfctl_probe_t *probe_hndl,
337*0Sstevel@tonic-gate void *cd)
338*0Sstevel@tonic-gate {
339*0Sstevel@tonic-gate tnf_probe_control_t *prbctl_p;
340*0Sstevel@tonic-gate boolean_t release_lock;
341*0Sstevel@tonic-gate tnfctl_errcode_t prexstat;
342*0Sstevel@tonic-gate
343*0Sstevel@tonic-gate /*LINTED statement has no consequent: else*/
344*0Sstevel@tonic-gate LOCK_SYNC(hndl, prexstat, release_lock);
345*0Sstevel@tonic-gate
346*0Sstevel@tonic-gate prexstat = check_operation(hndl, probe_hndl);
347*0Sstevel@tonic-gate if (prexstat)
348*0Sstevel@tonic-gate goto end_of_func;
349*0Sstevel@tonic-gate
350*0Sstevel@tonic-gate prbctl_p = &probe_hndl->probe_p->wrkprbctl;
351*0Sstevel@tonic-gate prbctl_p->commit_func = (tnf_probe_func_t) hndl->rollbackfunc;
352*0Sstevel@tonic-gate prexstat = _tnfctl_flush_a_probe(hndl, probe_hndl->probe_p,
353*0Sstevel@tonic-gate offsetof(struct tnf_probe_control, commit_func),
354*0Sstevel@tonic-gate sizeof (tnf_probe_func_t));
355*0Sstevel@tonic-gate
356*0Sstevel@tonic-gate end_of_func:
357*0Sstevel@tonic-gate /*LINTED statement has no consequent: else*/
358*0Sstevel@tonic-gate UNLOCK(hndl, release_lock);
359*0Sstevel@tonic-gate return (prexstat);
360*0Sstevel@tonic-gate }
361*0Sstevel@tonic-gate
362*0Sstevel@tonic-gate tnfctl_errcode_t
tnfctl_probe_connect(tnfctl_handle_t * hndl,tnfctl_probe_t * probe_hndl,const char * lib_base_name,const char * func)363*0Sstevel@tonic-gate tnfctl_probe_connect(tnfctl_handle_t *hndl, tnfctl_probe_t *probe_hndl,
364*0Sstevel@tonic-gate const char *lib_base_name, const char *func)
365*0Sstevel@tonic-gate {
366*0Sstevel@tonic-gate tnf_probe_control_t *prbctl_p;
367*0Sstevel@tonic-gate boolean_t release_lock;
368*0Sstevel@tonic-gate tnfctl_errcode_t prexstat;
369*0Sstevel@tonic-gate uintptr_t func_addr;
370*0Sstevel@tonic-gate uintptr_t comb;
371*0Sstevel@tonic-gate
372*0Sstevel@tonic-gate if (hndl->mode == KERNEL_MODE)
373*0Sstevel@tonic-gate return (TNFCTL_ERR_BADARG);
374*0Sstevel@tonic-gate
375*0Sstevel@tonic-gate /*LINTED statement has no consequent: else*/
376*0Sstevel@tonic-gate LOCK_SYNC(hndl, prexstat, release_lock);
377*0Sstevel@tonic-gate
378*0Sstevel@tonic-gate prexstat = check_operation(hndl, probe_hndl);
379*0Sstevel@tonic-gate if (prexstat)
380*0Sstevel@tonic-gate goto end_of_func;
381*0Sstevel@tonic-gate
382*0Sstevel@tonic-gate if (func == NULL) {
383*0Sstevel@tonic-gate prexstat = TNFCTL_ERR_NONE;
384*0Sstevel@tonic-gate goto end_of_func;
385*0Sstevel@tonic-gate }
386*0Sstevel@tonic-gate
387*0Sstevel@tonic-gate if (lib_base_name) {
388*0Sstevel@tonic-gate prexstat = _tnfctl_sym_obj_find(hndl, lib_base_name, func,
389*0Sstevel@tonic-gate &func_addr);
390*0Sstevel@tonic-gate } else {
391*0Sstevel@tonic-gate prexstat = _tnfctl_sym_find(hndl, func, &func_addr);
392*0Sstevel@tonic-gate }
393*0Sstevel@tonic-gate /* check if function address was found */
394*0Sstevel@tonic-gate if (prexstat)
395*0Sstevel@tonic-gate goto end_of_func;
396*0Sstevel@tonic-gate
397*0Sstevel@tonic-gate prbctl_p = &probe_hndl->probe_p->wrkprbctl;
398*0Sstevel@tonic-gate prexstat = _tnfctl_comb_build(hndl, PRB_COMB_CHAIN,
399*0Sstevel@tonic-gate func_addr, (uintptr_t) prbctl_p->probe_func,
400*0Sstevel@tonic-gate &comb);
401*0Sstevel@tonic-gate if (prexstat)
402*0Sstevel@tonic-gate goto end_of_func;
403*0Sstevel@tonic-gate prbctl_p->probe_func = (tnf_probe_func_t) comb;
404*0Sstevel@tonic-gate prexstat = _tnfctl_flush_a_probe(hndl, probe_hndl->probe_p,
405*0Sstevel@tonic-gate offsetof(struct tnf_probe_control, probe_func),
406*0Sstevel@tonic-gate sizeof (tnf_probe_func_t));
407*0Sstevel@tonic-gate
408*0Sstevel@tonic-gate end_of_func:
409*0Sstevel@tonic-gate /*LINTED statement has no consequent: else*/
410*0Sstevel@tonic-gate UNLOCK(hndl, release_lock);
411*0Sstevel@tonic-gate return (prexstat);
412*0Sstevel@tonic-gate }
413*0Sstevel@tonic-gate
414*0Sstevel@tonic-gate tnfctl_errcode_t
tnfctl_probe_disconnect_all(tnfctl_handle_t * hndl,tnfctl_probe_t * probe_hndl,void * cd)415*0Sstevel@tonic-gate tnfctl_probe_disconnect_all(tnfctl_handle_t *hndl, tnfctl_probe_t *probe_hndl,
416*0Sstevel@tonic-gate void *cd)
417*0Sstevel@tonic-gate {
418*0Sstevel@tonic-gate tnf_probe_control_t *prbctl_p;
419*0Sstevel@tonic-gate boolean_t release_lock;
420*0Sstevel@tonic-gate tnfctl_errcode_t prexstat;
421*0Sstevel@tonic-gate
422*0Sstevel@tonic-gate if (hndl->mode == KERNEL_MODE)
423*0Sstevel@tonic-gate return (TNFCTL_ERR_BADARG);
424*0Sstevel@tonic-gate
425*0Sstevel@tonic-gate /*LINTED statement has no consequent: else*/
426*0Sstevel@tonic-gate LOCK_SYNC(hndl, prexstat, release_lock);
427*0Sstevel@tonic-gate
428*0Sstevel@tonic-gate prexstat = check_operation(hndl, probe_hndl);
429*0Sstevel@tonic-gate if (prexstat)
430*0Sstevel@tonic-gate goto end_of_func;
431*0Sstevel@tonic-gate
432*0Sstevel@tonic-gate prbctl_p = &probe_hndl->probe_p->wrkprbctl;
433*0Sstevel@tonic-gate prbctl_p->probe_func = (tnf_probe_func_t) hndl->endfunc;
434*0Sstevel@tonic-gate prexstat = _tnfctl_flush_a_probe(hndl, probe_hndl->probe_p,
435*0Sstevel@tonic-gate offsetof(struct tnf_probe_control, probe_func),
436*0Sstevel@tonic-gate sizeof (tnf_probe_func_t));
437*0Sstevel@tonic-gate
438*0Sstevel@tonic-gate end_of_func:
439*0Sstevel@tonic-gate /*LINTED statement has no consequent: else*/
440*0Sstevel@tonic-gate UNLOCK(hndl, release_lock);
441*0Sstevel@tonic-gate return (prexstat);
442*0Sstevel@tonic-gate }
443*0Sstevel@tonic-gate
444*0Sstevel@tonic-gate /*
445*0Sstevel@tonic-gate * Important that this function be tail recursive to minimize depth
446*0Sstevel@tonic-gate * of call chain that is called for every probe
447*0Sstevel@tonic-gate */
448*0Sstevel@tonic-gate static tnfctl_errcode_t
apply_func(tnfctl_handle_t * hndl,prbctlref_t * probe,void * cd)449*0Sstevel@tonic-gate apply_func(tnfctl_handle_t *hndl, prbctlref_t *probe, void *cd)
450*0Sstevel@tonic-gate {
451*0Sstevel@tonic-gate struct pr_func_args *args = cd;
452*0Sstevel@tonic-gate tnfctl_errcode_t prexstat;
453*0Sstevel@tonic-gate
454*0Sstevel@tonic-gate /* Call function only if match_func returns true */
455*0Sstevel@tonic-gate prexstat = (*(args->func_p))(hndl, probe->probe_handle, args->calldata);
456*0Sstevel@tonic-gate return (prexstat);
457*0Sstevel@tonic-gate }
458