4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
21 * Portions Copyright 2010 The FreeBSD Foundation
27 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
28 * Use is subject to license terms.
32 #pragma ident "%Z%%M% %I% %E% SMI"
35 #include <sys/atomic.h>
36 #include <sys/errno.h>
38 #include <sys/modctl.h>
40 #include <sys/systm.h>
44 #include <sys/sunddi.h>
45 #include <sys/cpuvar.h>
48 #include <sys/strsubr.h>
50 #include <sys/fasttrap.h>
51 #include <sys/fasttrap_impl.h>
52 #include <sys/fasttrap_isa.h>
53 #include <sys/dtrace.h>
54 #include <sys/dtrace_impl.h>
55 #include <sys/sysmacros.h>
57 #include <sys/policy.h>
59 #include <util/qsort.h>
61 #include <sys/mutex.h>
62 #include <sys/kernel.h>
65 #include <sys/dtrace_bsd.h>
66 #include <cddl/dev/dtrace/dtrace_cddl.h>
70 * User-Land Trap-Based Tracing
71 * ----------------------------
73 * The fasttrap provider allows DTrace consumers to instrument any user-level
74 * instruction to gather data; this includes probes with semantic
75 * signifigance like entry and return as well as simple offsets into the
76 * function. While the specific techniques used are very ISA specific, the
77 * methodology is generalizable to any architecture.
80 * The General Methodology
81 * -----------------------
83 * With the primary goal of tracing every user-land instruction and the
84 * limitation that we can't trust user space so don't want to rely on much
85 * information there, we begin by replacing the instructions we want to trace
86 * with trap instructions. Each instruction we overwrite is saved into a hash
87 * table keyed by process ID and pc address. When we enter the kernel due to
88 * this trap instruction, we need the effects of the replaced instruction to
89 * appear to have occurred before we proceed with the user thread's
92 * Each user level thread is represented by a ulwp_t structure which is
93 * always easily accessible through a register. The most basic way to produce
94 * the effects of the instruction we replaced is to copy that instruction out
95 * to a bit of scratch space reserved in the user thread's ulwp_t structure
96 * (a sort of kernel-private thread local storage), set the PC to that
97 * scratch space and single step. When we reenter the kernel after single
98 * stepping the instruction we must then adjust the PC to point to what would
99 * normally be the next instruction. Of course, special care must be taken
100 * for branches and jumps, but these represent such a small fraction of any
101 * instruction set that writing the code to emulate these in the kernel is
104 * Return probes may require several tracepoints to trace every return site,
105 * and, conversely, each tracepoint may activate several probes (the entry
106 * and offset 0 probes, for example). To solve this muliplexing problem,
107 * tracepoints contain lists of probes to activate and probes contain lists
108 * of tracepoints to enable. If a probe is activated, it adds its ID to
109 * existing tracepoints or creates new ones as necessary.
111 * Most probes are activated _before_ the instruction is executed, but return
112 * probes are activated _after_ the effects of the last instruction of the
113 * function are visible. Return probes must be fired _after_ we have
114 * single-stepped the instruction whereas all other probes are fired
121 * The lock ordering below -- both internally and with respect to the DTrace
122 * framework -- is a little tricky and bears some explanation. Each provider
123 * has a lock (ftp_mtx) that protects its members including reference counts
124 * for enabled probes (ftp_rcount), consumers actively creating probes
125 * (ftp_ccount) and USDT consumers (ftp_mcount); all three prevent a provider
126 * from being freed. A provider is looked up by taking the bucket lock for the
127 * provider hash table, and is returned with its lock held. The provider lock
128 * may be taken in functions invoked by the DTrace framework, but may not be
129 * held while calling functions in the DTrace framework.
131 * To ensure consistency over multiple calls to the DTrace framework, the
132 * creation lock (ftp_cmtx) should be held. Naturally, the creation lock may
133 * not be taken when holding the provider lock as that would create a cyclic
134 * lock ordering. In situations where one would naturally take the provider
135 * lock and then the creation lock, we instead up a reference count to prevent
136 * the provider from disappearing, drop the provider lock, and acquire the
140 * bucket lock before provider lock
141 * DTrace before provider lock
142 * creation lock before DTrace
143 * never hold the provider lock and creation lock simultaneously
146 static d_open_t fasttrap_open;
147 static d_ioctl_t fasttrap_ioctl;
149 static struct cdevsw fasttrap_cdevsw = {
150 .d_version = D_VERSION,
151 .d_open = fasttrap_open,
152 .d_ioctl = fasttrap_ioctl,
153 .d_name = "fasttrap",
155 static struct cdev *fasttrap_cdev;
156 static dtrace_meta_provider_id_t fasttrap_meta_id;
158 static struct proc *fasttrap_cleanup_proc;
159 static struct mtx fasttrap_cleanup_mtx;
160 static uint_t fasttrap_cleanup_work, fasttrap_cleanup_drain, fasttrap_cleanup_cv;
163 * Generation count on modifications to the global tracepoint lookup table.
165 static volatile uint64_t fasttrap_mod_gen;
168 * When the fasttrap provider is loaded, fasttrap_max is set to either
169 * FASTTRAP_MAX_DEFAULT or the value for fasttrap-max-probes in the
170 * fasttrap.conf file. Each time a probe is created, fasttrap_total is
171 * incremented by the number of tracepoints that may be associated with that
172 * probe; fasttrap_total is capped at fasttrap_max.
174 #define FASTTRAP_MAX_DEFAULT 250000
175 static uint32_t fasttrap_max;
176 static uint32_t fasttrap_total;
179 * Copyright (c) 2011, Joyent, Inc. All rights reserved.
182 #define FASTTRAP_TPOINTS_DEFAULT_SIZE 0x4000
183 #define FASTTRAP_PROVIDERS_DEFAULT_SIZE 0x100
184 #define FASTTRAP_PROCS_DEFAULT_SIZE 0x100
186 #define FASTTRAP_PID_NAME "pid"
188 fasttrap_hash_t fasttrap_tpoints;
189 static fasttrap_hash_t fasttrap_provs;
190 static fasttrap_hash_t fasttrap_procs;
192 static uint64_t fasttrap_pid_count; /* pid ref count */
193 static kmutex_t fasttrap_count_mtx; /* lock on ref count */
195 #define FASTTRAP_ENABLE_FAIL 1
196 #define FASTTRAP_ENABLE_PARTIAL 2
198 static int fasttrap_tracepoint_enable(proc_t *, fasttrap_probe_t *, uint_t);
199 static void fasttrap_tracepoint_disable(proc_t *, fasttrap_probe_t *, uint_t);
201 static fasttrap_provider_t *fasttrap_provider_lookup(pid_t, const char *,
202 const dtrace_pattr_t *);
203 static void fasttrap_provider_retire(pid_t, const char *, int);
204 static void fasttrap_provider_free(fasttrap_provider_t *);
206 static fasttrap_proc_t *fasttrap_proc_lookup(pid_t);
207 static void fasttrap_proc_release(fasttrap_proc_t *);
209 #define FASTTRAP_PROVS_INDEX(pid, name) \
210 ((fasttrap_hash_str(name) + (pid)) & fasttrap_provs.fth_mask)
212 #define FASTTRAP_PROCS_INDEX(pid) ((pid) & fasttrap_procs.fth_mask)
215 static kmutex_t fasttrap_cpuc_pid_lock[MAXCPU];
219 fasttrap_highbit(ulong_t i)
226 if (i & 0xffffffff00000000ul) {
230 if (i & 0xffff0000) {
249 fasttrap_hash_str(const char *p)
255 hval = (hval << 4) + *p++;
256 if ((g = (hval & 0xf0000000)) != 0)
264 fasttrap_sigtrap(proc_t *p, kthread_t *t, uintptr_t pc)
267 sigqueue_t *sqp = kmem_zalloc(sizeof (sigqueue_t), KM_SLEEP);
269 sqp->sq_info.si_signo = SIGTRAP;
270 sqp->sq_info.si_code = TRAP_DTRACE;
271 sqp->sq_info.si_addr = (caddr_t)pc;
273 mutex_enter(&p->p_lock);
275 mutex_exit(&p->p_lock);
280 ksiginfo_t *ksi = kmem_zalloc(sizeof (ksiginfo_t), KM_SLEEP);
283 ksi->ksi_signo = SIGTRAP;
284 ksi->ksi_code = TRAP_DTRACE;
285 ksi->ksi_addr = (caddr_t)pc;
287 (void) tdksignal(t, SIGTRAP, ksi);
293 * This function ensures that no threads are actively using the memory
294 * associated with probes that were formerly live.
297 fasttrap_mod_barrier(uint64_t gen)
301 if (gen < fasttrap_mod_gen)
307 mutex_enter(&fasttrap_cpuc_pid_lock[i]);
308 mutex_exit(&fasttrap_cpuc_pid_lock[i]);
313 * This function performs asynchronous cleanup of fasttrap providers. The
314 * Solaris implementation of this mechanism use a timeout that's activated in
315 * fasttrap_pid_cleanup(), but this doesn't work in FreeBSD: one may sleep while
316 * holding the DTrace mutexes, but it is unsafe to sleep in a callout handler.
317 * Thus we use a dedicated process to perform the cleanup when requested.
321 fasttrap_pid_cleanup_cb(void *data)
323 fasttrap_provider_t **fpp, *fp;
324 fasttrap_bucket_t *bucket;
325 dtrace_provider_id_t provid;
326 int i, later = 0, rval;
328 mtx_lock(&fasttrap_cleanup_mtx);
329 while (!fasttrap_cleanup_drain || later > 0) {
330 fasttrap_cleanup_work = 0;
331 mtx_unlock(&fasttrap_cleanup_mtx);
336 * Iterate over all the providers trying to remove the marked
337 * ones. If a provider is marked but not retired, we just
338 * have to take a crack at removing it -- it's no big deal if
341 for (i = 0; i < fasttrap_provs.fth_nent; i++) {
342 bucket = &fasttrap_provs.fth_table[i];
343 mutex_enter(&bucket->ftb_mtx);
344 fpp = (fasttrap_provider_t **)&bucket->ftb_data;
346 while ((fp = *fpp) != NULL) {
347 if (!fp->ftp_marked) {
352 mutex_enter(&fp->ftp_mtx);
355 * If this provider has consumers actively
356 * creating probes (ftp_ccount) or is a USDT
357 * provider (ftp_mcount), we can't unregister
360 if (fp->ftp_ccount != 0 ||
361 fp->ftp_mcount != 0) {
362 mutex_exit(&fp->ftp_mtx);
367 if (!fp->ftp_retired || fp->ftp_rcount != 0)
370 mutex_exit(&fp->ftp_mtx);
373 * If we successfully unregister this
374 * provider we can remove it from the hash
375 * chain and free the memory. If our attempt
376 * to unregister fails and this is a retired
377 * provider, increment our flag to try again
378 * pretty soon. If we've consumed more than
379 * half of our total permitted number of
380 * probes call dtrace_condense() to try to
381 * clean out the unenabled probes.
383 provid = fp->ftp_provid;
384 if ((rval = dtrace_unregister(provid)) != 0) {
385 if (fasttrap_total > fasttrap_max / 2)
386 (void) dtrace_condense(provid);
391 later += fp->ftp_marked;
395 fasttrap_provider_free(fp);
398 mutex_exit(&bucket->ftb_mtx);
400 mtx_lock(&fasttrap_cleanup_mtx);
403 * If we were unable to retire a provider, try again after a
404 * second. This situation can occur in certain circumstances
405 * where providers cannot be unregistered even though they have
406 * no probes enabled because of an execution of dtrace -l or
409 if (later > 0 || fasttrap_cleanup_work ||
410 fasttrap_cleanup_drain) {
411 mtx_unlock(&fasttrap_cleanup_mtx);
412 pause("ftclean", hz);
413 mtx_lock(&fasttrap_cleanup_mtx);
415 mtx_sleep(&fasttrap_cleanup_cv, &fasttrap_cleanup_mtx,
420 * Wake up the thread in fasttrap_unload() now that we're done.
422 wakeup(&fasttrap_cleanup_drain);
423 mtx_unlock(&fasttrap_cleanup_mtx);
429 * Activates the asynchronous cleanup mechanism.
432 fasttrap_pid_cleanup(void)
435 mtx_lock(&fasttrap_cleanup_mtx);
436 if (!fasttrap_cleanup_work) {
437 fasttrap_cleanup_work = 1;
438 wakeup(&fasttrap_cleanup_cv);
440 mtx_unlock(&fasttrap_cleanup_mtx);
444 * This is called from cfork() via dtrace_fasttrap_fork(). The child
445 * process's address space is (roughly) a copy of the parent process's so
446 * we have to remove all the instrumentation we had previously enabled in the
450 fasttrap_fork(proc_t *p, proc_t *cp)
452 pid_t ppid = p->p_pid;
456 ASSERT(curproc == p);
457 ASSERT(p->p_proc_flag & P_PR_LOCK);
459 PROC_LOCK_ASSERT(p, MA_OWNED);
462 ASSERT(p->p_dtrace_count > 0);
464 if (p->p_dtrace_helpers) {
466 * dtrace_helpers_duplicate() allocates memory.
471 dtrace_helpers_duplicate(p, cp);
477 * This check is purposely here instead of in kern_fork.c because,
478 * for legal resons, we cannot include the dtrace_cddl.h header
479 * inside kern_fork.c and insert if-clause there.
481 if (p->p_dtrace_count == 0)
484 ASSERT(cp->p_dtrace_count == 0);
487 * This would be simpler and faster if we maintained per-process
488 * hash tables of enabled tracepoints. It could, however, potentially
489 * slow down execution of a tracepoint since we'd need to go
490 * through two levels of indirection. In the future, we should
491 * consider either maintaining per-process ancillary lists of
492 * enabled tracepoints or hanging a pointer to a per-process hash
493 * table of enabled tracepoints off the proc structure.
497 * We don't have to worry about the child process disappearing
498 * because we're in fork().
501 mtx_lock_spin(&cp->p_slock);
503 mtx_unlock_spin(&cp->p_slock);
506 * fasttrap_tracepoint_remove() expects the child process to be
507 * unlocked and the VM then expects curproc to be unlocked.
515 * Iterate over every tracepoint looking for ones that belong to the
516 * parent process, and remove each from the child process.
518 for (i = 0; i < fasttrap_tpoints.fth_nent; i++) {
519 fasttrap_tracepoint_t *tp;
520 fasttrap_bucket_t *bucket = &fasttrap_tpoints.fth_table[i];
522 mutex_enter(&bucket->ftb_mtx);
523 for (tp = bucket->ftb_data; tp != NULL; tp = tp->ftt_next) {
524 if (tp->ftt_pid == ppid &&
525 tp->ftt_proc->ftpc_acount != 0) {
526 int ret = fasttrap_tracepoint_remove(cp, tp);
530 * The count of active providers can only be
531 * decremented (i.e. to zero) during exec,
532 * exit, and removal of a meta provider so it
533 * should be impossible to drop the count
536 ASSERT(tp->ftt_proc->ftpc_acount != 0);
539 mutex_exit(&bucket->ftb_mtx);
543 mutex_enter(&cp->p_lock);
553 * This is called from proc_exit() or from exec_common() if p_dtrace_probes
554 * is set on the proc structure to indicate that there is a pid provider
555 * associated with this process.
558 fasttrap_exec_exit(proc_t *p)
561 ASSERT(p == curproc);
563 PROC_LOCK_ASSERT(p, MA_OWNED);
568 * We clean up the pid provider for this process here; user-land
569 * static probes are handled by the meta-provider remove entry point.
571 fasttrap_provider_retire(p->p_pid, FASTTRAP_PID_NAME, 0);
573 if (p->p_dtrace_helpers)
574 dtrace_helpers_destroy(p);
583 fasttrap_pid_provide(void *arg, dtrace_probedesc_t *desc)
586 * There are no "default" pid probes.
591 fasttrap_tracepoint_enable(proc_t *p, fasttrap_probe_t *probe, uint_t index)
593 fasttrap_tracepoint_t *tp, *new_tp = NULL;
594 fasttrap_bucket_t *bucket;
599 ASSERT(index < probe->ftp_ntps);
601 pid = probe->ftp_pid;
602 pc = probe->ftp_tps[index].fit_tp->ftt_pc;
603 id = &probe->ftp_tps[index].fit_id;
605 ASSERT(probe->ftp_tps[index].fit_tp->ftt_pid == pid);
608 ASSERT(!(p->p_flag & SVFORK));
612 * Before we make any modifications, make sure we've imposed a barrier
613 * on the generation in which this probe was last modified.
615 fasttrap_mod_barrier(probe->ftp_gen);
617 bucket = &fasttrap_tpoints.fth_table[FASTTRAP_TPOINTS_INDEX(pid, pc)];
620 * If the tracepoint has already been enabled, just add our id to the
621 * list of interested probes. This may be our second time through
622 * this path in which case we'll have constructed the tracepoint we'd
623 * like to install. If we can't find a match, and have an allocated
624 * tracepoint ready to go, enable that one now.
626 * A tracepoint whose process is defunct is also considered defunct.
629 mutex_enter(&bucket->ftb_mtx);
630 for (tp = bucket->ftb_data; tp != NULL; tp = tp->ftt_next) {
632 * Note that it's safe to access the active count on the
633 * associated proc structure because we know that at least one
634 * provider (this one) will still be around throughout this
637 if (tp->ftt_pid != pid || tp->ftt_pc != pc ||
638 tp->ftt_proc->ftpc_acount == 0)
642 * Now that we've found a matching tracepoint, it would be
643 * a decent idea to confirm that the tracepoint is still
644 * enabled and the trap instruction hasn't been overwritten.
645 * Since this is a little hairy, we'll punt for now.
649 * This can't be the first interested probe. We don't have
650 * to worry about another thread being in the midst of
651 * deleting this tracepoint (which would be the only valid
652 * reason for a tracepoint to have no interested probes)
653 * since we're holding P_PR_LOCK for this process.
655 ASSERT(tp->ftt_ids != NULL || tp->ftt_retids != NULL);
657 switch (id->fti_ptype) {
660 case DTFTP_IS_ENABLED:
661 id->fti_next = tp->ftt_ids;
668 case DTFTP_POST_OFFSETS:
669 id->fti_next = tp->ftt_retids;
679 mutex_exit(&bucket->ftb_mtx);
681 if (new_tp != NULL) {
682 new_tp->ftt_ids = NULL;
683 new_tp->ftt_retids = NULL;
690 * If we have a good tracepoint ready to go, install it now while
691 * we have the lock held and no one can screw with us.
693 if (new_tp != NULL) {
696 new_tp->ftt_next = bucket->ftb_data;
698 bucket->ftb_data = new_tp;
700 mutex_exit(&bucket->ftb_mtx);
703 * Activate the tracepoint in the ISA-specific manner.
704 * If this fails, we need to report the failure, but
705 * indicate that this tracepoint must still be disabled
706 * by calling fasttrap_tracepoint_disable().
708 if (fasttrap_tracepoint_install(p, new_tp) != 0)
709 rc = FASTTRAP_ENABLE_PARTIAL;
712 * Increment the count of the number of tracepoints active in
713 * the victim process.
716 ASSERT(p->p_proc_flag & P_PR_LOCK);
723 mutex_exit(&bucket->ftb_mtx);
726 * Initialize the tracepoint that's been preallocated with the probe.
728 new_tp = probe->ftp_tps[index].fit_tp;
730 ASSERT(new_tp->ftt_pid == pid);
731 ASSERT(new_tp->ftt_pc == pc);
732 ASSERT(new_tp->ftt_proc == probe->ftp_prov->ftp_proc);
733 ASSERT(new_tp->ftt_ids == NULL);
734 ASSERT(new_tp->ftt_retids == NULL);
736 switch (id->fti_ptype) {
739 case DTFTP_IS_ENABLED:
741 new_tp->ftt_ids = id;
745 case DTFTP_POST_OFFSETS:
747 new_tp->ftt_retids = id;
755 * If the ISA-dependent initialization goes to plan, go back to the
756 * beginning and try to install this freshly made tracepoint.
758 if (fasttrap_tracepoint_init(p, new_tp, pc, id->fti_ptype) == 0)
761 new_tp->ftt_ids = NULL;
762 new_tp->ftt_retids = NULL;
764 return (FASTTRAP_ENABLE_FAIL);
768 fasttrap_tracepoint_disable(proc_t *p, fasttrap_probe_t *probe, uint_t index)
770 fasttrap_bucket_t *bucket;
771 fasttrap_provider_t *provider = probe->ftp_prov;
772 fasttrap_tracepoint_t **pp, *tp;
773 fasttrap_id_t *id, **idp = NULL;
777 ASSERT(index < probe->ftp_ntps);
779 pid = probe->ftp_pid;
780 pc = probe->ftp_tps[index].fit_tp->ftt_pc;
781 id = &probe->ftp_tps[index].fit_id;
783 ASSERT(probe->ftp_tps[index].fit_tp->ftt_pid == pid);
786 * Find the tracepoint and make sure that our id is one of the
787 * ones registered with it.
789 bucket = &fasttrap_tpoints.fth_table[FASTTRAP_TPOINTS_INDEX(pid, pc)];
790 mutex_enter(&bucket->ftb_mtx);
791 for (tp = bucket->ftb_data; tp != NULL; tp = tp->ftt_next) {
792 if (tp->ftt_pid == pid && tp->ftt_pc == pc &&
793 tp->ftt_proc == provider->ftp_proc)
798 * If we somehow lost this tracepoint, we're in a world of hurt.
802 switch (id->fti_ptype) {
805 case DTFTP_IS_ENABLED:
806 ASSERT(tp->ftt_ids != NULL);
811 case DTFTP_POST_OFFSETS:
812 ASSERT(tp->ftt_retids != NULL);
813 idp = &tp->ftt_retids;
820 while ((*idp)->fti_probe != probe) {
821 idp = &(*idp)->fti_next;
822 ASSERT(*idp != NULL);
829 ASSERT(id->fti_probe == probe);
832 * If there are other registered enablings of this tracepoint, we're
833 * all done, but if this was the last probe assocated with this
834 * this tracepoint, we need to remove and free it.
836 if (tp->ftt_ids != NULL || tp->ftt_retids != NULL) {
839 * If the current probe's tracepoint is in use, swap it
840 * for an unused tracepoint.
842 if (tp == probe->ftp_tps[index].fit_tp) {
843 fasttrap_probe_t *tmp_probe;
844 fasttrap_tracepoint_t **tmp_tp;
847 if (tp->ftt_ids != NULL) {
848 tmp_probe = tp->ftt_ids->fti_probe;
849 /* LINTED - alignment */
850 tmp_index = FASTTRAP_ID_INDEX(tp->ftt_ids);
851 tmp_tp = &tmp_probe->ftp_tps[tmp_index].fit_tp;
853 tmp_probe = tp->ftt_retids->fti_probe;
854 /* LINTED - alignment */
855 tmp_index = FASTTRAP_ID_INDEX(tp->ftt_retids);
856 tmp_tp = &tmp_probe->ftp_tps[tmp_index].fit_tp;
859 ASSERT(*tmp_tp != NULL);
860 ASSERT(*tmp_tp != probe->ftp_tps[index].fit_tp);
861 ASSERT((*tmp_tp)->ftt_ids == NULL);
862 ASSERT((*tmp_tp)->ftt_retids == NULL);
864 probe->ftp_tps[index].fit_tp = *tmp_tp;
868 mutex_exit(&bucket->ftb_mtx);
871 * Tag the modified probe with the generation in which it was
874 probe->ftp_gen = fasttrap_mod_gen;
878 mutex_exit(&bucket->ftb_mtx);
881 * We can't safely remove the tracepoint from the set of active
882 * tracepoints until we've actually removed the fasttrap instruction
883 * from the process's text. We can, however, operate on this
884 * tracepoint secure in the knowledge that no other thread is going to
885 * be looking at it since we hold P_PR_LOCK on the process if it's
886 * live or we hold the provider lock on the process if it's dead and
891 * We only need to remove the actual instruction if we're looking
892 * at an existing process
896 * If we fail to restore the instruction we need to kill
897 * this process since it's in a completely unrecoverable
900 if (fasttrap_tracepoint_remove(p, tp) != 0)
901 fasttrap_sigtrap(p, NULL, pc);
904 * Decrement the count of the number of tracepoints active
905 * in the victim process.
908 ASSERT(p->p_proc_flag & P_PR_LOCK);
914 * Remove the probe from the hash table of active tracepoints.
916 mutex_enter(&bucket->ftb_mtx);
917 pp = (fasttrap_tracepoint_t **)&bucket->ftb_data;
920 pp = &(*pp)->ftt_next;
927 mutex_exit(&bucket->ftb_mtx);
930 * Tag the modified probe with the generation in which it was changed.
932 probe->ftp_gen = fasttrap_mod_gen;
936 fasttrap_enable_callbacks(void)
939 * We don't have to play the rw lock game here because we're
940 * providing something rather than taking something away --
941 * we can be sure that no threads have tried to follow this
942 * function pointer yet.
944 mutex_enter(&fasttrap_count_mtx);
945 if (fasttrap_pid_count == 0) {
946 ASSERT(dtrace_pid_probe_ptr == NULL);
947 ASSERT(dtrace_return_probe_ptr == NULL);
948 dtrace_pid_probe_ptr = &fasttrap_pid_probe;
949 dtrace_return_probe_ptr = &fasttrap_return_probe;
951 ASSERT(dtrace_pid_probe_ptr == &fasttrap_pid_probe);
952 ASSERT(dtrace_return_probe_ptr == &fasttrap_return_probe);
953 fasttrap_pid_count++;
954 mutex_exit(&fasttrap_count_mtx);
958 fasttrap_disable_callbacks(void)
961 ASSERT(MUTEX_HELD(&cpu_lock));
965 mutex_enter(&fasttrap_count_mtx);
966 ASSERT(fasttrap_pid_count > 0);
967 fasttrap_pid_count--;
968 if (fasttrap_pid_count == 0) {
970 cpu_t *cur, *cpu = CPU;
972 for (cur = cpu->cpu_next_onln; cur != cpu;
973 cur = cur->cpu_next_onln) {
974 rw_enter(&cur->cpu_ft_lock, RW_WRITER);
977 dtrace_pid_probe_ptr = NULL;
978 dtrace_return_probe_ptr = NULL;
980 for (cur = cpu->cpu_next_onln; cur != cpu;
981 cur = cur->cpu_next_onln) {
982 rw_exit(&cur->cpu_ft_lock);
986 mutex_exit(&fasttrap_count_mtx);
991 fasttrap_pid_enable(void *arg, dtrace_id_t id, void *parg)
993 fasttrap_probe_t *probe = parg;
997 ASSERT(probe != NULL);
998 ASSERT(!probe->ftp_enabled);
999 ASSERT(id == probe->ftp_id);
1001 ASSERT(MUTEX_HELD(&cpu_lock));
1005 * Increment the count of enabled probes on this probe's provider;
1006 * the provider can't go away while the probe still exists. We
1007 * must increment this even if we aren't able to properly enable
1010 mutex_enter(&probe->ftp_prov->ftp_mtx);
1011 probe->ftp_prov->ftp_rcount++;
1012 mutex_exit(&probe->ftp_prov->ftp_mtx);
1015 * If this probe's provider is retired (meaning it was valid in a
1016 * previously exec'ed incarnation of this address space), bail out. The
1017 * provider can't go away while we're in this code path.
1019 if (probe->ftp_prov->ftp_retired)
1023 * If we can't find the process, it may be that we're in the context of
1024 * a fork in which the traced process is being born and we're copying
1025 * USDT probes. Otherwise, the process is gone so bail.
1028 if ((p = sprlock(probe->ftp_pid)) == NULL) {
1029 if ((curproc->p_flag & SFORKING) == 0)
1032 mutex_enter(&pidlock);
1033 p = prfind(probe->ftp_pid);
1036 * Confirm that curproc is indeed forking the process in which
1037 * we're trying to enable probes.
1040 ASSERT(p->p_parent == curproc);
1041 ASSERT(p->p_stat == SIDL);
1043 mutex_enter(&p->p_lock);
1044 mutex_exit(&pidlock);
1049 ASSERT(!(p->p_flag & SVFORK));
1050 mutex_exit(&p->p_lock);
1052 if ((p = pfind(probe->ftp_pid)) == NULL)
1057 * We have to enable the trap entry point before any user threads have
1058 * the chance to execute the trap instruction we're about to place
1059 * in their process's text.
1063 * pfind() returns a locked process.
1068 fasttrap_enable_callbacks();
1071 * Enable all the tracepoints and add this probe's id to each
1072 * tracepoint's list of active probes.
1074 for (i = 0; i < probe->ftp_ntps; i++) {
1075 if ((rc = fasttrap_tracepoint_enable(p, probe, i)) != 0) {
1077 * If enabling the tracepoint failed completely,
1078 * we don't have to disable it; if the failure
1079 * was only partial we must disable it.
1081 if (rc == FASTTRAP_ENABLE_FAIL)
1084 ASSERT(rc == FASTTRAP_ENABLE_PARTIAL);
1087 * Back up and pull out all the tracepoints we've
1088 * created so far for this probe.
1091 fasttrap_tracepoint_disable(p, probe, i);
1096 mutex_enter(&p->p_lock);
1103 * Since we're not actually enabling this probe,
1104 * drop our reference on the trap table entry.
1106 fasttrap_disable_callbacks();
1111 mutex_enter(&p->p_lock);
1117 probe->ftp_enabled = 1;
1122 fasttrap_pid_disable(void *arg, dtrace_id_t id, void *parg)
1124 fasttrap_probe_t *probe = parg;
1125 fasttrap_provider_t *provider = probe->ftp_prov;
1129 ASSERT(id == probe->ftp_id);
1131 mutex_enter(&provider->ftp_mtx);
1134 * We won't be able to acquire a /proc-esque lock on the process
1135 * iff the process is dead and gone. In this case, we rely on the
1136 * provider lock as a point of mutual exclusion to prevent other
1137 * DTrace consumers from disabling this probe.
1139 if ((p = pfind(probe->ftp_pid)) != NULL) {
1147 * Disable all the associated tracepoints (for fully enabled probes).
1149 if (probe->ftp_enabled) {
1150 for (i = 0; i < probe->ftp_ntps; i++) {
1151 fasttrap_tracepoint_disable(p, probe, i);
1155 ASSERT(provider->ftp_rcount > 0);
1156 provider->ftp_rcount--;
1160 * Even though we may not be able to remove it entirely, we
1161 * mark this retired provider to get a chance to remove some
1162 * of the associated probes.
1164 if (provider->ftp_retired && !provider->ftp_marked)
1165 whack = provider->ftp_marked = 1;
1166 mutex_exit(&provider->ftp_mtx);
1169 * If the process is dead, we're just waiting for the
1170 * last probe to be disabled to be able to free it.
1172 if (provider->ftp_rcount == 0 && !provider->ftp_marked)
1173 whack = provider->ftp_marked = 1;
1174 mutex_exit(&provider->ftp_mtx);
1178 fasttrap_pid_cleanup();
1184 if (!probe->ftp_enabled)
1187 probe->ftp_enabled = 0;
1190 ASSERT(MUTEX_HELD(&cpu_lock));
1192 fasttrap_disable_callbacks();
1197 fasttrap_pid_getargdesc(void *arg, dtrace_id_t id, void *parg,
1198 dtrace_argdesc_t *desc)
1200 fasttrap_probe_t *probe = parg;
1204 desc->dtargd_native[0] = '\0';
1205 desc->dtargd_xlate[0] = '\0';
1207 if (probe->ftp_prov->ftp_retired != 0 ||
1208 desc->dtargd_ndx >= probe->ftp_nargs) {
1209 desc->dtargd_ndx = DTRACE_ARGNONE;
1213 ndx = (probe->ftp_argmap != NULL) ?
1214 probe->ftp_argmap[desc->dtargd_ndx] : desc->dtargd_ndx;
1216 str = probe->ftp_ntypes;
1217 for (i = 0; i < ndx; i++) {
1218 str += strlen(str) + 1;
1221 ASSERT(strlen(str + 1) < sizeof (desc->dtargd_native));
1222 (void) strcpy(desc->dtargd_native, str);
1224 if (probe->ftp_xtypes == NULL)
1227 str = probe->ftp_xtypes;
1228 for (i = 0; i < desc->dtargd_ndx; i++) {
1229 str += strlen(str) + 1;
1232 ASSERT(strlen(str + 1) < sizeof (desc->dtargd_xlate));
1233 (void) strcpy(desc->dtargd_xlate, str);
1238 fasttrap_pid_destroy(void *arg, dtrace_id_t id, void *parg)
1240 fasttrap_probe_t *probe = parg;
1244 ASSERT(probe != NULL);
1245 ASSERT(!probe->ftp_enabled);
1246 ASSERT(fasttrap_total >= probe->ftp_ntps);
1248 atomic_add_32(&fasttrap_total, -probe->ftp_ntps);
1249 size = offsetof(fasttrap_probe_t, ftp_tps[probe->ftp_ntps]);
1251 if (probe->ftp_gen + 1 >= fasttrap_mod_gen)
1252 fasttrap_mod_barrier(probe->ftp_gen);
1254 for (i = 0; i < probe->ftp_ntps; i++) {
1255 kmem_free(probe->ftp_tps[i].fit_tp,
1256 sizeof (fasttrap_tracepoint_t));
1259 kmem_free(probe, size);
1263 static const dtrace_pattr_t pid_attr = {
1264 { DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_ISA },
1265 { DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_UNKNOWN },
1266 { DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_UNKNOWN },
1267 { DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_ISA },
1268 { DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_UNKNOWN },
1271 static dtrace_pops_t pid_pops = {
1272 fasttrap_pid_provide,
1274 fasttrap_pid_enable,
1275 fasttrap_pid_disable,
1278 fasttrap_pid_getargdesc,
1279 fasttrap_pid_getarg,
1281 fasttrap_pid_destroy
1284 static dtrace_pops_t usdt_pops = {
1285 fasttrap_pid_provide,
1287 fasttrap_pid_enable,
1288 fasttrap_pid_disable,
1291 fasttrap_pid_getargdesc,
1292 fasttrap_usdt_getarg,
1294 fasttrap_pid_destroy
1297 static fasttrap_proc_t *
1298 fasttrap_proc_lookup(pid_t pid)
1300 fasttrap_bucket_t *bucket;
1301 fasttrap_proc_t *fprc, *new_fprc;
1304 bucket = &fasttrap_procs.fth_table[FASTTRAP_PROCS_INDEX(pid)];
1305 mutex_enter(&bucket->ftb_mtx);
1307 for (fprc = bucket->ftb_data; fprc != NULL; fprc = fprc->ftpc_next) {
1308 if (fprc->ftpc_pid == pid && fprc->ftpc_acount != 0) {
1309 mutex_enter(&fprc->ftpc_mtx);
1310 mutex_exit(&bucket->ftb_mtx);
1311 fprc->ftpc_rcount++;
1312 atomic_add_64(&fprc->ftpc_acount, 1);
1313 ASSERT(fprc->ftpc_acount <= fprc->ftpc_rcount);
1314 mutex_exit(&fprc->ftpc_mtx);
1321 * Drop the bucket lock so we don't try to perform a sleeping
1322 * allocation under it.
1324 mutex_exit(&bucket->ftb_mtx);
1326 new_fprc = kmem_zalloc(sizeof (fasttrap_proc_t), KM_SLEEP);
1327 new_fprc->ftpc_pid = pid;
1328 new_fprc->ftpc_rcount = 1;
1329 new_fprc->ftpc_acount = 1;
1331 mutex_init(&new_fprc->ftpc_mtx, "fasttrap proc mtx", MUTEX_DEFAULT,
1335 mutex_enter(&bucket->ftb_mtx);
1338 * Take another lap through the list to make sure a proc hasn't
1339 * been created for this pid while we weren't under the bucket lock.
1341 for (fprc = bucket->ftb_data; fprc != NULL; fprc = fprc->ftpc_next) {
1342 if (fprc->ftpc_pid == pid && fprc->ftpc_acount != 0) {
1343 mutex_enter(&fprc->ftpc_mtx);
1344 mutex_exit(&bucket->ftb_mtx);
1345 fprc->ftpc_rcount++;
1346 atomic_add_64(&fprc->ftpc_acount, 1);
1347 ASSERT(fprc->ftpc_acount <= fprc->ftpc_rcount);
1348 mutex_exit(&fprc->ftpc_mtx);
1350 kmem_free(new_fprc, sizeof (fasttrap_proc_t));
1356 new_fprc->ftpc_next = bucket->ftb_data;
1357 bucket->ftb_data = new_fprc;
1359 mutex_exit(&bucket->ftb_mtx);
1365 fasttrap_proc_release(fasttrap_proc_t *proc)
1367 fasttrap_bucket_t *bucket;
1368 fasttrap_proc_t *fprc, **fprcp;
1369 pid_t pid = proc->ftpc_pid;
1371 mutex_enter(&proc->ftpc_mtx);
1373 ASSERT(proc->ftpc_rcount != 0);
1374 ASSERT(proc->ftpc_acount <= proc->ftpc_rcount);
1376 if (--proc->ftpc_rcount != 0) {
1377 mutex_exit(&proc->ftpc_mtx);
1381 mutex_exit(&proc->ftpc_mtx);
1384 * There should definitely be no live providers associated with this
1385 * process at this point.
1387 ASSERT(proc->ftpc_acount == 0);
1389 bucket = &fasttrap_procs.fth_table[FASTTRAP_PROCS_INDEX(pid)];
1390 mutex_enter(&bucket->ftb_mtx);
1392 fprcp = (fasttrap_proc_t **)&bucket->ftb_data;
1393 while ((fprc = *fprcp) != NULL) {
1397 fprcp = &fprc->ftpc_next;
1401 * Something strange has happened if we can't find the proc.
1403 ASSERT(fprc != NULL);
1405 *fprcp = fprc->ftpc_next;
1407 mutex_exit(&bucket->ftb_mtx);
1409 kmem_free(fprc, sizeof (fasttrap_proc_t));
1413 * Lookup a fasttrap-managed provider based on its name and associated pid.
1414 * If the pattr argument is non-NULL, this function instantiates the provider
1415 * if it doesn't exist otherwise it returns NULL. The provider is returned
1416 * with its lock held.
1418 static fasttrap_provider_t *
1419 fasttrap_provider_lookup(pid_t pid, const char *name,
1420 const dtrace_pattr_t *pattr)
1422 fasttrap_provider_t *fp, *new_fp = NULL;
1423 fasttrap_bucket_t *bucket;
1424 char provname[DTRACE_PROVNAMELEN];
1428 ASSERT(strlen(name) < sizeof (fp->ftp_name));
1429 ASSERT(pattr != NULL);
1431 bucket = &fasttrap_provs.fth_table[FASTTRAP_PROVS_INDEX(pid, name)];
1432 mutex_enter(&bucket->ftb_mtx);
1435 * Take a lap through the list and return the match if we find it.
1437 for (fp = bucket->ftb_data; fp != NULL; fp = fp->ftp_next) {
1438 if (fp->ftp_pid == pid && strcmp(fp->ftp_name, name) == 0 &&
1440 mutex_enter(&fp->ftp_mtx);
1441 mutex_exit(&bucket->ftb_mtx);
1447 * Drop the bucket lock so we don't try to perform a sleeping
1448 * allocation under it.
1450 mutex_exit(&bucket->ftb_mtx);
1453 * Make sure the process exists, isn't a child created as the result
1454 * of a vfork(2), and isn't a zombie (but may be in fork).
1456 if ((p = pfind(pid)) == NULL)
1460 * Increment p_dtrace_probes so that the process knows to inform us
1461 * when it exits or execs. fasttrap_provider_free() decrements this
1462 * when we're done with this provider.
1464 p->p_dtrace_probes++;
1467 * Grab the credentials for this process so we have
1468 * something to pass to dtrace_register().
1470 PROC_LOCK_ASSERT(p, MA_OWNED);
1475 new_fp = kmem_zalloc(sizeof (fasttrap_provider_t), KM_SLEEP);
1476 new_fp->ftp_pid = pid;
1477 new_fp->ftp_proc = fasttrap_proc_lookup(pid);
1479 mutex_init(&new_fp->ftp_mtx, "provider mtx", MUTEX_DEFAULT, NULL);
1480 mutex_init(&new_fp->ftp_cmtx, "lock on creating", MUTEX_DEFAULT, NULL);
1483 ASSERT(new_fp->ftp_proc != NULL);
1485 mutex_enter(&bucket->ftb_mtx);
1488 * Take another lap through the list to make sure a provider hasn't
1489 * been created for this pid while we weren't under the bucket lock.
1491 for (fp = bucket->ftb_data; fp != NULL; fp = fp->ftp_next) {
1492 if (fp->ftp_pid == pid && strcmp(fp->ftp_name, name) == 0 &&
1494 mutex_enter(&fp->ftp_mtx);
1495 mutex_exit(&bucket->ftb_mtx);
1496 fasttrap_provider_free(new_fp);
1502 (void) strcpy(new_fp->ftp_name, name);
1505 * Fail and return NULL if either the provider name is too long
1506 * or we fail to register this new provider with the DTrace
1507 * framework. Note that this is the only place we ever construct
1508 * the full provider name -- we keep it in pieces in the provider
1511 if (snprintf(provname, sizeof (provname), "%s%u", name, (uint_t)pid) >=
1512 sizeof (provname) ||
1513 dtrace_register(provname, pattr,
1514 DTRACE_PRIV_PROC | DTRACE_PRIV_OWNER | DTRACE_PRIV_ZONEOWNER, cred,
1515 pattr == &pid_attr ? &pid_pops : &usdt_pops, new_fp,
1516 &new_fp->ftp_provid) != 0) {
1517 mutex_exit(&bucket->ftb_mtx);
1518 fasttrap_provider_free(new_fp);
1523 new_fp->ftp_next = bucket->ftb_data;
1524 bucket->ftb_data = new_fp;
1526 mutex_enter(&new_fp->ftp_mtx);
1527 mutex_exit(&bucket->ftb_mtx);
1534 fasttrap_provider_free(fasttrap_provider_t *provider)
1536 pid_t pid = provider->ftp_pid;
1540 * There need to be no associated enabled probes, no consumers
1541 * creating probes, and no meta providers referencing this provider.
1543 ASSERT(provider->ftp_rcount == 0);
1544 ASSERT(provider->ftp_ccount == 0);
1545 ASSERT(provider->ftp_mcount == 0);
1548 * If this provider hasn't been retired, we need to explicitly drop the
1549 * count of active providers on the associated process structure.
1551 if (!provider->ftp_retired) {
1552 atomic_add_64(&provider->ftp_proc->ftpc_acount, -1);
1553 ASSERT(provider->ftp_proc->ftpc_acount <
1554 provider->ftp_proc->ftpc_rcount);
1557 fasttrap_proc_release(provider->ftp_proc);
1560 mutex_destroy(&provider->ftp_mtx);
1561 mutex_destroy(&provider->ftp_cmtx);
1563 kmem_free(provider, sizeof (fasttrap_provider_t));
1566 * Decrement p_dtrace_probes on the process whose provider we're
1567 * freeing. We don't have to worry about clobbering somone else's
1568 * modifications to it because we have locked the bucket that
1569 * corresponds to this process's hash chain in the provider hash
1570 * table. Don't sweat it if we can't find the process.
1572 if ((p = pfind(pid)) == NULL) {
1576 p->p_dtrace_probes--;
1583 fasttrap_provider_retire(pid_t pid, const char *name, int mprov)
1585 fasttrap_provider_t *fp;
1586 fasttrap_bucket_t *bucket;
1587 dtrace_provider_id_t provid;
1589 ASSERT(strlen(name) < sizeof (fp->ftp_name));
1591 bucket = &fasttrap_provs.fth_table[FASTTRAP_PROVS_INDEX(pid, name)];
1592 mutex_enter(&bucket->ftb_mtx);
1594 for (fp = bucket->ftb_data; fp != NULL; fp = fp->ftp_next) {
1595 if (fp->ftp_pid == pid && strcmp(fp->ftp_name, name) == 0 &&
1601 mutex_exit(&bucket->ftb_mtx);
1605 mutex_enter(&fp->ftp_mtx);
1606 ASSERT(!mprov || fp->ftp_mcount > 0);
1607 if (mprov && --fp->ftp_mcount != 0) {
1608 mutex_exit(&fp->ftp_mtx);
1609 mutex_exit(&bucket->ftb_mtx);
1614 * Mark the provider to be removed in our post-processing step, mark it
1615 * retired, and drop the active count on its proc. Marking it indicates
1616 * that we should try to remove it; setting the retired flag indicates
1617 * that we're done with this provider; dropping the active the proc
1618 * releases our hold, and when this reaches zero (as it will during
1619 * exit or exec) the proc and associated providers become defunct.
1621 * We obviously need to take the bucket lock before the provider lock
1622 * to perform the lookup, but we need to drop the provider lock
1623 * before calling into the DTrace framework since we acquire the
1624 * provider lock in callbacks invoked from the DTrace framework. The
1625 * bucket lock therefore protects the integrity of the provider hash
1628 atomic_add_64(&fp->ftp_proc->ftpc_acount, -1);
1629 ASSERT(fp->ftp_proc->ftpc_acount < fp->ftp_proc->ftpc_rcount);
1631 fp->ftp_retired = 1;
1633 provid = fp->ftp_provid;
1634 mutex_exit(&fp->ftp_mtx);
1637 * We don't have to worry about invalidating the same provider twice
1638 * since fasttrap_provider_lookup() will ignore provider that have
1639 * been marked as retired.
1641 dtrace_invalidate(provid);
1643 mutex_exit(&bucket->ftb_mtx);
1645 fasttrap_pid_cleanup();
1649 fasttrap_uint32_cmp(const void *ap, const void *bp)
1651 return (*(const uint32_t *)ap - *(const uint32_t *)bp);
1655 fasttrap_uint64_cmp(const void *ap, const void *bp)
1657 return (*(const uint64_t *)ap - *(const uint64_t *)bp);
1661 fasttrap_add_probe(fasttrap_probe_spec_t *pdata)
1663 fasttrap_provider_t *provider;
1664 fasttrap_probe_t *pp;
1665 fasttrap_tracepoint_t *tp;
1667 int i, aframes = 0, whack;
1670 * There needs to be at least one desired trace point.
1672 if (pdata->ftps_noffs == 0)
1675 switch (pdata->ftps_type) {
1678 aframes = FASTTRAP_ENTRY_AFRAMES;
1682 aframes = FASTTRAP_RETURN_AFRAMES;
1691 if ((provider = fasttrap_provider_lookup(pdata->ftps_pid,
1692 FASTTRAP_PID_NAME, &pid_attr)) == NULL)
1696 * Increment this reference count to indicate that a consumer is
1697 * actively adding a new probe associated with this provider. This
1698 * prevents the provider from being deleted -- we'll need to check
1699 * for pending deletions when we drop this reference count.
1701 provider->ftp_ccount++;
1702 mutex_exit(&provider->ftp_mtx);
1705 * Grab the creation lock to ensure consistency between calls to
1706 * dtrace_probe_lookup() and dtrace_probe_create() in the face of
1707 * other threads creating probes. We must drop the provider lock
1708 * before taking this lock to avoid a three-way deadlock with the
1711 mutex_enter(&provider->ftp_cmtx);
1714 for (i = 0; i < pdata->ftps_noffs; i++) {
1717 (void) sprintf(name_str, "%llx",
1718 (unsigned long long)pdata->ftps_offs[i]);
1720 if (dtrace_probe_lookup(provider->ftp_provid,
1721 pdata->ftps_mod, pdata->ftps_func, name_str) != 0)
1724 atomic_add_32(&fasttrap_total, 1);
1726 if (fasttrap_total > fasttrap_max) {
1727 atomic_add_32(&fasttrap_total, -1);
1731 pp = kmem_zalloc(sizeof (fasttrap_probe_t), KM_SLEEP);
1733 pp->ftp_prov = provider;
1734 pp->ftp_faddr = pdata->ftps_pc;
1735 pp->ftp_fsize = pdata->ftps_size;
1736 pp->ftp_pid = pdata->ftps_pid;
1739 tp = kmem_zalloc(sizeof (fasttrap_tracepoint_t),
1742 tp->ftt_proc = provider->ftp_proc;
1743 tp->ftt_pc = pdata->ftps_offs[i] + pdata->ftps_pc;
1744 tp->ftt_pid = pdata->ftps_pid;
1746 pp->ftp_tps[0].fit_tp = tp;
1747 pp->ftp_tps[0].fit_id.fti_probe = pp;
1748 pp->ftp_tps[0].fit_id.fti_ptype = pdata->ftps_type;
1750 pp->ftp_id = dtrace_probe_create(provider->ftp_provid,
1751 pdata->ftps_mod, pdata->ftps_func, name_str,
1752 FASTTRAP_OFFSET_AFRAMES, pp);
1755 } else if (dtrace_probe_lookup(provider->ftp_provid, pdata->ftps_mod,
1756 pdata->ftps_func, name) == 0) {
1757 atomic_add_32(&fasttrap_total, pdata->ftps_noffs);
1759 if (fasttrap_total > fasttrap_max) {
1760 atomic_add_32(&fasttrap_total, -pdata->ftps_noffs);
1765 * Make sure all tracepoint program counter values are unique.
1766 * We later assume that each probe has exactly one tracepoint
1769 qsort(pdata->ftps_offs, pdata->ftps_noffs,
1770 sizeof (uint64_t), fasttrap_uint64_cmp);
1771 for (i = 1; i < pdata->ftps_noffs; i++) {
1772 if (pdata->ftps_offs[i] > pdata->ftps_offs[i - 1])
1775 atomic_add_32(&fasttrap_total, -pdata->ftps_noffs);
1779 ASSERT(pdata->ftps_noffs > 0);
1780 pp = kmem_zalloc(offsetof(fasttrap_probe_t,
1781 ftp_tps[pdata->ftps_noffs]), KM_SLEEP);
1783 pp->ftp_prov = provider;
1784 pp->ftp_faddr = pdata->ftps_pc;
1785 pp->ftp_fsize = pdata->ftps_size;
1786 pp->ftp_pid = pdata->ftps_pid;
1787 pp->ftp_ntps = pdata->ftps_noffs;
1789 for (i = 0; i < pdata->ftps_noffs; i++) {
1790 tp = kmem_zalloc(sizeof (fasttrap_tracepoint_t),
1793 tp->ftt_proc = provider->ftp_proc;
1794 tp->ftt_pc = pdata->ftps_offs[i] + pdata->ftps_pc;
1795 tp->ftt_pid = pdata->ftps_pid;
1797 pp->ftp_tps[i].fit_tp = tp;
1798 pp->ftp_tps[i].fit_id.fti_probe = pp;
1799 pp->ftp_tps[i].fit_id.fti_ptype = pdata->ftps_type;
1802 pp->ftp_id = dtrace_probe_create(provider->ftp_provid,
1803 pdata->ftps_mod, pdata->ftps_func, name, aframes, pp);
1806 mutex_exit(&provider->ftp_cmtx);
1809 * We know that the provider is still valid since we incremented the
1810 * creation reference count. If someone tried to clean up this provider
1811 * while we were using it (e.g. because the process called exec(2) or
1812 * exit(2)), take note of that and try to clean it up now.
1814 mutex_enter(&provider->ftp_mtx);
1815 provider->ftp_ccount--;
1816 whack = provider->ftp_retired;
1817 mutex_exit(&provider->ftp_mtx);
1820 fasttrap_pid_cleanup();
1826 * If we've exhausted the allowable resources, we'll try to remove
1827 * this provider to free some up. This is to cover the case where
1828 * the user has accidentally created many more probes than was
1829 * intended (e.g. pid123:::).
1831 mutex_exit(&provider->ftp_cmtx);
1832 mutex_enter(&provider->ftp_mtx);
1833 provider->ftp_ccount--;
1834 provider->ftp_marked = 1;
1835 mutex_exit(&provider->ftp_mtx);
1837 fasttrap_pid_cleanup();
1844 fasttrap_meta_provide(void *arg, dtrace_helper_provdesc_t *dhpv, pid_t pid)
1846 fasttrap_provider_t *provider;
1849 * A 32-bit unsigned integer (like a pid for example) can be
1850 * expressed in 10 or fewer decimal digits. Make sure that we'll
1851 * have enough space for the provider name.
1853 if (strlen(dhpv->dthpv_provname) + 10 >=
1854 sizeof (provider->ftp_name)) {
1855 printf("failed to instantiate provider %s: "
1856 "name too long to accomodate pid", dhpv->dthpv_provname);
1861 * Don't let folks spoof the true pid provider.
1863 if (strcmp(dhpv->dthpv_provname, FASTTRAP_PID_NAME) == 0) {
1864 printf("failed to instantiate provider %s: "
1865 "%s is an invalid name", dhpv->dthpv_provname,
1871 * The highest stability class that fasttrap supports is ISA; cap
1872 * the stability of the new provider accordingly.
1874 if (dhpv->dthpv_pattr.dtpa_provider.dtat_class > DTRACE_CLASS_ISA)
1875 dhpv->dthpv_pattr.dtpa_provider.dtat_class = DTRACE_CLASS_ISA;
1876 if (dhpv->dthpv_pattr.dtpa_mod.dtat_class > DTRACE_CLASS_ISA)
1877 dhpv->dthpv_pattr.dtpa_mod.dtat_class = DTRACE_CLASS_ISA;
1878 if (dhpv->dthpv_pattr.dtpa_func.dtat_class > DTRACE_CLASS_ISA)
1879 dhpv->dthpv_pattr.dtpa_func.dtat_class = DTRACE_CLASS_ISA;
1880 if (dhpv->dthpv_pattr.dtpa_name.dtat_class > DTRACE_CLASS_ISA)
1881 dhpv->dthpv_pattr.dtpa_name.dtat_class = DTRACE_CLASS_ISA;
1882 if (dhpv->dthpv_pattr.dtpa_args.dtat_class > DTRACE_CLASS_ISA)
1883 dhpv->dthpv_pattr.dtpa_args.dtat_class = DTRACE_CLASS_ISA;
1885 if ((provider = fasttrap_provider_lookup(pid, dhpv->dthpv_provname,
1886 &dhpv->dthpv_pattr)) == NULL) {
1887 printf("failed to instantiate provider %s for "
1888 "process %u", dhpv->dthpv_provname, (uint_t)pid);
1893 * Up the meta provider count so this provider isn't removed until
1894 * the meta provider has been told to remove it.
1896 provider->ftp_mcount++;
1898 mutex_exit(&provider->ftp_mtx);
1905 fasttrap_meta_create_probe(void *arg, void *parg,
1906 dtrace_helper_probedesc_t *dhpb)
1908 fasttrap_provider_t *provider = parg;
1909 fasttrap_probe_t *pp;
1910 fasttrap_tracepoint_t *tp;
1915 * Since the meta provider count is non-zero we don't have to worry
1916 * about this provider disappearing.
1918 ASSERT(provider->ftp_mcount > 0);
1921 * The offsets must be unique.
1923 qsort(dhpb->dthpb_offs, dhpb->dthpb_noffs, sizeof (uint32_t),
1924 fasttrap_uint32_cmp);
1925 for (i = 1; i < dhpb->dthpb_noffs; i++) {
1926 if (dhpb->dthpb_base + dhpb->dthpb_offs[i] <=
1927 dhpb->dthpb_base + dhpb->dthpb_offs[i - 1])
1931 qsort(dhpb->dthpb_enoffs, dhpb->dthpb_nenoffs, sizeof (uint32_t),
1932 fasttrap_uint32_cmp);
1933 for (i = 1; i < dhpb->dthpb_nenoffs; i++) {
1934 if (dhpb->dthpb_base + dhpb->dthpb_enoffs[i] <=
1935 dhpb->dthpb_base + dhpb->dthpb_enoffs[i - 1])
1940 * Grab the creation lock to ensure consistency between calls to
1941 * dtrace_probe_lookup() and dtrace_probe_create() in the face of
1942 * other threads creating probes.
1944 mutex_enter(&provider->ftp_cmtx);
1946 if (dtrace_probe_lookup(provider->ftp_provid, dhpb->dthpb_mod,
1947 dhpb->dthpb_func, dhpb->dthpb_name) != 0) {
1948 mutex_exit(&provider->ftp_cmtx);
1952 ntps = dhpb->dthpb_noffs + dhpb->dthpb_nenoffs;
1955 atomic_add_32(&fasttrap_total, ntps);
1957 if (fasttrap_total > fasttrap_max) {
1958 atomic_add_32(&fasttrap_total, -ntps);
1959 mutex_exit(&provider->ftp_cmtx);
1963 pp = kmem_zalloc(offsetof(fasttrap_probe_t, ftp_tps[ntps]), KM_SLEEP);
1965 pp->ftp_prov = provider;
1966 pp->ftp_pid = provider->ftp_pid;
1967 pp->ftp_ntps = ntps;
1968 pp->ftp_nargs = dhpb->dthpb_xargc;
1969 pp->ftp_xtypes = dhpb->dthpb_xtypes;
1970 pp->ftp_ntypes = dhpb->dthpb_ntypes;
1973 * First create a tracepoint for each actual point of interest.
1975 for (i = 0; i < dhpb->dthpb_noffs; i++) {
1976 tp = kmem_zalloc(sizeof (fasttrap_tracepoint_t), KM_SLEEP);
1978 tp->ftt_proc = provider->ftp_proc;
1979 tp->ftt_pc = dhpb->dthpb_base + dhpb->dthpb_offs[i];
1980 tp->ftt_pid = provider->ftp_pid;
1982 pp->ftp_tps[i].fit_tp = tp;
1983 pp->ftp_tps[i].fit_id.fti_probe = pp;
1985 pp->ftp_tps[i].fit_id.fti_ptype = DTFTP_POST_OFFSETS;
1987 pp->ftp_tps[i].fit_id.fti_ptype = DTFTP_OFFSETS;
1992 * Then create a tracepoint for each is-enabled point.
1994 for (j = 0; i < ntps; i++, j++) {
1995 tp = kmem_zalloc(sizeof (fasttrap_tracepoint_t), KM_SLEEP);
1997 tp->ftt_proc = provider->ftp_proc;
1998 tp->ftt_pc = dhpb->dthpb_base + dhpb->dthpb_enoffs[j];
1999 tp->ftt_pid = provider->ftp_pid;
2001 pp->ftp_tps[i].fit_tp = tp;
2002 pp->ftp_tps[i].fit_id.fti_probe = pp;
2003 pp->ftp_tps[i].fit_id.fti_ptype = DTFTP_IS_ENABLED;
2007 * If the arguments are shuffled around we set the argument remapping
2008 * table. Later, when the probe fires, we only remap the arguments
2009 * if the table is non-NULL.
2011 for (i = 0; i < dhpb->dthpb_xargc; i++) {
2012 if (dhpb->dthpb_args[i] != i) {
2013 pp->ftp_argmap = dhpb->dthpb_args;
2019 * The probe is fully constructed -- register it with DTrace.
2021 pp->ftp_id = dtrace_probe_create(provider->ftp_provid, dhpb->dthpb_mod,
2022 dhpb->dthpb_func, dhpb->dthpb_name, FASTTRAP_OFFSET_AFRAMES, pp);
2024 mutex_exit(&provider->ftp_cmtx);
2029 fasttrap_meta_remove(void *arg, dtrace_helper_provdesc_t *dhpv, pid_t pid)
2032 * Clean up the USDT provider. There may be active consumers of the
2033 * provider busy adding probes, no damage will actually befall the
2034 * provider until that count has dropped to zero. This just puts
2035 * the provider on death row.
2037 fasttrap_provider_retire(pid, dhpv->dthpv_provname, 1);
2040 static dtrace_mops_t fasttrap_mops = {
2041 fasttrap_meta_create_probe,
2042 fasttrap_meta_provide,
2043 fasttrap_meta_remove
2048 fasttrap_open(struct cdev *dev __unused, int oflags __unused,
2049 int devtype __unused, struct thread *td __unused)
2056 fasttrap_ioctl(struct cdev *dev, u_long cmd, caddr_t arg, int fflag,
2060 struct kinfo_proc kp;
2061 const cred_t *cr = td->td_ucred;
2063 if (!dtrace_attached())
2066 if (cmd == FASTTRAPIOC_MAKEPROBE) {
2067 fasttrap_probe_spec_t *uprobe = (void *)arg;
2068 fasttrap_probe_spec_t *probe;
2075 if (copyin(&uprobe->ftps_noffs, &noffs,
2076 sizeof (uprobe->ftps_noffs)))
2079 noffs = uprobe->ftps_noffs;
2083 * Probes must have at least one tracepoint.
2088 size = sizeof (fasttrap_probe_spec_t) +
2089 sizeof (probe->ftps_offs[0]) * (noffs - 1);
2091 if (size > 1024 * 1024)
2094 probe = kmem_alloc(size, KM_SLEEP);
2097 if (copyin(uprobe, probe, size) != 0) {
2098 kmem_free(probe, size);
2102 memcpy(probe, uprobe, sizeof(*probe));
2103 if (noffs > 1 && copyin(uprobe + 1, probe + 1, size) != 0) {
2104 kmem_free(probe, size);
2111 * Verify that the function and module strings contain no
2114 for (c = &probe->ftps_func[0]; *c != '\0'; c++) {
2115 if (*c < 0x20 || 0x7f <= *c) {
2121 for (c = &probe->ftps_mod[0]; *c != '\0'; c++) {
2122 if (*c < 0x20 || 0x7f <= *c) {
2129 if (!PRIV_POLICY_CHOICE(cr, PRIV_ALL, B_FALSE)) {
2131 pid_t pid = probe->ftps_pid;
2134 mutex_enter(&pidlock);
2137 * Report an error if the process doesn't exist
2138 * or is actively being birthed.
2142 fill_kinfo_proc(p, &kp);
2143 if (p == NULL || kp.ki_stat == SIDL) {
2145 mutex_exit(&pidlock);
2150 mutex_enter(&p->p_lock);
2151 mutex_exit(&pidlock);
2153 PROC_LOCK_ASSERT(p, MA_OWNED);
2157 if ((ret = priv_proc_cred_perm(cr, p, NULL,
2158 VREAD | VWRITE)) != 0) {
2160 mutex_exit(&p->p_lock);
2168 mutex_exit(&p->p_lock);
2175 ret = fasttrap_add_probe(probe);
2177 kmem_free(probe, size);
2181 } else if (cmd == FASTTRAPIOC_GETINSTR) {
2182 fasttrap_instr_query_t instr;
2183 fasttrap_tracepoint_t *tp;
2190 if (copyin((void *)arg, &instr, sizeof (instr)) != 0)
2195 if (!PRIV_POLICY_CHOICE(cr, PRIV_ALL, B_FALSE)) {
2197 pid_t pid = instr.ftiq_pid;
2200 mutex_enter(&pidlock);
2203 * Report an error if the process doesn't exist
2204 * or is actively being birthed.
2208 fill_kinfo_proc(p, &kp);
2209 if (p == NULL || kp.ki_stat == SIDL) {
2211 mutex_exit(&pidlock);
2216 mutex_enter(&p->p_lock);
2217 mutex_exit(&pidlock);
2219 PROC_LOCK_ASSERT(p, MA_OWNED);
2223 if ((ret = priv_proc_cred_perm(cr, p, NULL,
2226 mutex_exit(&p->p_lock);
2235 mutex_exit(&p->p_lock);
2242 index = FASTTRAP_TPOINTS_INDEX(instr.ftiq_pid, instr.ftiq_pc);
2244 mutex_enter(&fasttrap_tpoints.fth_table[index].ftb_mtx);
2245 tp = fasttrap_tpoints.fth_table[index].ftb_data;
2246 while (tp != NULL) {
2247 if (instr.ftiq_pid == tp->ftt_pid &&
2248 instr.ftiq_pc == tp->ftt_pc &&
2249 tp->ftt_proc->ftpc_acount != 0)
2256 mutex_exit(&fasttrap_tpoints.fth_table[index].ftb_mtx);
2260 bcopy(&tp->ftt_instr, &instr.ftiq_instr,
2261 sizeof (instr.ftiq_instr));
2262 mutex_exit(&fasttrap_tpoints.fth_table[index].ftb_mtx);
2264 if (copyout(&instr, (void *)arg, sizeof (instr)) != 0)
2279 /* Create the /dev/dtrace/fasttrap entry. */
2280 fasttrap_cdev = make_dev(&fasttrap_cdevsw, 0, UID_ROOT, GID_WHEEL, 0600,
2283 mtx_init(&fasttrap_cleanup_mtx, "fasttrap clean", "dtrace", MTX_DEF);
2284 mutex_init(&fasttrap_count_mtx, "fasttrap count mtx", MUTEX_DEFAULT,
2287 ret = kproc_create(fasttrap_pid_cleanup_cb, NULL,
2288 &fasttrap_cleanup_proc, 0, 0, "ftcleanup");
2290 destroy_dev(fasttrap_cdev);
2295 fasttrap_max = ddi_getprop(DDI_DEV_T_ANY, devi, DDI_PROP_DONTPASS,
2296 "fasttrap-max-probes", FASTTRAP_MAX_DEFAULT);
2298 fasttrap_max = FASTTRAP_MAX_DEFAULT;
2303 * Conjure up the tracepoints hashtable...
2306 nent = ddi_getprop(DDI_DEV_T_ANY, devi, DDI_PROP_DONTPASS,
2307 "fasttrap-hash-size", FASTTRAP_TPOINTS_DEFAULT_SIZE);
2309 nent = FASTTRAP_TPOINTS_DEFAULT_SIZE;
2312 if (nent == 0 || nent > 0x1000000)
2313 nent = FASTTRAP_TPOINTS_DEFAULT_SIZE;
2315 if ((nent & (nent - 1)) == 0)
2316 fasttrap_tpoints.fth_nent = nent;
2318 fasttrap_tpoints.fth_nent = 1 << fasttrap_highbit(nent);
2319 ASSERT(fasttrap_tpoints.fth_nent > 0);
2320 fasttrap_tpoints.fth_mask = fasttrap_tpoints.fth_nent - 1;
2321 fasttrap_tpoints.fth_table = kmem_zalloc(fasttrap_tpoints.fth_nent *
2322 sizeof (fasttrap_bucket_t), KM_SLEEP);
2324 for (i = 0; i < fasttrap_tpoints.fth_nent; i++)
2325 mutex_init(&fasttrap_tpoints.fth_table[i].ftb_mtx,
2326 "tracepoints bucket mtx", MUTEX_DEFAULT, NULL);
2330 * ... and the providers hash table...
2332 nent = FASTTRAP_PROVIDERS_DEFAULT_SIZE;
2333 if ((nent & (nent - 1)) == 0)
2334 fasttrap_provs.fth_nent = nent;
2336 fasttrap_provs.fth_nent = 1 << fasttrap_highbit(nent);
2337 ASSERT(fasttrap_provs.fth_nent > 0);
2338 fasttrap_provs.fth_mask = fasttrap_provs.fth_nent - 1;
2339 fasttrap_provs.fth_table = kmem_zalloc(fasttrap_provs.fth_nent *
2340 sizeof (fasttrap_bucket_t), KM_SLEEP);
2342 for (i = 0; i < fasttrap_provs.fth_nent; i++)
2343 mutex_init(&fasttrap_provs.fth_table[i].ftb_mtx,
2344 "providers bucket mtx", MUTEX_DEFAULT, NULL);
2348 * ... and the procs hash table.
2350 nent = FASTTRAP_PROCS_DEFAULT_SIZE;
2351 if ((nent & (nent - 1)) == 0)
2352 fasttrap_procs.fth_nent = nent;
2354 fasttrap_procs.fth_nent = 1 << fasttrap_highbit(nent);
2355 ASSERT(fasttrap_procs.fth_nent > 0);
2356 fasttrap_procs.fth_mask = fasttrap_procs.fth_nent - 1;
2357 fasttrap_procs.fth_table = kmem_zalloc(fasttrap_procs.fth_nent *
2358 sizeof (fasttrap_bucket_t), KM_SLEEP);
2360 for (i = 0; i < fasttrap_procs.fth_nent; i++)
2361 mutex_init(&fasttrap_procs.fth_table[i].ftb_mtx,
2362 "processes bucket mtx", MUTEX_DEFAULT, NULL);
2365 mutex_init(&fasttrap_cpuc_pid_lock[i], "fasttrap barrier",
2366 MUTEX_DEFAULT, NULL);
2371 * Install our hooks into fork(2), exec(2), and exit(2).
2373 dtrace_fasttrap_fork = &fasttrap_fork;
2374 dtrace_fasttrap_exit = &fasttrap_exec_exit;
2375 dtrace_fasttrap_exec = &fasttrap_exec_exit;
2377 (void) dtrace_meta_register("fasttrap", &fasttrap_mops, NULL,
2384 fasttrap_unload(void)
2389 * Unregister the meta-provider to make sure no new fasttrap-
2390 * managed providers come along while we're trying to close up
2391 * shop. If we fail to detach, we'll need to re-register as a
2392 * meta-provider. We can fail to unregister as a meta-provider
2393 * if providers we manage still exist.
2395 if (fasttrap_meta_id != DTRACE_METAPROVNONE &&
2396 dtrace_meta_unregister(fasttrap_meta_id) != 0)
2400 * Iterate over all of our providers. If there's still a process
2401 * that corresponds to that pid, fail to detach.
2403 for (i = 0; i < fasttrap_provs.fth_nent; i++) {
2404 fasttrap_provider_t **fpp, *fp;
2405 fasttrap_bucket_t *bucket = &fasttrap_provs.fth_table[i];
2407 mutex_enter(&bucket->ftb_mtx);
2408 fpp = (fasttrap_provider_t **)&bucket->ftb_data;
2409 while ((fp = *fpp) != NULL) {
2411 * Acquire and release the lock as a simple way of
2412 * waiting for any other consumer to finish with
2413 * this provider. A thread must first acquire the
2414 * bucket lock so there's no chance of another thread
2415 * blocking on the provider's lock.
2417 mutex_enter(&fp->ftp_mtx);
2418 mutex_exit(&fp->ftp_mtx);
2420 if (dtrace_unregister(fp->ftp_provid) != 0) {
2422 fpp = &fp->ftp_next;
2424 *fpp = fp->ftp_next;
2425 fasttrap_provider_free(fp);
2429 mutex_exit(&bucket->ftb_mtx);
2433 (void) dtrace_meta_register("fasttrap", &fasttrap_mops, NULL,
2439 mtx_lock(&fasttrap_cleanup_mtx);
2440 fasttrap_cleanup_drain = 1;
2441 /* Wait for the cleanup thread to finish up and signal us. */
2442 wakeup(&fasttrap_cleanup_cv);
2443 mtx_sleep(&fasttrap_cleanup_drain, &fasttrap_cleanup_mtx, 0, "ftcld",
2445 fasttrap_cleanup_proc = NULL;
2446 mtx_destroy(&fasttrap_cleanup_mtx);
2449 mutex_enter(&fasttrap_count_mtx);
2450 ASSERT(fasttrap_pid_count == 0);
2451 mutex_exit(&fasttrap_count_mtx);
2454 kmem_free(fasttrap_tpoints.fth_table,
2455 fasttrap_tpoints.fth_nent * sizeof (fasttrap_bucket_t));
2456 fasttrap_tpoints.fth_nent = 0;
2458 kmem_free(fasttrap_provs.fth_table,
2459 fasttrap_provs.fth_nent * sizeof (fasttrap_bucket_t));
2460 fasttrap_provs.fth_nent = 0;
2462 kmem_free(fasttrap_procs.fth_table,
2463 fasttrap_procs.fth_nent * sizeof (fasttrap_bucket_t));
2464 fasttrap_procs.fth_nent = 0;
2467 * We know there are no tracepoints in any process anywhere in
2468 * the system so there is no process which has its p_dtrace_count
2469 * greater than zero, therefore we know that no thread can actively
2470 * be executing code in fasttrap_fork(). Similarly for p_dtrace_probes
2471 * and fasttrap_exec() and fasttrap_exit().
2473 ASSERT(dtrace_fasttrap_fork == &fasttrap_fork);
2474 dtrace_fasttrap_fork = NULL;
2476 ASSERT(dtrace_fasttrap_exec == &fasttrap_exec_exit);
2477 dtrace_fasttrap_exec = NULL;
2479 ASSERT(dtrace_fasttrap_exit == &fasttrap_exec_exit);
2480 dtrace_fasttrap_exit = NULL;
2483 destroy_dev(fasttrap_cdev);
2484 mutex_destroy(&fasttrap_count_mtx);
2486 mutex_destroy(&fasttrap_cpuc_pid_lock[i]);
2495 fasttrap_modevent(module_t mod __unused, int type, void *data __unused)
2516 SYSINIT(fasttrap_load, SI_SUB_DTRACE_PROVIDER, SI_ORDER_ANY, fasttrap_load,
2518 SYSUNINIT(fasttrap_unload, SI_SUB_DTRACE_PROVIDER, SI_ORDER_ANY,
2519 fasttrap_unload, NULL);
2521 DEV_MODULE(fasttrap, fasttrap_modevent, NULL);
2522 MODULE_VERSION(fasttrap, 1);
2523 MODULE_DEPEND(fasttrap, dtrace, 1, 1, 1);
2524 MODULE_DEPEND(fasttrap, opensolaris, 1, 1, 1);