xref: /onnv-gate/usr/src/lib/libdtrace/common/dt_handle.c (revision 457:d8f2995c64aa)
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
50Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
70Sstevel@tonic-gate  * with the License.
80Sstevel@tonic-gate  *
90Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate  * See the License for the specific language governing permissions
120Sstevel@tonic-gate  * and limitations under the License.
130Sstevel@tonic-gate  *
140Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate  *
200Sstevel@tonic-gate  * CDDL HEADER END
210Sstevel@tonic-gate  */
220Sstevel@tonic-gate /*
230Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #include <stddef.h>
300Sstevel@tonic-gate #include <stdlib.h>
310Sstevel@tonic-gate #include <strings.h>
320Sstevel@tonic-gate #include <errno.h>
330Sstevel@tonic-gate #include <unistd.h>
340Sstevel@tonic-gate #include <assert.h>
350Sstevel@tonic-gate #include <alloca.h>
360Sstevel@tonic-gate 
37265Smws #include <dt_impl.h>
38265Smws #include <dt_program.h>
39265Smws 
400Sstevel@tonic-gate static const char _dt_errprog[] =
410Sstevel@tonic-gate "dtrace:::ERROR"
420Sstevel@tonic-gate "{"
430Sstevel@tonic-gate "	trace(arg1);"
440Sstevel@tonic-gate "	trace(arg2);"
450Sstevel@tonic-gate "	trace(arg3);"
460Sstevel@tonic-gate "	trace(arg4);"
470Sstevel@tonic-gate "	trace(arg5);"
480Sstevel@tonic-gate "}";
490Sstevel@tonic-gate 
500Sstevel@tonic-gate int
510Sstevel@tonic-gate dtrace_handle_err(dtrace_hdl_t *dtp, dtrace_handle_err_f *hdlr, void *arg)
520Sstevel@tonic-gate {
530Sstevel@tonic-gate 	dtrace_prog_t *pgp = NULL;
540Sstevel@tonic-gate 	dt_stmt_t *stp;
550Sstevel@tonic-gate 	dtrace_ecbdesc_t *edp;
560Sstevel@tonic-gate 
570Sstevel@tonic-gate 	/*
580Sstevel@tonic-gate 	 * We don't currently support multiple error handlers.
590Sstevel@tonic-gate 	 */
600Sstevel@tonic-gate 	if (dtp->dt_errhdlr != NULL)
610Sstevel@tonic-gate 		return (dt_set_errno(dtp, EALREADY));
620Sstevel@tonic-gate 
630Sstevel@tonic-gate 	/*
640Sstevel@tonic-gate 	 * If the DTRACEOPT_GRABANON is enabled, the anonymous enabling will
650Sstevel@tonic-gate 	 * already have a dtrace:::ERROR probe enabled; save 'hdlr' and 'arg'
660Sstevel@tonic-gate 	 * but do not bother compiling and enabling _dt_errprog.
670Sstevel@tonic-gate 	 */
680Sstevel@tonic-gate 	if (dtp->dt_options[DTRACEOPT_GRABANON] != DTRACEOPT_UNSET)
690Sstevel@tonic-gate 		goto out;
700Sstevel@tonic-gate 
710Sstevel@tonic-gate 	if ((pgp = dtrace_program_strcompile(dtp, _dt_errprog,
720Sstevel@tonic-gate 	    DTRACE_PROBESPEC_NAME, DTRACE_C_ZDEFS, 0, NULL)) == NULL)
730Sstevel@tonic-gate 		return (dt_set_errno(dtp, dtrace_errno(dtp)));
740Sstevel@tonic-gate 
750Sstevel@tonic-gate 	stp = dt_list_next(&pgp->dp_stmts);
760Sstevel@tonic-gate 	assert(stp != NULL);
770Sstevel@tonic-gate 
780Sstevel@tonic-gate 	edp = stp->ds_desc->dtsd_ecbdesc;
790Sstevel@tonic-gate 	assert(edp != NULL);
800Sstevel@tonic-gate 	edp->dted_uarg = DT_ECB_ERROR;
810Sstevel@tonic-gate 
820Sstevel@tonic-gate out:
830Sstevel@tonic-gate 	dtp->dt_errhdlr = hdlr;
840Sstevel@tonic-gate 	dtp->dt_errarg = arg;
850Sstevel@tonic-gate 	dtp->dt_errprog = pgp;
860Sstevel@tonic-gate 
870Sstevel@tonic-gate 	return (0);
880Sstevel@tonic-gate }
890Sstevel@tonic-gate 
900Sstevel@tonic-gate int
910Sstevel@tonic-gate dtrace_handle_drop(dtrace_hdl_t *dtp, dtrace_handle_drop_f *hdlr, void *arg)
920Sstevel@tonic-gate {
930Sstevel@tonic-gate 	if (dtp->dt_drophdlr != NULL)
940Sstevel@tonic-gate 		return (dt_set_errno(dtp, EALREADY));
950Sstevel@tonic-gate 
960Sstevel@tonic-gate 	dtp->dt_drophdlr = hdlr;
970Sstevel@tonic-gate 	dtp->dt_droparg = arg;
980Sstevel@tonic-gate 
990Sstevel@tonic-gate 	return (0);
1000Sstevel@tonic-gate }
1010Sstevel@tonic-gate 
1020Sstevel@tonic-gate int
1030Sstevel@tonic-gate dtrace_handle_proc(dtrace_hdl_t *dtp, dtrace_handle_proc_f *hdlr, void *arg)
1040Sstevel@tonic-gate {
1050Sstevel@tonic-gate 	if (dtp->dt_prochdlr != NULL)
1060Sstevel@tonic-gate 		return (dt_set_errno(dtp, EALREADY));
1070Sstevel@tonic-gate 
1080Sstevel@tonic-gate 	dtp->dt_prochdlr = hdlr;
1090Sstevel@tonic-gate 	dtp->dt_procarg = arg;
1100Sstevel@tonic-gate 
1110Sstevel@tonic-gate 	return (0);
1120Sstevel@tonic-gate }
1130Sstevel@tonic-gate 
1140Sstevel@tonic-gate int
1150Sstevel@tonic-gate dtrace_handle_buffered(dtrace_hdl_t *dtp, dtrace_handle_buffered_f *hdlr,
1160Sstevel@tonic-gate     void *arg)
1170Sstevel@tonic-gate {
1180Sstevel@tonic-gate 	if (dtp->dt_bufhdlr != NULL)
1190Sstevel@tonic-gate 		return (dt_set_errno(dtp, EALREADY));
1200Sstevel@tonic-gate 
1210Sstevel@tonic-gate 	if (hdlr == NULL)
1220Sstevel@tonic-gate 		return (dt_set_errno(dtp, EINVAL));
1230Sstevel@tonic-gate 
1240Sstevel@tonic-gate 	dtp->dt_bufhdlr = hdlr;
1250Sstevel@tonic-gate 	dtp->dt_bufarg = arg;
1260Sstevel@tonic-gate 
1270Sstevel@tonic-gate 	return (0);
1280Sstevel@tonic-gate }
1290Sstevel@tonic-gate 
130*457Sbmc int
131*457Sbmc dtrace_handle_setopt(dtrace_hdl_t *dtp, dtrace_handle_setopt_f *hdlr,
132*457Sbmc     void *arg)
133*457Sbmc {
134*457Sbmc 	if (hdlr == NULL)
135*457Sbmc 		return (dt_set_errno(dtp, EINVAL));
136*457Sbmc 
137*457Sbmc 	dtp->dt_setopthdlr = hdlr;
138*457Sbmc 	dtp->dt_setoptarg = arg;
139*457Sbmc 
140*457Sbmc 	return (0);
141*457Sbmc }
142*457Sbmc 
1430Sstevel@tonic-gate #define	DT_REC(type, ndx) *((type *)((uintptr_t)data->dtpda_data + \
1440Sstevel@tonic-gate     epd->dtepd_rec[(ndx)].dtrd_offset))
1450Sstevel@tonic-gate 
1460Sstevel@tonic-gate static int
1470Sstevel@tonic-gate dt_handle_err(dtrace_hdl_t *dtp, dtrace_probedata_t *data)
1480Sstevel@tonic-gate {
1490Sstevel@tonic-gate 	dtrace_eprobedesc_t *epd = data->dtpda_edesc, *errepd;
1500Sstevel@tonic-gate 	dtrace_probedesc_t *pd = data->dtpda_pdesc, *errpd;
1510Sstevel@tonic-gate 	dtrace_errdata_t err;
1520Sstevel@tonic-gate 	dtrace_epid_t epid;
1530Sstevel@tonic-gate 
1540Sstevel@tonic-gate 	char where[30];
1550Sstevel@tonic-gate 	char details[30];
1560Sstevel@tonic-gate 	char offinfo[30];
1570Sstevel@tonic-gate 	const int slop = 80;
1580Sstevel@tonic-gate 	const char *faultstr;
1590Sstevel@tonic-gate 	char *str;
1600Sstevel@tonic-gate 	int len;
1610Sstevel@tonic-gate 
1620Sstevel@tonic-gate 	assert(epd->dtepd_uarg == DT_ECB_ERROR);
1630Sstevel@tonic-gate 
1640Sstevel@tonic-gate 	if (epd->dtepd_nrecs != 5 || strcmp(pd->dtpd_provider, "dtrace") != 0 ||
1650Sstevel@tonic-gate 	    strcmp(pd->dtpd_name, "ERROR") != 0)
1660Sstevel@tonic-gate 		return (dt_set_errno(dtp, EDT_BADERROR));
1670Sstevel@tonic-gate 
1680Sstevel@tonic-gate 	/*
1690Sstevel@tonic-gate 	 * This is an error.  We have the following items here:  EPID,
1700Sstevel@tonic-gate 	 * faulting action, DIF offset, fault code and faulting address.
1710Sstevel@tonic-gate 	 */
1720Sstevel@tonic-gate 	epid = (uint32_t)DT_REC(uint64_t, 0);
1730Sstevel@tonic-gate 
1740Sstevel@tonic-gate 	if (dt_epid_lookup(dtp, epid, &errepd, &errpd) != 0)
1750Sstevel@tonic-gate 		return (dt_set_errno(dtp, EDT_BADERROR));
1760Sstevel@tonic-gate 
1770Sstevel@tonic-gate 	err.dteda_edesc = errepd;
1780Sstevel@tonic-gate 	err.dteda_pdesc = errpd;
1790Sstevel@tonic-gate 	err.dteda_cpu = data->dtpda_cpu;
1800Sstevel@tonic-gate 	err.dteda_action = (int)DT_REC(uint64_t, 1);
1810Sstevel@tonic-gate 	err.dteda_offset = (int)DT_REC(uint64_t, 2);
1820Sstevel@tonic-gate 	err.dteda_fault = (int)DT_REC(uint64_t, 3);
1830Sstevel@tonic-gate 	err.dteda_addr = DT_REC(uint64_t, 4);
1840Sstevel@tonic-gate 
1850Sstevel@tonic-gate 	faultstr = dtrace_faultstr(dtp, err.dteda_fault);
1860Sstevel@tonic-gate 	len = sizeof (where) + sizeof (offinfo) + strlen(faultstr) +
1870Sstevel@tonic-gate 	    strlen(errpd->dtpd_provider) + strlen(errpd->dtpd_mod) +
1880Sstevel@tonic-gate 	    strlen(errpd->dtpd_name) + strlen(errpd->dtpd_func) +
1890Sstevel@tonic-gate 	    slop;
1900Sstevel@tonic-gate 
1910Sstevel@tonic-gate 	str = (char *)alloca(len);
1920Sstevel@tonic-gate 
1930Sstevel@tonic-gate 	if (err.dteda_action == 0) {
1940Sstevel@tonic-gate 		(void) sprintf(where, "predicate");
1950Sstevel@tonic-gate 	} else {
1960Sstevel@tonic-gate 		(void) sprintf(where, "action #%d", err.dteda_action);
1970Sstevel@tonic-gate 	}
1980Sstevel@tonic-gate 
1990Sstevel@tonic-gate 	if (err.dteda_offset != -1) {
2000Sstevel@tonic-gate 		(void) sprintf(offinfo, " at DIF offset %d", err.dteda_offset);
2010Sstevel@tonic-gate 	} else {
2020Sstevel@tonic-gate 		offinfo[0] = 0;
2030Sstevel@tonic-gate 	}
2040Sstevel@tonic-gate 
2050Sstevel@tonic-gate 	switch (err.dteda_fault) {
2060Sstevel@tonic-gate 	case DTRACEFLT_BADADDR:
2070Sstevel@tonic-gate 	case DTRACEFLT_BADALIGN:
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
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 
277*457Sbmc #define	DROPTAG(x)	x, #x
278*457Sbmc 
279*457Sbmc static const struct {
280*457Sbmc 	dtrace_dropkind_t dtdrg_kind;
281*457Sbmc 	char *dtdrg_tag;
282*457Sbmc } _dt_droptags[] = {
283*457Sbmc 	{ DROPTAG(DTRACEDROP_PRINCIPAL) },
284*457Sbmc 	{ DROPTAG(DTRACEDROP_AGGREGATION) },
285*457Sbmc 	{ DROPTAG(DTRACEDROP_DYNAMIC) },
286*457Sbmc 	{ DROPTAG(DTRACEDROP_DYNRINSE) },
287*457Sbmc 	{ DROPTAG(DTRACEDROP_DYNDIRTY) },
288*457Sbmc 	{ DROPTAG(DTRACEDROP_SPEC) },
289*457Sbmc 	{ DROPTAG(DTRACEDROP_SPECBUSY) },
290*457Sbmc 	{ DROPTAG(DTRACEDROP_SPECUNAVAIL) },
291*457Sbmc 	{ DROPTAG(DTRACEDROP_DBLERROR) },
292*457Sbmc 	{ DROPTAG(DTRACEDROP_STKSTROVERFLOW) },
293*457Sbmc 	{ 0, NULL }
294*457Sbmc };
295*457Sbmc 
296*457Sbmc static const char *
297*457Sbmc dt_droptag(dtrace_dropkind_t kind)
298*457Sbmc {
299*457Sbmc 	int i;
300*457Sbmc 
301*457Sbmc 	for (i = 0; _dt_droptags[i].dtdrg_tag != NULL; i++) {
302*457Sbmc 		if (_dt_droptags[i].dtdrg_kind == kind)
303*457Sbmc 			return (_dt_droptags[i].dtdrg_tag);
304*457Sbmc 	}
305*457Sbmc 
306*457Sbmc 	return ("DTRACEDROP_UNKNOWN");
307*457Sbmc }
308*457Sbmc 
3090Sstevel@tonic-gate int
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;
314*457Sbmc 	char str[80], *s;
315*457Sbmc 	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 
326*457Sbmc 	if (dtp->dt_droptags) {
327*457Sbmc 		(void) snprintf(str, sizeof (str), "[%s] ", dt_droptag(what));
328*457Sbmc 		s = &str[strlen(str)];
329*457Sbmc 		size = sizeof (str) - (s - str);
330*457Sbmc 	} else {
331*457Sbmc 		s = str;
332*457Sbmc 		size = sizeof (str);
333*457Sbmc 	}
334*457Sbmc 
335*457Sbmc 	(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 
378*457Sbmc 	{ DTRACEDROP_STKSTROVERFLOW,
379*457Sbmc 	    offsetof(dtrace_status_t, dtst_stkstroverflows),
380*457Sbmc 	    "jstack()/ustack() string table overflow" },
381*457Sbmc 
382*457Sbmc 	{ DTRACEDROP_DBLERROR,
383*457Sbmc 	    offsetof(dtrace_status_t, dtst_dblerrors),
384*457Sbmc 	    "error", " in ERROR probe enabling" },
385*457Sbmc 
3860Sstevel@tonic-gate 	{ 0, 0, NULL }
3870Sstevel@tonic-gate };
3880Sstevel@tonic-gate 
3890Sstevel@tonic-gate int
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;
393*457Sbmc 	char str[80], *s;
3940Sstevel@tonic-gate 	uintptr_t base = (uintptr_t)new, obase = (uintptr_t)old;
395*457Sbmc 	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 
418*457Sbmc 		if (dtp->dt_droptags) {
419*457Sbmc 			(void) snprintf(str, sizeof (str), "[%s] ",
420*457Sbmc 			    dt_droptag(_dt_droptab[i].dtdrt_kind));
421*457Sbmc 			s = &str[strlen(str)];
422*457Sbmc 			size = sizeof (str) - (s - str);
423*457Sbmc 		} else {
424*457Sbmc 			s = str;
425*457Sbmc 			size = sizeof (str);
426*457Sbmc 		}
427*457Sbmc 
428*457Sbmc 		(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
449*457Sbmc dt_handle_setopt(dtrace_hdl_t *dtp, dtrace_setoptdata_t *data)
450*457Sbmc {
451*457Sbmc 	void *arg = dtp->dt_setoptarg;
452*457Sbmc 
453*457Sbmc 	if (dtp->dt_setopthdlr == NULL)
454*457Sbmc 		return (0);
455*457Sbmc 
456*457Sbmc 	if ((*dtp->dt_setopthdlr)(data, arg) == DTRACE_HANDLE_ABORT)
457*457Sbmc 		return (dt_set_errno(dtp, EDT_DIRABORT));
458*457Sbmc 
459*457Sbmc 	return (0);
460*457Sbmc }
461*457Sbmc 
462*457Sbmc int
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