sdt.c revision b0f673c4626e4cb1db7785287eaeed2731dfefe8
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Copyright (c) 2012, Joyent, Inc. All rights reserved.
*/
#include <vm/seg_kmem.h>
#include <sys/dtrace_impl.h>
#include <sys/sysmacros.h>
#include <sys/privregs.h>
#include <sys/sdt_impl.h>
#define SDT_PATCHVAL 0xf0
static dev_info_t *sdt_devi;
static int sdt_verbose = 0;
static sdt_probe_t **sdt_probetab;
static int sdt_probetab_size;
static int sdt_probetab_mask;
/*ARGSUSED*/
static int
{
int i = 0;
#ifdef __amd64
/*
* On amd64, stack[0] contains the dereferenced stack pointer,
* stack[1] contains savfp, stack[2] contains savpc. We want
* to step over these entries.
*/
i += 3;
#endif
/*
* When accessing the arguments on the stack, we must
* protect against accessing beyond the stack. We can
* safely set NOFAULT here -- we know that interrupts
* are already disabled.
*/
return (DTRACE_INVOP_NOP);
}
}
return (0);
}
/*ARGSUSED*/
static void
{
int len;
/*
* One for all, and all for one: if we haven't yet registered all of
* our providers, we'll refuse to provide anything.
*/
return;
}
return;
int i, j;
break;
}
}
for (i = 0, j = 0; name[j] != '\0'; i++) {
nname[i] = '-';
j += 2;
} else {
}
}
nname[i] = '\0';
func = "<unknown>";
/*
* We have our provider. Now create the probe.
*/
} else {
mp->sdt_nprobes++;
}
sdp->sdp_hashnext =
}
}
/*ARGSUSED*/
static void
{
int ndx;
ctl->mod_loaded)) {
}
}
/*
* Now we need to remove this probe from the sdt_probetab.
*/
}
} else {
}
}
}
/*ARGSUSED*/
static int
{
ctl->mod_nenabled++;
/*
* If this module has disappeared since we discovered its probes,
* refuse to enable it.
*/
if (!ctl->mod_loaded) {
if (sdt_verbose) {
"(module %s unloaded)",
}
goto err;
}
/*
* Now check that our modctl has the expected load count. If it
* doesn't, this module must have been unloaded and reloaded -- and
* we're not going to touch it.
*/
if (sdt_verbose) {
"(module %s reloaded)",
}
goto err;
}
}
err:
return (0);
}
/*ARGSUSED*/
static void
{
ctl->mod_nenabled--;
goto err;
}
err:
;
}
/*ARGSUSED*/
{
int i;
#if defined(__amd64)
/*
* A total of 6 arguments are passed via registers; any argument with
* index of 5 or lower is therefore in a register.
*/
int inreg = 5;
#endif
for (i = 1; i <= aframes; i++) {
#if !defined(__amd64)
/*
* If we pass through the invalid op handler, we will
* use the pointer that it passed to the stack as the
* second argument to dtrace_invop() as the pointer to
* the stack.
*/
#else
/*
* In the case of amd64, we will use the pointer to the
* regs structure that was pushed when we took the
* trap. To get this structure, we must increment
* beyond the frame structure. If the argument that
* we're seeking is passed on the stack, we'll pull
* the true stack pointer out of the saved registers
* and decrement our argument by the number of
* arguments passed in registers; if the argument
* we're seeking is passed in regsiters, we can just
* load it directly.
*/
sizeof (uintptr_t));
} else {
}
#endif
goto load;
}
}
/*
* We know that we did not come through a trap to get into
* dtrace_probe() -- the provider simply called dtrace_probe()
* directly. As this is the case, we need to shift the argument
* that we're looking for: the probe ID is the first argument to
* dtrace_probe(), so the argument n will actually be found where
* one would expect to find argument (n + 1).
*/
argno++;
#if defined(__amd64)
/*
* This shouldn't happen. If the argument is passed in a
* register then it should have been, well, passed in a
* register...
*/
return (0);
}
#endif
load:
return (val);
}
static dtrace_pops_t sdt_pops = {
NULL,
NULL,
NULL,
NULL,
};
/*ARGSUSED*/
static int
{
return (DDI_FAILURE);
}
if (sdt_probetab_size == 0)
} else {
}
}
}
return (DDI_SUCCESS);
}
/*ARGSUSED*/
static int
{
switch (cmd) {
case DDI_DETACH:
break;
case DDI_SUSPEND:
return (DDI_SUCCESS);
default:
return (DDI_FAILURE);
}
return (DDI_FAILURE);
}
}
return (DDI_SUCCESS);
}
/*ARGSUSED*/
static int
{
int error;
switch (infocmd) {
case DDI_INFO_DEVT2DEVINFO:
error = DDI_SUCCESS;
break;
case DDI_INFO_DEVT2INSTANCE:
*result = (void *)0;
error = DDI_SUCCESS;
break;
default:
error = DDI_FAILURE;
}
return (error);
}
/*ARGSUSED*/
static int
{
return (0);
}
static struct cb_ops sdt_cb_ops = {
sdt_open, /* open */
nodev, /* close */
nulldev, /* strategy */
nulldev, /* print */
nodev, /* dump */
nodev, /* read */
nodev, /* write */
nodev, /* ioctl */
nodev, /* devmap */
nodev, /* mmap */
nodev, /* segmap */
nochpoll, /* poll */
ddi_prop_op, /* cb_prop_op */
0, /* streamtab */
};
DEVO_REV, /* devo_rev, */
0, /* refcnt */
sdt_info, /* get_dev_info */
nulldev, /* identify */
nulldev, /* probe */
sdt_attach, /* attach */
sdt_detach, /* detach */
nodev, /* reset */
&sdt_cb_ops, /* driver operations */
NULL, /* bus operations */
nodev, /* dev power */
ddi_quiesce_not_needed, /* quiesce */
};
/*
* Module linkage information for the kernel.
*/
&mod_driverops, /* module type (this is a pseudo driver) */
"Statically Defined Tracing", /* name of module */
&sdt_ops, /* driver ops */
};
static struct modlinkage modlinkage = {
(void *)&modldrv,
};
int
_init(void)
{
return (mod_install(&modlinkage));
}
int
{
}
int
_fini(void)
{
return (mod_remove(&modlinkage));
}