10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*3682Sjhaslam * Common Development and Distribution License (the "License").
6*3682Sjhaslam * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
210Sstevel@tonic-gate /*
22*3682Sjhaslam * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
230Sstevel@tonic-gate * Use is subject to license terms.
240Sstevel@tonic-gate */
250Sstevel@tonic-gate
260Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
270Sstevel@tonic-gate
280Sstevel@tonic-gate #include <stddef.h>
290Sstevel@tonic-gate #include <stdlib.h>
300Sstevel@tonic-gate #include <strings.h>
310Sstevel@tonic-gate #include <errno.h>
320Sstevel@tonic-gate #include <unistd.h>
330Sstevel@tonic-gate #include <assert.h>
340Sstevel@tonic-gate #include <alloca.h>
350Sstevel@tonic-gate
36265Smws #include <dt_impl.h>
37265Smws #include <dt_program.h>
38265Smws
390Sstevel@tonic-gate static const char _dt_errprog[] =
400Sstevel@tonic-gate "dtrace:::ERROR"
410Sstevel@tonic-gate "{"
420Sstevel@tonic-gate " trace(arg1);"
430Sstevel@tonic-gate " trace(arg2);"
440Sstevel@tonic-gate " trace(arg3);"
450Sstevel@tonic-gate " trace(arg4);"
460Sstevel@tonic-gate " trace(arg5);"
470Sstevel@tonic-gate "}";
480Sstevel@tonic-gate
490Sstevel@tonic-gate int
dtrace_handle_err(dtrace_hdl_t * dtp,dtrace_handle_err_f * hdlr,void * arg)500Sstevel@tonic-gate dtrace_handle_err(dtrace_hdl_t *dtp, dtrace_handle_err_f *hdlr, void *arg)
510Sstevel@tonic-gate {
520Sstevel@tonic-gate dtrace_prog_t *pgp = NULL;
530Sstevel@tonic-gate dt_stmt_t *stp;
540Sstevel@tonic-gate dtrace_ecbdesc_t *edp;
550Sstevel@tonic-gate
560Sstevel@tonic-gate /*
570Sstevel@tonic-gate * We don't currently support multiple error handlers.
580Sstevel@tonic-gate */
590Sstevel@tonic-gate if (dtp->dt_errhdlr != NULL)
600Sstevel@tonic-gate return (dt_set_errno(dtp, EALREADY));
610Sstevel@tonic-gate
620Sstevel@tonic-gate /*
630Sstevel@tonic-gate * If the DTRACEOPT_GRABANON is enabled, the anonymous enabling will
640Sstevel@tonic-gate * already have a dtrace:::ERROR probe enabled; save 'hdlr' and 'arg'
650Sstevel@tonic-gate * but do not bother compiling and enabling _dt_errprog.
660Sstevel@tonic-gate */
670Sstevel@tonic-gate if (dtp->dt_options[DTRACEOPT_GRABANON] != DTRACEOPT_UNSET)
680Sstevel@tonic-gate goto out;
690Sstevel@tonic-gate
700Sstevel@tonic-gate if ((pgp = dtrace_program_strcompile(dtp, _dt_errprog,
710Sstevel@tonic-gate DTRACE_PROBESPEC_NAME, DTRACE_C_ZDEFS, 0, NULL)) == NULL)
720Sstevel@tonic-gate return (dt_set_errno(dtp, dtrace_errno(dtp)));
730Sstevel@tonic-gate
740Sstevel@tonic-gate stp = dt_list_next(&pgp->dp_stmts);
750Sstevel@tonic-gate assert(stp != NULL);
760Sstevel@tonic-gate
770Sstevel@tonic-gate edp = stp->ds_desc->dtsd_ecbdesc;
780Sstevel@tonic-gate assert(edp != NULL);
790Sstevel@tonic-gate edp->dted_uarg = DT_ECB_ERROR;
800Sstevel@tonic-gate
810Sstevel@tonic-gate out:
820Sstevel@tonic-gate dtp->dt_errhdlr = hdlr;
830Sstevel@tonic-gate dtp->dt_errarg = arg;
840Sstevel@tonic-gate dtp->dt_errprog = pgp;
850Sstevel@tonic-gate
860Sstevel@tonic-gate return (0);
870Sstevel@tonic-gate }
880Sstevel@tonic-gate
890Sstevel@tonic-gate int
dtrace_handle_drop(dtrace_hdl_t * dtp,dtrace_handle_drop_f * hdlr,void * arg)900Sstevel@tonic-gate dtrace_handle_drop(dtrace_hdl_t *dtp, dtrace_handle_drop_f *hdlr, void *arg)
910Sstevel@tonic-gate {
920Sstevel@tonic-gate if (dtp->dt_drophdlr != NULL)
930Sstevel@tonic-gate return (dt_set_errno(dtp, EALREADY));
940Sstevel@tonic-gate
950Sstevel@tonic-gate dtp->dt_drophdlr = hdlr;
960Sstevel@tonic-gate dtp->dt_droparg = arg;
970Sstevel@tonic-gate
980Sstevel@tonic-gate return (0);
990Sstevel@tonic-gate }
1000Sstevel@tonic-gate
1010Sstevel@tonic-gate int
dtrace_handle_proc(dtrace_hdl_t * dtp,dtrace_handle_proc_f * hdlr,void * arg)1020Sstevel@tonic-gate dtrace_handle_proc(dtrace_hdl_t *dtp, dtrace_handle_proc_f *hdlr, void *arg)
1030Sstevel@tonic-gate {
1040Sstevel@tonic-gate if (dtp->dt_prochdlr != NULL)
1050Sstevel@tonic-gate return (dt_set_errno(dtp, EALREADY));
1060Sstevel@tonic-gate
1070Sstevel@tonic-gate dtp->dt_prochdlr = hdlr;
1080Sstevel@tonic-gate dtp->dt_procarg = arg;
1090Sstevel@tonic-gate
1100Sstevel@tonic-gate return (0);
1110Sstevel@tonic-gate }
1120Sstevel@tonic-gate
1130Sstevel@tonic-gate int
dtrace_handle_buffered(dtrace_hdl_t * dtp,dtrace_handle_buffered_f * hdlr,void * arg)1140Sstevel@tonic-gate dtrace_handle_buffered(dtrace_hdl_t *dtp, dtrace_handle_buffered_f *hdlr,
1150Sstevel@tonic-gate void *arg)
1160Sstevel@tonic-gate {
1170Sstevel@tonic-gate if (dtp->dt_bufhdlr != NULL)
1180Sstevel@tonic-gate return (dt_set_errno(dtp, EALREADY));
1190Sstevel@tonic-gate
1200Sstevel@tonic-gate if (hdlr == NULL)
1210Sstevel@tonic-gate return (dt_set_errno(dtp, EINVAL));
1220Sstevel@tonic-gate
1230Sstevel@tonic-gate dtp->dt_bufhdlr = hdlr;
1240Sstevel@tonic-gate dtp->dt_bufarg = arg;
1250Sstevel@tonic-gate
1260Sstevel@tonic-gate return (0);
1270Sstevel@tonic-gate }
1280Sstevel@tonic-gate
129457Sbmc int
dtrace_handle_setopt(dtrace_hdl_t * dtp,dtrace_handle_setopt_f * hdlr,void * arg)130457Sbmc dtrace_handle_setopt(dtrace_hdl_t *dtp, dtrace_handle_setopt_f *hdlr,
131457Sbmc void *arg)
132457Sbmc {
133457Sbmc if (hdlr == NULL)
134457Sbmc return (dt_set_errno(dtp, EINVAL));
135457Sbmc
136457Sbmc dtp->dt_setopthdlr = hdlr;
137457Sbmc dtp->dt_setoptarg = arg;
138457Sbmc
139457Sbmc return (0);
140457Sbmc }
141457Sbmc
1420Sstevel@tonic-gate #define DT_REC(type, ndx) *((type *)((uintptr_t)data->dtpda_data + \
1430Sstevel@tonic-gate epd->dtepd_rec[(ndx)].dtrd_offset))
1440Sstevel@tonic-gate
1450Sstevel@tonic-gate static int
dt_handle_err(dtrace_hdl_t * dtp,dtrace_probedata_t * data)1460Sstevel@tonic-gate dt_handle_err(dtrace_hdl_t *dtp, dtrace_probedata_t *data)
1470Sstevel@tonic-gate {
1480Sstevel@tonic-gate dtrace_eprobedesc_t *epd = data->dtpda_edesc, *errepd;
1490Sstevel@tonic-gate dtrace_probedesc_t *pd = data->dtpda_pdesc, *errpd;
1500Sstevel@tonic-gate dtrace_errdata_t err;
1510Sstevel@tonic-gate dtrace_epid_t epid;
1520Sstevel@tonic-gate
1530Sstevel@tonic-gate char where[30];
1540Sstevel@tonic-gate char details[30];
1550Sstevel@tonic-gate char offinfo[30];
1560Sstevel@tonic-gate const int slop = 80;
1570Sstevel@tonic-gate const char *faultstr;
1580Sstevel@tonic-gate char *str;
1590Sstevel@tonic-gate int len;
1600Sstevel@tonic-gate
1610Sstevel@tonic-gate assert(epd->dtepd_uarg == DT_ECB_ERROR);
1620Sstevel@tonic-gate
1630Sstevel@tonic-gate if (epd->dtepd_nrecs != 5 || strcmp(pd->dtpd_provider, "dtrace") != 0 ||
1640Sstevel@tonic-gate strcmp(pd->dtpd_name, "ERROR") != 0)
1650Sstevel@tonic-gate return (dt_set_errno(dtp, EDT_BADERROR));
1660Sstevel@tonic-gate
1670Sstevel@tonic-gate /*
1680Sstevel@tonic-gate * This is an error. We have the following items here: EPID,
1690Sstevel@tonic-gate * faulting action, DIF offset, fault code and faulting address.
1700Sstevel@tonic-gate */
1710Sstevel@tonic-gate epid = (uint32_t)DT_REC(uint64_t, 0);
1720Sstevel@tonic-gate
1730Sstevel@tonic-gate if (dt_epid_lookup(dtp, epid, &errepd, &errpd) != 0)
1740Sstevel@tonic-gate return (dt_set_errno(dtp, EDT_BADERROR));
1750Sstevel@tonic-gate
1760Sstevel@tonic-gate err.dteda_edesc = errepd;
1770Sstevel@tonic-gate err.dteda_pdesc = errpd;
1780Sstevel@tonic-gate err.dteda_cpu = data->dtpda_cpu;
1790Sstevel@tonic-gate err.dteda_action = (int)DT_REC(uint64_t, 1);
1800Sstevel@tonic-gate err.dteda_offset = (int)DT_REC(uint64_t, 2);
1810Sstevel@tonic-gate err.dteda_fault = (int)DT_REC(uint64_t, 3);
1820Sstevel@tonic-gate err.dteda_addr = DT_REC(uint64_t, 4);
1830Sstevel@tonic-gate
1840Sstevel@tonic-gate faultstr = dtrace_faultstr(dtp, err.dteda_fault);
1850Sstevel@tonic-gate len = sizeof (where) + sizeof (offinfo) + strlen(faultstr) +
1860Sstevel@tonic-gate strlen(errpd->dtpd_provider) + strlen(errpd->dtpd_mod) +
1870Sstevel@tonic-gate strlen(errpd->dtpd_name) + strlen(errpd->dtpd_func) +
1880Sstevel@tonic-gate slop;
1890Sstevel@tonic-gate
1900Sstevel@tonic-gate str = (char *)alloca(len);
1910Sstevel@tonic-gate
1920Sstevel@tonic-gate if (err.dteda_action == 0) {
1930Sstevel@tonic-gate (void) sprintf(where, "predicate");
1940Sstevel@tonic-gate } else {
1950Sstevel@tonic-gate (void) sprintf(where, "action #%d", err.dteda_action);
1960Sstevel@tonic-gate }
1970Sstevel@tonic-gate
1980Sstevel@tonic-gate if (err.dteda_offset != -1) {
1990Sstevel@tonic-gate (void) sprintf(offinfo, " at DIF offset %d", err.dteda_offset);
2000Sstevel@tonic-gate } else {
2010Sstevel@tonic-gate offinfo[0] = 0;
2020Sstevel@tonic-gate }
2030Sstevel@tonic-gate
2040Sstevel@tonic-gate switch (err.dteda_fault) {
2050Sstevel@tonic-gate case DTRACEFLT_BADADDR:
2060Sstevel@tonic-gate case DTRACEFLT_BADALIGN:
207*3682Sjhaslam case DTRACEFLT_BADSTACK:
2080Sstevel@tonic-gate (void) sprintf(details, " (0x%llx)",
2090Sstevel@tonic-gate (u_longlong_t)err.dteda_addr);
2100Sstevel@tonic-gate break;
2110Sstevel@tonic-gate
2120Sstevel@tonic-gate default:
2130Sstevel@tonic-gate details[0] = 0;
2140Sstevel@tonic-gate }
2150Sstevel@tonic-gate
2160Sstevel@tonic-gate (void) snprintf(str, len, "error on enabled probe ID %u "
2170Sstevel@tonic-gate "(ID %u: %s:%s:%s:%s): %s%s in %s%s\n",
2180Sstevel@tonic-gate epid, errpd->dtpd_id, errpd->dtpd_provider,
2190Sstevel@tonic-gate errpd->dtpd_mod, errpd->dtpd_func,
2200Sstevel@tonic-gate errpd->dtpd_name, dtrace_faultstr(dtp, err.dteda_fault),
2210Sstevel@tonic-gate details, where, offinfo);
2220Sstevel@tonic-gate
2230Sstevel@tonic-gate err.dteda_msg = str;
2240Sstevel@tonic-gate
2250Sstevel@tonic-gate if (dtp->dt_errhdlr == NULL)
2260Sstevel@tonic-gate return (dt_set_errno(dtp, EDT_ERRABORT));
2270Sstevel@tonic-gate
2280Sstevel@tonic-gate if ((*dtp->dt_errhdlr)(&err, dtp->dt_errarg) == DTRACE_HANDLE_ABORT)
2290Sstevel@tonic-gate return (dt_set_errno(dtp, EDT_ERRABORT));
2300Sstevel@tonic-gate
2310Sstevel@tonic-gate return (0);
2320Sstevel@tonic-gate }
2330Sstevel@tonic-gate
2340Sstevel@tonic-gate int
dt_handle_liberr(dtrace_hdl_t * dtp,const dtrace_probedata_t * data,const char * faultstr)2350Sstevel@tonic-gate dt_handle_liberr(dtrace_hdl_t *dtp, const dtrace_probedata_t *data,
2360Sstevel@tonic-gate const char *faultstr)
2370Sstevel@tonic-gate {
2380Sstevel@tonic-gate dtrace_probedesc_t *errpd = data->dtpda_pdesc;
2390Sstevel@tonic-gate dtrace_errdata_t err;
2400Sstevel@tonic-gate const int slop = 80;
2410Sstevel@tonic-gate char *str;
2420Sstevel@tonic-gate int len;
2430Sstevel@tonic-gate
2440Sstevel@tonic-gate err.dteda_edesc = data->dtpda_edesc;
2450Sstevel@tonic-gate err.dteda_pdesc = errpd;
2460Sstevel@tonic-gate err.dteda_cpu = data->dtpda_cpu;
2470Sstevel@tonic-gate err.dteda_action = -1;
2480Sstevel@tonic-gate err.dteda_offset = -1;
2490Sstevel@tonic-gate err.dteda_fault = DTRACEFLT_LIBRARY;
2500Sstevel@tonic-gate err.dteda_addr = NULL;
2510Sstevel@tonic-gate
2520Sstevel@tonic-gate len = strlen(faultstr) +
2530Sstevel@tonic-gate strlen(errpd->dtpd_provider) + strlen(errpd->dtpd_mod) +
2540Sstevel@tonic-gate strlen(errpd->dtpd_name) + strlen(errpd->dtpd_func) +
2550Sstevel@tonic-gate slop;
2560Sstevel@tonic-gate
2570Sstevel@tonic-gate str = alloca(len);
2580Sstevel@tonic-gate
2590Sstevel@tonic-gate (void) snprintf(str, len, "error on enabled probe ID %u "
2600Sstevel@tonic-gate "(ID %u: %s:%s:%s:%s): %s\n",
2610Sstevel@tonic-gate data->dtpda_edesc->dtepd_epid,
2620Sstevel@tonic-gate errpd->dtpd_id, errpd->dtpd_provider,
2630Sstevel@tonic-gate errpd->dtpd_mod, errpd->dtpd_func,
2640Sstevel@tonic-gate errpd->dtpd_name, faultstr);
2650Sstevel@tonic-gate
2660Sstevel@tonic-gate err.dteda_msg = str;
2670Sstevel@tonic-gate
2680Sstevel@tonic-gate if (dtp->dt_errhdlr == NULL)
2690Sstevel@tonic-gate return (dt_set_errno(dtp, EDT_ERRABORT));
2700Sstevel@tonic-gate
2710Sstevel@tonic-gate if ((*dtp->dt_errhdlr)(&err, dtp->dt_errarg) == DTRACE_HANDLE_ABORT)
2720Sstevel@tonic-gate return (dt_set_errno(dtp, EDT_ERRABORT));
2730Sstevel@tonic-gate
2740Sstevel@tonic-gate return (0);
2750Sstevel@tonic-gate }
2760Sstevel@tonic-gate
277457Sbmc #define DROPTAG(x) x, #x
278457Sbmc
279457Sbmc static const struct {
280457Sbmc dtrace_dropkind_t dtdrg_kind;
281457Sbmc char *dtdrg_tag;
282457Sbmc } _dt_droptags[] = {
283457Sbmc { DROPTAG(DTRACEDROP_PRINCIPAL) },
284457Sbmc { DROPTAG(DTRACEDROP_AGGREGATION) },
285457Sbmc { DROPTAG(DTRACEDROP_DYNAMIC) },
286457Sbmc { DROPTAG(DTRACEDROP_DYNRINSE) },
287457Sbmc { DROPTAG(DTRACEDROP_DYNDIRTY) },
288457Sbmc { DROPTAG(DTRACEDROP_SPEC) },
289457Sbmc { DROPTAG(DTRACEDROP_SPECBUSY) },
290457Sbmc { DROPTAG(DTRACEDROP_SPECUNAVAIL) },
291457Sbmc { DROPTAG(DTRACEDROP_DBLERROR) },
292457Sbmc { DROPTAG(DTRACEDROP_STKSTROVERFLOW) },
293457Sbmc { 0, NULL }
294457Sbmc };
295457Sbmc
296457Sbmc static const char *
dt_droptag(dtrace_dropkind_t kind)297457Sbmc dt_droptag(dtrace_dropkind_t kind)
298457Sbmc {
299457Sbmc int i;
300457Sbmc
301457Sbmc for (i = 0; _dt_droptags[i].dtdrg_tag != NULL; i++) {
302457Sbmc if (_dt_droptags[i].dtdrg_kind == kind)
303457Sbmc return (_dt_droptags[i].dtdrg_tag);
304457Sbmc }
305457Sbmc
306457Sbmc return ("DTRACEDROP_UNKNOWN");
307457Sbmc }
308457Sbmc
3090Sstevel@tonic-gate int
dt_handle_cpudrop(dtrace_hdl_t * dtp,processorid_t cpu,dtrace_dropkind_t what,uint64_t howmany)3100Sstevel@tonic-gate dt_handle_cpudrop(dtrace_hdl_t *dtp, processorid_t cpu,
3110Sstevel@tonic-gate dtrace_dropkind_t what, uint64_t howmany)
3120Sstevel@tonic-gate {
3130Sstevel@tonic-gate dtrace_dropdata_t drop;
314457Sbmc char str[80], *s;
315457Sbmc int size;
3160Sstevel@tonic-gate
3170Sstevel@tonic-gate assert(what == DTRACEDROP_PRINCIPAL || what == DTRACEDROP_AGGREGATION);
3180Sstevel@tonic-gate
3190Sstevel@tonic-gate bzero(&drop, sizeof (drop));
3200Sstevel@tonic-gate drop.dtdda_handle = dtp;
3210Sstevel@tonic-gate drop.dtdda_cpu = cpu;
3220Sstevel@tonic-gate drop.dtdda_kind = what;
3230Sstevel@tonic-gate drop.dtdda_drops = howmany;
3240Sstevel@tonic-gate drop.dtdda_msg = str;
3250Sstevel@tonic-gate
326457Sbmc if (dtp->dt_droptags) {
327457Sbmc (void) snprintf(str, sizeof (str), "[%s] ", dt_droptag(what));
328457Sbmc s = &str[strlen(str)];
329457Sbmc size = sizeof (str) - (s - str);
330457Sbmc } else {
331457Sbmc s = str;
332457Sbmc size = sizeof (str);
333457Sbmc }
334457Sbmc
335457Sbmc (void) snprintf(s, size, "%llu %sdrop%s on CPU %d\n",
3360Sstevel@tonic-gate howmany, what == DTRACEDROP_PRINCIPAL ? "" : "aggregation ",
3370Sstevel@tonic-gate howmany > 1 ? "s" : "", cpu);
3380Sstevel@tonic-gate
3390Sstevel@tonic-gate if (dtp->dt_drophdlr == NULL)
3400Sstevel@tonic-gate return (dt_set_errno(dtp, EDT_DROPABORT));
3410Sstevel@tonic-gate
3420Sstevel@tonic-gate if ((*dtp->dt_drophdlr)(&drop, dtp->dt_droparg) == DTRACE_HANDLE_ABORT)
3430Sstevel@tonic-gate return (dt_set_errno(dtp, EDT_DROPABORT));
3440Sstevel@tonic-gate
3450Sstevel@tonic-gate return (0);
3460Sstevel@tonic-gate }
3470Sstevel@tonic-gate
3480Sstevel@tonic-gate static const struct {
3490Sstevel@tonic-gate dtrace_dropkind_t dtdrt_kind;
3500Sstevel@tonic-gate uintptr_t dtdrt_offset;
3510Sstevel@tonic-gate const char *dtdrt_str;
3520Sstevel@tonic-gate const char *dtdrt_msg;
3530Sstevel@tonic-gate } _dt_droptab[] = {
3540Sstevel@tonic-gate { DTRACEDROP_DYNAMIC,
3550Sstevel@tonic-gate offsetof(dtrace_status_t, dtst_dyndrops),
3560Sstevel@tonic-gate "dynamic variable drop" },
3570Sstevel@tonic-gate
3580Sstevel@tonic-gate { DTRACEDROP_DYNRINSE,
3590Sstevel@tonic-gate offsetof(dtrace_status_t, dtst_dyndrops_rinsing),
3600Sstevel@tonic-gate "dynamic variable drop", " with non-empty rinsing list" },
3610Sstevel@tonic-gate
3620Sstevel@tonic-gate { DTRACEDROP_DYNDIRTY,
3630Sstevel@tonic-gate offsetof(dtrace_status_t, dtst_dyndrops_dirty),
3640Sstevel@tonic-gate "dynamic variable drop", " with non-empty dirty list" },
3650Sstevel@tonic-gate
3660Sstevel@tonic-gate { DTRACEDROP_SPEC,
3670Sstevel@tonic-gate offsetof(dtrace_status_t, dtst_specdrops),
3680Sstevel@tonic-gate "speculative drop" },
3690Sstevel@tonic-gate
3700Sstevel@tonic-gate { DTRACEDROP_SPECBUSY,
3710Sstevel@tonic-gate offsetof(dtrace_status_t, dtst_specdrops_busy),
3720Sstevel@tonic-gate "failed speculation", " (available buffer(s) still busy)" },
3730Sstevel@tonic-gate
3740Sstevel@tonic-gate { DTRACEDROP_SPECUNAVAIL,
3750Sstevel@tonic-gate offsetof(dtrace_status_t, dtst_specdrops_unavail),
3760Sstevel@tonic-gate "failed speculation", " (no speculative buffer available)" },
3770Sstevel@tonic-gate
378457Sbmc { DTRACEDROP_STKSTROVERFLOW,
379457Sbmc offsetof(dtrace_status_t, dtst_stkstroverflows),
380457Sbmc "jstack()/ustack() string table overflow" },
381457Sbmc
382457Sbmc { DTRACEDROP_DBLERROR,
383457Sbmc offsetof(dtrace_status_t, dtst_dblerrors),
384457Sbmc "error", " in ERROR probe enabling" },
385457Sbmc
3860Sstevel@tonic-gate { 0, 0, NULL }
3870Sstevel@tonic-gate };
3880Sstevel@tonic-gate
3890Sstevel@tonic-gate int
dt_handle_status(dtrace_hdl_t * dtp,dtrace_status_t * old,dtrace_status_t * new)3900Sstevel@tonic-gate dt_handle_status(dtrace_hdl_t *dtp, dtrace_status_t *old, dtrace_status_t *new)
3910Sstevel@tonic-gate {
3920Sstevel@tonic-gate dtrace_dropdata_t drop;
393457Sbmc char str[80], *s;
3940Sstevel@tonic-gate uintptr_t base = (uintptr_t)new, obase = (uintptr_t)old;
395457Sbmc int i, size;
3960Sstevel@tonic-gate
3970Sstevel@tonic-gate bzero(&drop, sizeof (drop));
3980Sstevel@tonic-gate drop.dtdda_handle = dtp;
3990Sstevel@tonic-gate drop.dtdda_cpu = DTRACE_CPUALL;
4000Sstevel@tonic-gate drop.dtdda_msg = str;
4010Sstevel@tonic-gate
4020Sstevel@tonic-gate /*
4030Sstevel@tonic-gate * First, check to see if we've been killed -- in which case we abort.
4040Sstevel@tonic-gate */
4050Sstevel@tonic-gate if (new->dtst_killed && !old->dtst_killed)
4060Sstevel@tonic-gate return (dt_set_errno(dtp, EDT_BRICKED));
4070Sstevel@tonic-gate
4080Sstevel@tonic-gate for (i = 0; _dt_droptab[i].dtdrt_str != NULL; i++) {
4090Sstevel@tonic-gate uintptr_t naddr = base + _dt_droptab[i].dtdrt_offset;
4100Sstevel@tonic-gate uintptr_t oaddr = obase + _dt_droptab[i].dtdrt_offset;
4110Sstevel@tonic-gate
4120Sstevel@tonic-gate uint64_t nval = *((uint64_t *)naddr);
4130Sstevel@tonic-gate uint64_t oval = *((uint64_t *)oaddr);
4140Sstevel@tonic-gate
4150Sstevel@tonic-gate if (nval == oval)
4160Sstevel@tonic-gate continue;
4170Sstevel@tonic-gate
418457Sbmc if (dtp->dt_droptags) {
419457Sbmc (void) snprintf(str, sizeof (str), "[%s] ",
420457Sbmc dt_droptag(_dt_droptab[i].dtdrt_kind));
421457Sbmc s = &str[strlen(str)];
422457Sbmc size = sizeof (str) - (s - str);
423457Sbmc } else {
424457Sbmc s = str;
425457Sbmc size = sizeof (str);
426457Sbmc }
427457Sbmc
428457Sbmc (void) snprintf(s, size, "%llu %s%s%s\n", nval - oval,
4290Sstevel@tonic-gate _dt_droptab[i].dtdrt_str, (nval - oval > 1) ? "s" : "",
4300Sstevel@tonic-gate _dt_droptab[i].dtdrt_msg != NULL ?
4310Sstevel@tonic-gate _dt_droptab[i].dtdrt_msg : "");
4320Sstevel@tonic-gate
4330Sstevel@tonic-gate drop.dtdda_kind = _dt_droptab[i].dtdrt_kind;
4340Sstevel@tonic-gate drop.dtdda_total = nval;
4350Sstevel@tonic-gate drop.dtdda_drops = nval - oval;
4360Sstevel@tonic-gate
4370Sstevel@tonic-gate if (dtp->dt_drophdlr == NULL)
4380Sstevel@tonic-gate return (dt_set_errno(dtp, EDT_DROPABORT));
4390Sstevel@tonic-gate
4400Sstevel@tonic-gate if ((*dtp->dt_drophdlr)(&drop,
4410Sstevel@tonic-gate dtp->dt_droparg) == DTRACE_HANDLE_ABORT)
4420Sstevel@tonic-gate return (dt_set_errno(dtp, EDT_DROPABORT));
4430Sstevel@tonic-gate }
4440Sstevel@tonic-gate
4450Sstevel@tonic-gate return (0);
4460Sstevel@tonic-gate }
4470Sstevel@tonic-gate
4480Sstevel@tonic-gate int
dt_handle_setopt(dtrace_hdl_t * dtp,dtrace_setoptdata_t * data)449457Sbmc dt_handle_setopt(dtrace_hdl_t *dtp, dtrace_setoptdata_t *data)
450457Sbmc {
451457Sbmc void *arg = dtp->dt_setoptarg;
452457Sbmc
453457Sbmc if (dtp->dt_setopthdlr == NULL)
454457Sbmc return (0);
455457Sbmc
456457Sbmc if ((*dtp->dt_setopthdlr)(data, arg) == DTRACE_HANDLE_ABORT)
457457Sbmc return (dt_set_errno(dtp, EDT_DIRABORT));
458457Sbmc
459457Sbmc return (0);
460457Sbmc }
461457Sbmc
462457Sbmc int
dt_handle(dtrace_hdl_t * dtp,dtrace_probedata_t * data)4630Sstevel@tonic-gate dt_handle(dtrace_hdl_t *dtp, dtrace_probedata_t *data)
4640Sstevel@tonic-gate {
4650Sstevel@tonic-gate dtrace_eprobedesc_t *epd = data->dtpda_edesc;
4660Sstevel@tonic-gate int rval;
4670Sstevel@tonic-gate
4680Sstevel@tonic-gate switch (epd->dtepd_uarg) {
4690Sstevel@tonic-gate case DT_ECB_ERROR:
4700Sstevel@tonic-gate rval = dt_handle_err(dtp, data);
4710Sstevel@tonic-gate break;
4720Sstevel@tonic-gate
4730Sstevel@tonic-gate default:
4740Sstevel@tonic-gate return (DTRACE_CONSUME_THIS);
4750Sstevel@tonic-gate }
4760Sstevel@tonic-gate
4770Sstevel@tonic-gate if (rval == 0)
4780Sstevel@tonic-gate return (DTRACE_CONSUME_NEXT);
4790Sstevel@tonic-gate
4800Sstevel@tonic-gate return (DTRACE_CONSUME_ERROR);
4810Sstevel@tonic-gate }
482