On Tue, Aug 24, 2010 at 11:11:58AM +0000, Rui Paulo wrote: > Author: rpaulo > Date: Tue Aug 24 11:11:58 2010 > New Revision: 211738 > URL: http://svn.freebsd.org/changeset/base/211738 > > Log: > Port the fasttrap provider to FreeBSD. This provider is responsible for > injecting debugging probes in the userland programs and is the basis for > the pid provider and the usdt provider. > > Sponsored by: The FreeBSD Foundation > > Modified: > head/sys/cddl/contrib/opensolaris/uts/common/dtrace/fasttrap.c > > Modified: head/sys/cddl/contrib/opensolaris/uts/common/dtrace/fasttrap.c > ============================================================================== > --- head/sys/cddl/contrib/opensolaris/uts/common/dtrace/fasttrap.c Tue Aug > 24 09:57:06 2010 (r211737) > +++ head/sys/cddl/contrib/opensolaris/uts/common/dtrace/fasttrap.c Tue Aug > 24 11:11:58 2010 (r211738) > @@ -17,6 +17,10 @@ > * information: Portions Copyright [yyyy] [name of copyright owner] > * > * CDDL HEADER END > + * > + * Portions Copyright 2010 The FreeBSD Foundation > + * > + * $FreeBSD$ > */ > > /* > @@ -24,7 +28,9 @@ > * Use is subject to license terms. > */ > > +#if defined(sun) > #pragma ident "%Z%%M% %I% %E% SMI" > +#endif > > #include <sys/atomic.h> > #include <sys/errno.h> > @@ -32,11 +38,15 @@ > #include <sys/modctl.h> > #include <sys/conf.h> > #include <sys/systm.h> > +#if defined(sun) > #include <sys/ddi.h> > +#endif > #include <sys/sunddi.h> > #include <sys/cpuvar.h> > #include <sys/kmem.h> > +#if defined(sun) > #include <sys/strsubr.h> > +#endif > #include <sys/fasttrap.h> > #include <sys/fasttrap_impl.h> > #include <sys/fasttrap_isa.h> > @@ -44,9 +54,17 @@ > #include <sys/dtrace_impl.h> > #include <sys/sysmacros.h> > #include <sys/proc.h> > -#include <sys/priv.h> > #include <sys/policy.h> > +#if defined(sun) > #include <util/qsort.h> > +#endif > +#include <sys/mutex.h> > +#include <sys/kernel.h> > +#if !defined(sun) > +#include <sys/user.h> > +#include <sys/dtrace_bsd.h> > +#include <cddl/dev/dtrace/dtrace_cddl.h> > +#endif > > /* > * User-Land Trap-Based Tracing > @@ -125,11 +143,20 @@ > * never hold the provider lock and creation lock simultaneously > */ > > -static dev_info_t *fasttrap_devi; > +static d_open_t fasttrap_open; > +static d_ioctl_t fasttrap_ioctl; > + > +static struct cdevsw fasttrap_cdevsw = { > + .d_version = D_VERSION, > + .d_open = fasttrap_open, > + .d_ioctl = fasttrap_ioctl, > + .d_name = "fasttrap", > +}; > +static struct cdev *fasttrap_cdev; > static dtrace_meta_provider_id_t fasttrap_meta_id; > > -static timeout_id_t fasttrap_timeout; > -static kmutex_t fasttrap_cleanup_mtx; > +static struct callout fasttrap_timeout; > +static struct mtx fasttrap_cleanup_mtx; > static uint_t fasttrap_cleanup_work; > > /* > @@ -229,6 +256,7 @@ fasttrap_hash_str(const char *p) > void > fasttrap_sigtrap(proc_t *p, kthread_t *t, uintptr_t pc) > { > +#if defined(sun) > sigqueue_t *sqp = kmem_zalloc(sizeof (sigqueue_t), KM_SLEEP); > > sqp->sq_info.si_signo = SIGTRAP; > @@ -241,6 +269,17 @@ fasttrap_sigtrap(proc_t *p, kthread_t *t > > if (t != NULL) > aston(t); > +#else > + ksiginfo_t *ksi = kmem_zalloc(sizeof (ksiginfo_t), KM_SLEEP); > + > + ksiginfo_init(ksi); > + ksi->ksi_signo = SIGTRAP; > + ksi->ksi_code = TRAP_DTRACE; > + ksi->ksi_addr = (caddr_t)pc; > + PROC_LOCK(p); > + (void) pksignal(p, SIGTRAP, ksi); > + PROC_UNLOCK(p); > +#endif From the quick look at the solaris part of the code, I think that the signal should be posted to the specific thread, and not to the process.
> } > > /* > @@ -250,17 +289,24 @@ fasttrap_sigtrap(proc_t *p, kthread_t *t > static void > fasttrap_mod_barrier(uint64_t gen) > { > +#if defined(sun) > int i; > +#endif > > if (gen < fasttrap_mod_gen) > return; > > fasttrap_mod_gen++; > > +#if defined(sun) > for (i = 0; i < NCPU; i++) { > mutex_enter(&cpu_core[i].cpuc_pid_lock); > mutex_exit(&cpu_core[i].cpuc_pid_lock); > } > +#else > + /* XXX */ > + __asm __volatile("": : :"memory"); Indeed XXX. Semantic of acquiring/releasing a mutex, even on Solaris, is much stricter then performing compiler-level memory barrier.
pgpwpEZiVd5P8.pgp
Description: PGP signature