14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * CDDL HEADER START
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * The contents of this file are subject to the terms of the
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Common Development and Distribution License (the "License").
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * You may not use this file except in compliance with the License.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * or http://www.opensolaris.org/os/licensing.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * See the License for the specific language governing permissions
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * and limitations under the License.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * When distributing Covered Code, include this CDDL HEADER in each
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * If applicable, add the following below this CDDL HEADER, with the
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * fields enclosed by brackets "[]" replaced with your own identifying
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * information: Portions Copyright [yyyy] [name of copyright owner]
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * CDDL HEADER END
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Use is subject to license terms.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#include <sys/modctl.h>
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#include <sys/dtrace.h>
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#include <sys/kobj.h>
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#include <sys/stat.h>
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#include <sys/ddi.h>
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#include <sys/sunddi.h>
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#include <sys/conf.h>
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#define FBT_PUSHL_EBP 0x55
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#define FBT_MOVL_ESP_EBP0_V0 0x8b
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#define FBT_MOVL_ESP_EBP1_V0 0xec
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#define FBT_MOVL_ESP_EBP0_V1 0x89
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#define FBT_MOVL_ESP_EBP1_V1 0xe5
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#define FBT_REX_RSP_RBP 0x48
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#define FBT_POPL_EBP 0x5d
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#define FBT_RET 0xc3
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#define FBT_RET_IMM16 0xc2
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#define FBT_LEAVE 0xc9
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#ifdef __amd64
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#define FBT_PATCHVAL 0xcc
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#else
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#define FBT_PATCHVAL 0xf0
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#endif
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#define FBT_ENTRY "entry"
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#define FBT_RETURN "return"
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#define FBT_ADDR2NDX(addr) ((((uintptr_t)(addr)) >> 4) & fbt_probetab_mask)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#define FBT_PROBETAB_SIZE 0x8000 /* 32k entries -- 128K total */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsynctypedef struct fbt_probe {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync struct fbt_probe *fbtp_hashnext;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync uint8_t *fbtp_patchpoint;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync int8_t fbtp_rval;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync uint8_t fbtp_patchval;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync uint8_t fbtp_savedval;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync uintptr_t fbtp_roffset;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dtrace_id_t fbtp_id;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync char *fbtp_name;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync struct modctl *fbtp_ctl;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync int fbtp_loadcnt;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync int fbtp_symndx;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync int fbtp_primary;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync struct fbt_probe *fbtp_next;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync} fbt_probe_t;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic dev_info_t *fbt_devi;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic dtrace_provider_id_t fbt_id;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic fbt_probe_t **fbt_probetab;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic int fbt_probetab_size;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic int fbt_probetab_mask;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic int fbt_verbose = 0;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic int
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncfbt_invop(uintptr_t addr, uintptr_t *stack, uintptr_t rval)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync uintptr_t stack0, stack1, stack2, stack3, stack4;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync fbt_probe_t *fbt = fbt_probetab[FBT_ADDR2NDX(addr)];
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync for (; fbt != NULL; fbt = fbt->fbtp_hashnext) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if ((uintptr_t)fbt->fbtp_patchpoint == addr) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (fbt->fbtp_roffset == 0) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync int i = 0;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync /*
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * When accessing the arguments on the stack,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * we must protect against accessing beyond
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * the stack. We can safely set NOFAULT here
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * -- we know that interrupts are already
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * disabled.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync DTRACE_CPUFLAG_SET(CPU_DTRACE_NOFAULT);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync CPU->cpu_dtrace_caller = stack[i++];
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#ifdef __amd64
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync /*
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * On amd64, stack[0] contains the dereferenced
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * stack pointer, stack[1] contains savfp,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * stack[2] contains savpc. We want to step
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * over these entries.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync i += 2;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#endif
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync stack0 = stack[i++];
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync stack1 = stack[i++];
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync stack2 = stack[i++];
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync stack3 = stack[i++];
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync stack4 = stack[i++];
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync DTRACE_CPUFLAG_CLEAR(CPU_DTRACE_NOFAULT |
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync CPU_DTRACE_BADADDR);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dtrace_probe(fbt->fbtp_id, stack0, stack1,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync stack2, stack3, stack4);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync CPU->cpu_dtrace_caller = NULL;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync } else {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#ifdef __amd64
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync /*
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * On amd64, we instrument the ret, not the
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * leave. We therefore need to set the caller
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * to assure that the top frame of a stack()
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * action is correct.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync DTRACE_CPUFLAG_SET(CPU_DTRACE_NOFAULT);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync CPU->cpu_dtrace_caller = stack[0];
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync DTRACE_CPUFLAG_CLEAR(CPU_DTRACE_NOFAULT |
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync CPU_DTRACE_BADADDR);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#endif
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dtrace_probe(fbt->fbtp_id, fbt->fbtp_roffset,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync rval, 0, 0, 0);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync CPU->cpu_dtrace_caller = NULL;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (fbt->fbtp_rval);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (0);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic void
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncfbt_provide_module(void *arg, struct modctl *ctl)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync struct module *mp = ctl->mod_mp;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync char *str = mp->strings;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync int nsyms = mp->nsyms;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync Shdr *symhdr = mp->symhdr;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync char *modname = ctl->mod_modname;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync char *name;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync fbt_probe_t *fbt, *retfbt;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync size_t symsize;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync int i, size;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync /*
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Employees of dtrace and their families are ineligible. Void
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * where prohibited.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (strcmp(modname, "dtrace") == 0)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (ctl->mod_requisites != NULL) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync struct modctl_list *list;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync list = (struct modctl_list *)ctl->mod_requisites;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync for (; list != NULL; list = list->modl_next) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (strcmp(list->modl_modp->mod_modname, "dtrace") == 0)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync /*
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * KMDB is ineligible for instrumentation -- it may execute in
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * any context, including probe context.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (strcmp(modname, "kmdbmod") == 0)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (str == NULL || symhdr == NULL || symhdr->sh_addr == NULL) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync /*
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * If this module doesn't (yet) have its string or symbol
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * table allocated, clear out.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync symsize = symhdr->sh_entsize;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (mp->fbt_nentries) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync /*
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * This module has some FBT entries allocated; we're afraid
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * to screw with it.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync for (i = 1; i < nsyms; i++) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync uint8_t *instr, *limit;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync Sym *sym = (Sym *)(symhdr->sh_addr + i * symsize);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync int j;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (ELF_ST_TYPE(sym->st_info) != STT_FUNC)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync continue;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync /*
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Weak symbols are not candidates. This could be made to
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * work (where weak functions and their underlying function
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * appear as two disjoint probes), but it's not simple.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (ELF_ST_BIND(sym->st_info) == STB_WEAK)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync continue;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync name = str + sym->st_name;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (strstr(name, "dtrace_") == name &&
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync strstr(name, "dtrace_safe_") != name) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync /*
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Anything beginning with "dtrace_" may be called
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * from probe context unless it explitly indicates
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * that it won't be called from probe context by
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * using the prefix "dtrace_safe_".
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync continue;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (strstr(name, "kdi_") == name ||
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync strstr(name, "_kdi_") != NULL) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync /*
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Any function name beginning with "kdi_" or
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * containing the string "_kdi_" is a part of the
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * kernel debugger interface and may be called in
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * arbitrary context -- including probe context.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync continue;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync /*
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Due to 4524008, _init and _fini may have a bloated st_size.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * While this bug was fixed quite some time ago, old drivers
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * may be lurking. We need to develop a better solution to
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * this problem, such that correct _init and _fini functions
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * (the vast majority) may be correctly traced. One solution
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * may be to scan through the entire symbol table to see if
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * any symbol overlaps with _init. If none does, set a bit in
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * the module structure that this module has correct _init and
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * _fini sizes. This will cause some pain the first time a
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * module is scanned, but at least it would be O(N) instead of
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * O(N log N)...
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (strcmp(name, "_init") == 0)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync continue;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (strcmp(name, "_fini") == 0)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync continue;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync /*
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * In order to be eligible, the function must begin with the
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * following sequence:
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * pushl %esp
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * movl %esp, %ebp
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Note that there are two variants of encodings that generate
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * the movl; we must check for both. For 64-bit, we would
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * normally insist that a function begin with the following
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * sequence:
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * pushq %rbp
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * movq %rsp, %rbp
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * However, the compiler for 64-bit often splits these two
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * instructions -- and the first instruction in the function
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * is often not the pushq. As a result, on 64-bit we look
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * for any "pushq %rbp" in the function and we instrument
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * this with a breakpoint instruction.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync instr = (uint8_t *)sym->st_value;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync limit = (uint8_t *)(sym->st_value + sym->st_size);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#ifdef __amd64
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync while (instr < limit) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (*instr == FBT_PUSHL_EBP)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync break;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if ((size = dtrace_instr_size(instr)) <= 0)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync break;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync instr += size;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (instr >= limit || *instr != FBT_PUSHL_EBP) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync /*
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * We either don't save the frame pointer in this
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * function, or we ran into some disassembly
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * screw-up. Either way, we bail.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync continue;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#else
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (instr[0] != FBT_PUSHL_EBP)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync continue;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (!(instr[1] == FBT_MOVL_ESP_EBP0_V0 &&
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync instr[2] == FBT_MOVL_ESP_EBP1_V0) &&
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync !(instr[1] == FBT_MOVL_ESP_EBP0_V1 &&
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync instr[2] == FBT_MOVL_ESP_EBP1_V1))
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync continue;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#endif
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync fbt = kmem_zalloc(sizeof (fbt_probe_t), KM_SLEEP);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync fbt->fbtp_name = name;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync fbt->fbtp_id = dtrace_probe_create(fbt_id, modname,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync name, FBT_ENTRY, 3, fbt);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync fbt->fbtp_patchpoint = instr;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync fbt->fbtp_ctl = ctl;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync fbt->fbtp_loadcnt = ctl->mod_loadcnt;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync fbt->fbtp_rval = DTRACE_INVOP_PUSHL_EBP;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync fbt->fbtp_savedval = *instr;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync fbt->fbtp_patchval = FBT_PATCHVAL;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync fbt->fbtp_hashnext = fbt_probetab[FBT_ADDR2NDX(instr)];
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync fbt->fbtp_symndx = i;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync fbt_probetab[FBT_ADDR2NDX(instr)] = fbt;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync mp->fbt_nentries++;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync retfbt = NULL;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncagain:
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (instr >= limit)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync continue;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync /*
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * If this disassembly fails, then we've likely walked off into
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * a jump table or some other unsuitable area. Bail out of the
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * disassembly now.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if ((size = dtrace_instr_size(instr)) <= 0)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync continue;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#ifdef __amd64
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync /*
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * We only instrument "ret" on amd64 -- we don't yet instrument
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * ret imm16, largely because the compiler doesn't seem to
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * (yet) emit them in the kernel...
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (*instr != FBT_RET) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync instr += size;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync goto again;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#else
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (!(size == 1 &&
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync (*instr == FBT_POPL_EBP || *instr == FBT_LEAVE) &&
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync (*(instr + 1) == FBT_RET ||
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *(instr + 1) == FBT_RET_IMM16))) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync instr += size;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync goto again;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#endif
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync /*
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * We (desperately) want to avoid erroneously instrumenting a
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * jump table, especially given that our markers are pretty
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * short: two bytes on x86, and just one byte on amd64. To
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * determine if we're looking at a true instruction sequence
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * or an inline jump table that happens to contain the same
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * byte sequences, we resort to some heuristic sleeze: we
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * treat this instruction as being contained within a pointer,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * and see if that pointer points to within the body of the
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * function. If it does, we refuse to instrument it.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync for (j = 0; j < sizeof (uintptr_t); j++) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync uintptr_t check = (uintptr_t)instr - j;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync uint8_t *ptr;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (check < sym->st_value)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync break;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (check + sizeof (uintptr_t) > (uintptr_t)limit)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync continue;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ptr = *(uint8_t **)check;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (ptr >= (uint8_t *)sym->st_value && ptr < limit) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync instr += size;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync goto again;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync /*
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * We have a winner!
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync fbt = kmem_zalloc(sizeof (fbt_probe_t), KM_SLEEP);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync fbt->fbtp_name = name;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (retfbt == NULL) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync fbt->fbtp_id = dtrace_probe_create(fbt_id, modname,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync name, FBT_RETURN, 3, fbt);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync } else {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync retfbt->fbtp_next = fbt;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync fbt->fbtp_id = retfbt->fbtp_id;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync retfbt = fbt;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync fbt->fbtp_patchpoint = instr;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync fbt->fbtp_ctl = ctl;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync fbt->fbtp_loadcnt = ctl->mod_loadcnt;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#ifndef __amd64
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (*instr == FBT_POPL_EBP) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync fbt->fbtp_rval = DTRACE_INVOP_POPL_EBP;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync } else {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ASSERT(*instr == FBT_LEAVE);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync fbt->fbtp_rval = DTRACE_INVOP_LEAVE;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync fbt->fbtp_roffset =
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync (uintptr_t)(instr - (uint8_t *)sym->st_value) + 1;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#else
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ASSERT(*instr == FBT_RET);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync fbt->fbtp_rval = DTRACE_INVOP_RET;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync fbt->fbtp_roffset =
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync (uintptr_t)(instr - (uint8_t *)sym->st_value);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync#endif
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync fbt->fbtp_savedval = *instr;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync fbt->fbtp_patchval = FBT_PATCHVAL;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync fbt->fbtp_hashnext = fbt_probetab[FBT_ADDR2NDX(instr)];
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync fbt->fbtp_symndx = i;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync fbt_probetab[FBT_ADDR2NDX(instr)] = fbt;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync mp->fbt_nentries++;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync instr += size;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync goto again;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic void
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncfbt_destroy(void *arg, dtrace_id_t id, void *parg)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync fbt_probe_t *fbt = parg, *next, *hash, *last;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync struct modctl *ctl = fbt->fbtp_ctl;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync int ndx;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync do {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (ctl != NULL && ctl->mod_loadcnt == fbt->fbtp_loadcnt) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if ((ctl->mod_loadcnt == fbt->fbtp_loadcnt &&
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ctl->mod_loaded)) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ((struct module *)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync (ctl->mod_mp))->fbt_nentries--;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync /*
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Now we need to remove this probe from the fbt_probetab.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ndx = FBT_ADDR2NDX(fbt->fbtp_patchpoint);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync last = NULL;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync hash = fbt_probetab[ndx];
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync while (hash != fbt) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ASSERT(hash != NULL);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync last = hash;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync hash = hash->fbtp_hashnext;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (last != NULL) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync last->fbtp_hashnext = fbt->fbtp_hashnext;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync } else {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync fbt_probetab[ndx] = fbt->fbtp_hashnext;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync next = fbt->fbtp_next;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync kmem_free(fbt, sizeof (fbt_probe_t));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync fbt = next;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync } while (fbt != NULL);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic int
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncfbt_enable(void *arg, dtrace_id_t id, void *parg)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync fbt_probe_t *fbt = parg;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync struct modctl *ctl = fbt->fbtp_ctl;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ctl->mod_nenabled++;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (!ctl->mod_loaded) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (fbt_verbose) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync cmn_err(CE_NOTE, "fbt is failing for probe %s "
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "(module %s unloaded)",
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync fbt->fbtp_name, ctl->mod_modname);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (0);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync /*
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Now check that our modctl has the expected load count. If it
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * doesn't, this module must have been unloaded and reloaded -- and
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * we're not going to touch it.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (ctl->mod_loadcnt != fbt->fbtp_loadcnt) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (fbt_verbose) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync cmn_err(CE_NOTE, "fbt is failing for probe %s "
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "(module %s reloaded)",
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync fbt->fbtp_name, ctl->mod_modname);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (0);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync for (; fbt != NULL; fbt = fbt->fbtp_next)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *fbt->fbtp_patchpoint = fbt->fbtp_patchval;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (0);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic void
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncfbt_disable(void *arg, dtrace_id_t id, void *parg)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync fbt_probe_t *fbt = parg;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync struct modctl *ctl = fbt->fbtp_ctl;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ASSERT(ctl->mod_nenabled > 0);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ctl->mod_nenabled--;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (!ctl->mod_loaded || (ctl->mod_loadcnt != fbt->fbtp_loadcnt))
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync for (; fbt != NULL; fbt = fbt->fbtp_next)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *fbt->fbtp_patchpoint = fbt->fbtp_savedval;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic void
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncfbt_suspend(void *arg, dtrace_id_t id, void *parg)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync fbt_probe_t *fbt = parg;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync struct modctl *ctl = fbt->fbtp_ctl;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ASSERT(ctl->mod_nenabled > 0);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (!ctl->mod_loaded || (ctl->mod_loadcnt != fbt->fbtp_loadcnt))
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync for (; fbt != NULL; fbt = fbt->fbtp_next)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *fbt->fbtp_patchpoint = fbt->fbtp_savedval;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic void
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncfbt_resume(void *arg, dtrace_id_t id, void *parg)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync fbt_probe_t *fbt = parg;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync struct modctl *ctl = fbt->fbtp_ctl;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ASSERT(ctl->mod_nenabled > 0);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (!ctl->mod_loaded || (ctl->mod_loadcnt != fbt->fbtp_loadcnt))
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync for (; fbt != NULL; fbt = fbt->fbtp_next)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *fbt->fbtp_patchpoint = fbt->fbtp_patchval;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic void
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncfbt_getargdesc(void *arg, dtrace_id_t id, void *parg, dtrace_argdesc_t *desc)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync fbt_probe_t *fbt = parg;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync struct modctl *ctl = fbt->fbtp_ctl;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync struct module *mp = ctl->mod_mp;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ctf_file_t *fp = NULL, *pfp;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ctf_funcinfo_t f;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync int error;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ctf_id_t argv[32], type;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync int argc = sizeof (argv) / sizeof (ctf_id_t);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync const char *parent;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (!ctl->mod_loaded || (ctl->mod_loadcnt != fbt->fbtp_loadcnt))
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync goto err;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (fbt->fbtp_roffset != 0 && desc->dtargd_ndx == 0) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync (void) strcpy(desc->dtargd_native, "int");
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if ((fp = ctf_modopen(mp, &error)) == NULL) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync /*
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * We have no CTF information for this module -- and therefore
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * no args[] information.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync goto err;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync /*
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * If we have a parent container, we must manually import it.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if ((parent = ctf_parent_name(fp)) != NULL) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync struct modctl *mp = &modules;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync struct modctl *mod = NULL;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync /*
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * We must iterate over all modules to find the module that
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * is our parent.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync do {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (strcmp(mp->mod_modname, parent) == 0) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync mod = mp;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync break;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync } while ((mp = mp->mod_next) != &modules);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (mod == NULL)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync goto err;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if ((pfp = ctf_modopen(mod->mod_mp, &error)) == NULL) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync goto err;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (ctf_import(fp, pfp) != 0) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ctf_close(pfp);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync goto err;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ctf_close(pfp);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (ctf_func_info(fp, fbt->fbtp_symndx, &f) == CTF_ERR)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync goto err;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (fbt->fbtp_roffset != 0) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (desc->dtargd_ndx > 1)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync goto err;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ASSERT(desc->dtargd_ndx == 1);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync type = f.ctc_return;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync } else {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (desc->dtargd_ndx + 1 > f.ctc_argc)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync goto err;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (ctf_func_args(fp, fbt->fbtp_symndx, argc, argv) == CTF_ERR)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync goto err;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync type = argv[desc->dtargd_ndx];
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (ctf_type_name(fp, type, desc->dtargd_native,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync DTRACE_ARGTYPELEN) != NULL) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ctf_close(fp);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncerr:
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (fp != NULL)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ctf_close(fp);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync desc->dtargd_ndx = DTRACE_ARGNONE;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic dtrace_pattr_t fbt_attr = {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{ DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_ISA },
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{ DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_UNKNOWN },
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{ DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_UNKNOWN },
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{ DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_ISA },
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{ DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_ISA },
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync};
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic dtrace_pops_t fbt_pops = {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync NULL,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync fbt_provide_module,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync fbt_enable,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync fbt_disable,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync fbt_suspend,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync fbt_resume,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync fbt_getargdesc,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync NULL,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync NULL,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync fbt_destroy
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync};
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic void
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncfbt_cleanup(dev_info_t *devi)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dtrace_invop_remove(fbt_invop);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ddi_remove_minor_node(devi, NULL);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync kmem_free(fbt_probetab, fbt_probetab_size * sizeof (fbt_probe_t *));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync fbt_probetab = NULL;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync fbt_probetab_mask = 0;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic int
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncfbt_attach(dev_info_t *devi, ddi_attach_cmd_t cmd)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync switch (cmd) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case DDI_ATTACH:
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync break;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case DDI_RESUME:
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (DDI_SUCCESS);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync default:
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (DDI_FAILURE);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (fbt_probetab_size == 0)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync fbt_probetab_size = FBT_PROBETAB_SIZE;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync fbt_probetab_mask = fbt_probetab_size - 1;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync fbt_probetab =
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync kmem_zalloc(fbt_probetab_size * sizeof (fbt_probe_t *), KM_SLEEP);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dtrace_invop_add(fbt_invop);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (ddi_create_minor_node(devi, "fbt", S_IFCHR, 0,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync DDI_PSEUDO, NULL) == DDI_FAILURE ||
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync dtrace_register("fbt", &fbt_attr, DTRACE_PRIV_KERNEL, NULL,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync &fbt_pops, NULL, &fbt_id) != 0) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync fbt_cleanup(devi);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (DDI_FAILURE);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ddi_report_dev(devi);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync fbt_devi = devi;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (DDI_SUCCESS);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic int
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncfbt_detach(dev_info_t *devi, ddi_detach_cmd_t cmd)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync switch (cmd) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case DDI_DETACH:
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync break;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case DDI_SUSPEND:
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (DDI_SUCCESS);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync default:
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (DDI_FAILURE);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (dtrace_unregister(fbt_id) != 0)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (DDI_FAILURE);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync fbt_cleanup(devi);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (DDI_SUCCESS);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic int
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncfbt_info(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg, void **result)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync int error;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync switch (infocmd) {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case DDI_INFO_DEVT2DEVINFO:
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *result = (void *)fbt_devi;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync error = DDI_SUCCESS;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync break;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync case DDI_INFO_DEVT2INSTANCE:
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync *result = (void *)0;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync error = DDI_SUCCESS;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync break;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync default:
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync error = DDI_FAILURE;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync }
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (error);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*ARGSUSED*/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic int
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncfbt_open(dev_t *devp, int flag, int otyp, cred_t *cred_p)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (0);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic struct cb_ops fbt_cb_ops = {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync fbt_open, /* open */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync nodev, /* close */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync nulldev, /* strategy */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync nulldev, /* print */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync nodev, /* dump */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync nodev, /* read */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync nodev, /* write */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync nodev, /* ioctl */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync nodev, /* devmap */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync nodev, /* mmap */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync nodev, /* segmap */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync nochpoll, /* poll */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ddi_prop_op, /* cb_prop_op */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync 0, /* streamtab */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync D_NEW | D_MP /* Driver compatibility flag */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync};
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic struct dev_ops fbt_ops = {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync DEVO_REV, /* devo_rev */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync 0, /* refcnt */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync fbt_info, /* get_dev_info */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync nulldev, /* identify */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync nulldev, /* probe */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync fbt_attach, /* attach */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync fbt_detach, /* detach */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync nodev, /* reset */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync &fbt_cb_ops, /* driver operations */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync NULL, /* bus operations */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync nodev, /* dev power */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ddi_quiesce_not_needed, /* quiesce */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync};
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Module linkage information for the kernel.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic struct modldrv modldrv = {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync &mod_driverops, /* module type (this is a pseudo driver) */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync "Function Boundary Tracing", /* name of module */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync &fbt_ops, /* driver ops */
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync};
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncstatic struct modlinkage modlinkage = {
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync MODREV_1,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync (void *)&modldrv,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync NULL
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync};
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncint
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync_init(void)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (mod_install(&modlinkage));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncint
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync_info(struct modinfo *modinfop)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (mod_info(&modlinkage, modinfop));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncint
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync_fini(void)
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync{
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync return (mod_remove(&modlinkage));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync}