⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fbt.c

📁 Sun Solaris 10 中的 DTrace 组件的源代码。请参看: http://www.sun.com/software/solaris/observability.jsp
💻 C
📖 第 1 页 / 共 2 页
字号:
	int ndx;	do {		if (ctl != NULL && ctl->mod_loadcnt == fbt->fbtp_loadcnt) {			if ((ctl->mod_loadcnt == fbt->fbtp_loadcnt &&			    ctl->mod_loaded)) {				((struct module *)				    (ctl->mod_mp))->fbt_nentries--;			}		}		/*		 * Now we need to remove this probe from the fbt_probetab.		 */		ndx = FBT_ADDR2NDX(fbt->fbtp_patchpoint);		last = NULL;		hash = fbt_probetab[ndx];		while (hash != fbt) {			ASSERT(hash != NULL);			last = hash;			hash = hash->fbtp_hashnext;		}		if (last != NULL) {			last->fbtp_hashnext = fbt->fbtp_hashnext;		} else {			fbt_probetab[ndx] = fbt->fbtp_hashnext;		}		next = fbt->fbtp_next;		kmem_free(fbt, sizeof (fbt_probe_t));		fbt = next;	} while (fbt != NULL);}/*ARGSUSED*/static voidfbt_enable(void *arg, dtrace_id_t id, void *parg){	fbt_probe_t *fbt = parg;	struct modctl *ctl = fbt->fbtp_ctl;	ctl->mod_nenabled++;	if (!ctl->mod_loaded) {		if (fbt_verbose) {			cmn_err(CE_NOTE, "fbt is failing for probe %s "			    "(module %s unloaded)",			    fbt->fbtp_name, ctl->mod_modname);		}		return;	}	/*	 * 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 (ctl->mod_loadcnt != fbt->fbtp_loadcnt) {		if (fbt_verbose) {			cmn_err(CE_NOTE, "fbt is failing for probe %s "			    "(module %s reloaded)",			    fbt->fbtp_name, ctl->mod_modname);		}		return;	}	for (; fbt != NULL; fbt = fbt->fbtp_next)		*fbt->fbtp_patchpoint = fbt->fbtp_patchval;}/*ARGSUSED*/static voidfbt_disable(void *arg, dtrace_id_t id, void *parg){	fbt_probe_t *fbt = parg;	struct modctl *ctl = fbt->fbtp_ctl;	ASSERT(ctl->mod_nenabled > 0);	ctl->mod_nenabled--;	if (!ctl->mod_loaded || (ctl->mod_loadcnt != fbt->fbtp_loadcnt))		return;	for (; fbt != NULL; fbt = fbt->fbtp_next)		*fbt->fbtp_patchpoint = fbt->fbtp_savedval;}/*ARGSUSED*/static voidfbt_suspend(void *arg, dtrace_id_t id, void *parg){	fbt_probe_t *fbt = parg;	struct modctl *ctl = fbt->fbtp_ctl;	ASSERT(ctl->mod_nenabled > 0);	if (!ctl->mod_loaded || (ctl->mod_loadcnt != fbt->fbtp_loadcnt))		return;	for (; fbt != NULL; fbt = fbt->fbtp_next)		*fbt->fbtp_patchpoint = fbt->fbtp_savedval;}/*ARGSUSED*/static voidfbt_resume(void *arg, dtrace_id_t id, void *parg){	fbt_probe_t *fbt = parg;	struct modctl *ctl = fbt->fbtp_ctl;	ASSERT(ctl->mod_nenabled > 0);	if (!ctl->mod_loaded || (ctl->mod_loadcnt != fbt->fbtp_loadcnt))		return;	for (; fbt != NULL; fbt = fbt->fbtp_next)		*fbt->fbtp_patchpoint = fbt->fbtp_patchval;}/*ARGSUSED*/static voidfbt_getargdesc(void *arg, dtrace_id_t id, void *parg, dtrace_argdesc_t *desc){	fbt_probe_t *fbt = parg;	struct modctl *ctl = fbt->fbtp_ctl;	struct module *mp = ctl->mod_mp;	ctf_file_t *fp = NULL, *pfp;	ctf_funcinfo_t f;	int error;	ctf_id_t argv[32], type;	int argc = sizeof (argv) / sizeof (ctf_id_t);	const char *parent;	if (!ctl->mod_loaded || (ctl->mod_loadcnt != fbt->fbtp_loadcnt))		goto err;	if (fbt->fbtp_roffset != 0 && desc->dtargd_ndx == 0) {		(void) strcpy(desc->dtargd_native, "int");		return;	}	if ((fp = ctf_modopen(mp, &error)) == NULL) {		/*		 * We have no CTF information for this module -- and therefore		 * no args[] information.		 */		goto err;	}	/*	 * If we have a parent container, we must manually import it.	 */	if ((parent = ctf_parent_name(fp)) != NULL) {		struct modctl *mod;		/*		 * We must iterate over all modules to find the module that		 * is our parent.		 */		for (mod = &modules; mod != NULL; mod = mod->mod_next) {			if (strcmp(mod->mod_filename, parent) == 0)				break;		}		if (mod == NULL)			goto err;		if ((pfp = ctf_modopen(mod->mod_mp, &error)) == NULL)			goto err;		if (ctf_import(fp, pfp) != 0) {			ctf_close(pfp);			goto err;		}		ctf_close(pfp);	}	if (ctf_func_info(fp, fbt->fbtp_symndx, &f) == CTF_ERR)		goto err;	if (fbt->fbtp_roffset != 0) {		if (desc->dtargd_ndx > 1)			goto err;		ASSERT(desc->dtargd_ndx == 1);		type = f.ctc_return;	} else {		if (desc->dtargd_ndx + 1 > f.ctc_argc)			goto err;		if (ctf_func_args(fp, fbt->fbtp_symndx, argc, argv) == CTF_ERR)			goto err;		type = argv[desc->dtargd_ndx];	}	if (ctf_type_name(fp, type, desc->dtargd_native,	    DTRACE_ARGTYPELEN) != NULL) {		ctf_close(fp);		return;	}err:	if (fp != NULL)		ctf_close(fp);	desc->dtargd_ndx = DTRACE_ARGNONE;}static dtrace_pattr_t fbt_attr = {{ DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_ISA },{ DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_UNKNOWN },{ DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_UNKNOWN },{ DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_ISA },{ DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_ISA },};static dtrace_pops_t fbt_pops = {	NULL,	fbt_provide_module,	fbt_enable,	fbt_disable,	fbt_suspend,	fbt_resume,	fbt_getargdesc,	NULL,	NULL,	fbt_destroy};static voidfbt_cleanup(dev_info_t *devi){	dtrace_invop_remove(fbt_invop);	ddi_remove_minor_node(devi, NULL);	kmem_free(fbt_probetab, fbt_probetab_size * sizeof (fbt_probe_t *));	fbt_probetab = NULL;	fbt_probetab_mask = 0;}static intfbt_attach(dev_info_t *devi, ddi_attach_cmd_t cmd){	switch (cmd) {	case DDI_ATTACH:		break;	case DDI_RESUME:		return (DDI_SUCCESS);	default:		return (DDI_FAILURE);	}	if (fbt_probetab_size == 0)		fbt_probetab_size = FBT_PROBETAB_SIZE;	fbt_probetab_mask = fbt_probetab_size - 1;	fbt_probetab =	    kmem_zalloc(fbt_probetab_size * sizeof (fbt_probe_t *), KM_SLEEP);	dtrace_invop_add(fbt_invop);	if (ddi_create_minor_node(devi, "fbt", S_IFCHR, 0,	    DDI_PSEUDO, NULL) == DDI_FAILURE ||	    dtrace_register("fbt", &fbt_attr, DTRACE_PRIV_KERNEL, 0,	    &fbt_pops, NULL, &fbt_id) != 0) {		fbt_cleanup(devi);		return (DDI_FAILURE);	}	ddi_report_dev(devi);	fbt_devi = devi;	return (DDI_SUCCESS);}static intfbt_detach(dev_info_t *devi, ddi_detach_cmd_t cmd){	switch (cmd) {	case DDI_DETACH:		break;	case DDI_SUSPEND:		return (DDI_SUCCESS);	default:		return (DDI_FAILURE);	}	if (dtrace_unregister(fbt_id) != 0)		return (DDI_FAILURE);	fbt_cleanup(devi);	return (DDI_SUCCESS);}/*ARGSUSED*/static intfbt_info(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg, void **result){	int error;	switch (infocmd) {	case DDI_INFO_DEVT2DEVINFO:		*result = (void *)fbt_devi;		error = DDI_SUCCESS;		break;	case DDI_INFO_DEVT2INSTANCE:		*result = (void *)0;		error = DDI_SUCCESS;		break;	default:		error = DDI_FAILURE;	}	return (error);}/*ARGSUSED*/static intfbt_open(dev_t *devp, int flag, int otyp, cred_t *cred_p){	return (0);}static struct cb_ops fbt_cb_ops = {	fbt_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  */	D_NEW | D_MP		/* Driver compatibility flag */};static struct dev_ops fbt_ops = {	DEVO_REV,		/* devo_rev */	0,			/* refcnt */	fbt_info,		/* get_dev_info */	nulldev,		/* identify */	nulldev,		/* probe */	fbt_attach,		/* attach */	fbt_detach,		/* detach */	nodev,			/* reset */	&fbt_cb_ops,		/* driver operations */	NULL,			/* bus operations */	nodev			/* dev power */};/* * Module linkage information for the kernel. */static struct modldrv modldrv = {	&mod_driverops,		/* module type (this is a pseudo driver) */	"Function Boundary Tracing",	/* name of module */	&fbt_ops,		/* driver ops */};static struct modlinkage modlinkage = {	MODREV_1,	(void *)&modldrv,	NULL};int_init(void){	return (mod_install(&modlinkage));}int_info(struct modinfo *modinfop){	return (mod_info(&modlinkage, modinfop));}int_fini(void){	return (mod_remove(&modlinkage));}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -