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