Merge latest DTrace changes from Perforce.

This commit is contained in:
Craig Rodrigues 2008-11-05 19:39:11 +00:00
parent 820e067933
commit f5a97d1bcb
10 changed files with 143 additions and 46 deletions

View File

@ -40,6 +40,8 @@ __FBSDID("$FreeBSD$");
#include <vm/vm_kern.h>
#include <vm/vm_map.h>
#define KMEM_DEBUG
#ifdef KMEM_DEBUG
#include <sys/queue.h>
#include <sys/stack.h>
@ -93,6 +95,10 @@ void
zfs_kmem_free(void *buf, size_t size __unused)
{
#ifdef KMEM_DEBUG
if (buf == NULL) {
printf("%s: attempt to free NULL\n",__func__);
return;
}
struct kmem_item *i;
buf = (u_char *)buf - sizeof(struct kmem_item);
@ -236,7 +242,8 @@ calloc(size_t n, size_t s)
}
#ifdef KMEM_DEBUG
static void
void kmem_show(void *);
void
kmem_show(void *dummy __unused)
{
struct kmem_item *i;
@ -248,12 +255,10 @@ kmem_show(void *dummy __unused)
printf("KMEM_DEBUG: Leaked elements:\n\n");
LIST_FOREACH(i, &kmem_items, next) {
printf("address=%p\n", i);
stack_print(&i->stack);
printf("\n");
}
}
mtx_unlock(&kmem_items_mtx);
}
SYSUNINIT(sol_kmem, SI_SUB_DRIVERS, SI_ORDER_FIRST, kmem_show, NULL);
SYSUNINIT(sol_kmem, SI_SUB_CPU, SI_ORDER_FIRST, kmem_show, NULL);
#endif /* KMEM_DEBUG */

View File

@ -64,12 +64,13 @@ typedef void pathname_t;
typedef int64_t rlim64_t;
#else
#ifdef NEED_SOLARIS_BOOLEAN
#if defined(__XOPEN_OR_POSIX)
typedef enum { _B_FALSE, _B_TRUE } boolean_t;
#else
typedef enum { B_FALSE, B_TRUE } boolean_t;
#endif /* defined(__XOPEN_OR_POSIX) */
#endif
typedef longlong_t offset_t;
typedef u_longlong_t u_offset_t;

View File

@ -51,6 +51,7 @@ typedef struct iovec iovec_t;
#define uio_loffset uio_offset
#ifdef BUILDING_ZFS
static __inline int
zfs_uiomove(void *cp, size_t n, enum uio_rw dir, uio_t *uio)
{
@ -59,5 +60,6 @@ zfs_uiomove(void *cp, size_t n, enum uio_rw dir, uio_t *uio)
return (uiomove(cp, (int)n, uio));
}
#define uiomove(cp, n, dir, uio) zfs_uiomove((cp), (n), (dir), (uio))
#endif
#endif /* !_OPENSOLARIS_SYS_UIO_H_ */

View File

@ -3007,6 +3007,9 @@ dtrace_dif_variable(dtrace_mstate_t *mstate, dtrace_state_t *state, uint64_t v,
case DIF_VAR_EXECARGS: {
struct pargs *p_args = curthread->td_proc->p_args;
if (p_args == NULL)
return(0);
return (dtrace_dif_varstrz(
(uintptr_t) p_args->ar_args, p_args->ar_length, state, mstate));
}
@ -10598,7 +10601,6 @@ dtrace_buffer_alloc(dtrace_buffer_t *bufs, size_t size, int flags,
/*
* If there is already a buffer allocated for this CPU, it
* is only possible that this is a DR event. In this case,
* the buffer size must match our specified size.
*/
if (buf->dtb_tomax != NULL) {
ASSERT(buf->dtb_size == size);
@ -12815,11 +12817,7 @@ dtrace_state_create(struct cdev *dev)
state = ddi_get_soft_state(dtrace_softstate, minor);
#else
if (dev != NULL) {
/*
* Disable this until we have the ability to set user
* credentials for DTrace.
* cr = dev->si_cred;
*/
cr = dev->si_cred;
m = dev2unit(dev);
}
@ -15241,6 +15239,15 @@ dtrace_attach(dev_info_t *devi, ddi_attach_cmd_t cmd)
}
#endif
#if !defined(sun)
#if __FreeBSD_version >= 800039
static void
dtrace_dtr(void *data __unused)
{
}
#endif
#endif
/*ARGSUSED*/
static int
#if defined(sun)
@ -15266,6 +15273,7 @@ dtrace_open(struct cdev *dev, int oflags, int devtype, struct thread *td)
#else
cred_t *cred_p = NULL;
#if __FreeBSD_version < 800039
/*
* The first minor device is the one that is cloned so there is
* nothing more to do here.
@ -15281,6 +15289,7 @@ dtrace_open(struct cdev *dev, int oflags, int devtype, struct thread *td)
*/
if (dev->si_drv1 != NULL)
return (EBUSY);
#endif
cred_p = dev->si_cred;
#endif
@ -15292,8 +15301,10 @@ dtrace_open(struct cdev *dev, int oflags, int devtype, struct thread *td)
dtrace_cred2priv(cred_p, &priv, &uid, &zoneid);
if (priv == DTRACE_PRIV_NONE) {
#if !defined(sun)
#if __FreeBSD_version < 800039
/* Destroy the cloned device. */
destroy_dev(dev);
#endif
#endif
return (EACCES);
@ -15326,7 +15337,11 @@ dtrace_open(struct cdev *dev, int oflags, int devtype, struct thread *td)
state = dtrace_state_create(devp, cred_p);
#else
state = dtrace_state_create(dev);
#if __FreeBSD_version < 800039
dev->si_drv1 = state;
#else
devfs_set_cdevpriv(state, dtrace_dtr);
#endif
#endif
mutex_exit(&cpu_lock);
@ -15340,8 +15355,10 @@ dtrace_open(struct cdev *dev, int oflags, int devtype, struct thread *td)
#endif
mutex_exit(&dtrace_lock);
#if !defined(sun)
#if __FreeBSD_version < 800039
/* Destroy the cloned device. */
destroy_dev(dev);
#endif
#endif
return (EAGAIN);
}
@ -15368,11 +15385,16 @@ dtrace_close(struct cdev *dev, int flags, int fmt __unused, struct thread *td)
state = ddi_get_soft_state(dtrace_softstate, minor);
#else
#if __FreeBSD_version < 800039
dtrace_state_t *state = dev->si_drv1;
/* Check if this is not a cloned device. */
if (dev2unit(dev) == 0)
return (0);
#else
dtrace_state_t *state;
devfs_get_cdevpriv((void **) &state);
#endif
#endif
@ -15392,7 +15414,11 @@ dtrace_close(struct cdev *dev, int flags, int fmt __unused, struct thread *td)
#if !defined(sun)
kmem_free(state, 0);
#if __FreeBSD_version < 800039
dev->si_drv1 = NULL;
#else
devfs_clear_cdevpriv();
#endif
#endif
}
@ -15407,8 +15433,10 @@ dtrace_close(struct cdev *dev, int flags, int fmt __unused, struct thread *td)
mutex_exit(&dtrace_lock);
mutex_exit(&cpu_lock);
#if __FreeBSD_version < 800039
/* Schedule this cloned device to be destroyed. */
destroy_dev_sched(dev);
#endif
return (0);
}
@ -16442,16 +16470,20 @@ _fini(void)
static d_ioctl_t dtrace_ioctl;
static void dtrace_load(void *);
static int dtrace_unload(void);
#if __FreeBSD_version < 800039
static void dtrace_clone(void *, struct ucred *, char *, int , struct cdev **);
static struct clonedevs *dtrace_clones; /* Ptr to the array of cloned devices. */
static eventhandler_tag eh_tag; /* Event handler tag. */
#else
static struct cdev *dtrace_dev;
#endif
void dtrace_invop_init(void);
void dtrace_invop_uninit(void);
static struct cdevsw dtrace_cdevsw = {
.d_version = D_VERSION,
.d_flags = D_NEEDMINOR,
.d_flags = D_TRACKCLOSE | D_NEEDMINOR,
.d_close = dtrace_close,
.d_ioctl = dtrace_ioctl,
.d_open = dtrace_open,
@ -16459,7 +16491,9 @@ static struct cdevsw dtrace_cdevsw = {
};
#include <dtrace_anon.c>
#if __FreeBSD_version < 800039
#include <dtrace_clone.c>
#endif
#include <dtrace_ioctl.c>
#include <dtrace_load.c>
#include <dtrace_modevent.c>

View File

@ -2044,13 +2044,6 @@ fasttrap_ioctl(dev_t dev, int cmd, intptr_t arg, int md, cred_t *cr, int *rv)
tp->ftt_proc->ftpc_acount != 0)
break;
/*
* The count of active providers can only be
* decremented (i.e. to zero) during exec, exit, and
* removal of a meta provider so it should be
* impossible to drop the count during this operation().
*/
ASSERT(tp->ftt_proc->ftpc_acount != 0);
tp = tp->ftt_next;
}

View File

@ -32,7 +32,12 @@ static int
dtrace_ioctl(struct cdev *dev, u_long cmd, caddr_t addr,
int flags __unused, struct thread *td)
{
#if __FreeBSD_version < 800039
dtrace_state_t *state = dev->si_drv1;
#else
dtrace_state_t *state;
devfs_get_cdevpriv((void **) &state);
#endif
int error = 0;
if (state == NULL)
return (EINVAL);

View File

@ -154,11 +154,15 @@ dtrace_load(void *dummy)
mutex_exit(&cpu_lock);
#if __FreeBSD_version < 800039
/* Enable device cloning. */
clone_setup(&dtrace_clones);
/* Setup device cloning events. */
eh_tag = EVENTHANDLER_REGISTER(dev_clone, dtrace_clone, 0, 1000);
#else
dtrace_dev = make_dev(&dtrace_cdevsw, 0, UID_ROOT, GID_WHEEL, 0600, "dtrace/dtrace");
#endif
return;
}

View File

@ -28,6 +28,7 @@ dtrace_unload()
dtrace_state_t *state;
int error = 0;
#if __FreeBSD_version < 800039
/*
* Check if there is still an event handler callback
* registered.
@ -40,6 +41,9 @@ dtrace_unload()
/* Stop device cloning. */
clone_cleanup(&dtrace_clones);
}
#else
destroy_dev(dtrace_dev);
#endif
mutex_enter(&dtrace_provider_lock);
mutex_enter(&dtrace_lock);

View File

@ -50,15 +50,41 @@
#include <sys/proc.h>
#include <sys/selinfo.h>
#include <sys/smp.h>
#include <sys/syscall.h>
#include <sys/sysent.h>
#include <sys/sysproto.h>
#include <sys/sysent.h>
#include <sys/uio.h>
#include <sys/unistd.h>
#include <machine/stdarg.h>
#include <sys/dtrace.h>
#ifdef LINUX_SYSTRACE
#include <linux.h>
#include <linux_syscall.h>
#include <linux_proto.h>
#include <linux_syscallnames.c>
#include <linux_systrace.c>
extern struct sysent linux_sysent[];
#define DEVNAME "dtrace/linsystrace"
#define PROVNAME "linsyscall"
#define MAXSYSCALL LINUX_SYS_MAXSYSCALL
#define SYSCALLNAMES linux_syscallnames
#define SYSENT linux_sysent
#else
/*
* The syscall arguments are processed into a DTrace argument array
* using a generated function. See sys/kern/makesyscalls.sh.
*/
#include <sys/syscall.h>
#include <kern/systrace_args.c>
extern const char *syscallnames[];
#define DEVNAME "dtrace/systrace"
#define PROVNAME "syscall"
#define MAXSYSCALL SYS_MAXSYSCALL
#define SYSCALLNAMES syscallnames
#define SYSENT sysent
#endif
#define SYSTRACE_ARTIFICIAL_FRAMES 1
#define SYSTRACE_SHIFT 16
@ -67,17 +93,13 @@
#define SYSTRACE_ENTRY(id) ((1 << SYSTRACE_SHIFT) | (id))
#define SYSTRACE_RETURN(id) (id)
#if ((1 << SYSTRACE_SHIFT) <= SYS_MAXSYSCALL)
#if ((1 << SYSTRACE_SHIFT) <= MAXSYSCALL)
#error 1 << SYSTRACE_SHIFT must exceed number of system calls
#endif
extern char *syscallnames[];
static d_open_t systrace_open;
static int systrace_unload(void);
static void systrace_getargdesc(void *, dtrace_id_t, void *, dtrace_argdesc_t *);
static void systrace_args(int, void *, u_int64_t *, int *);
static void systrace_probe(u_int32_t, int, struct sysent *, void *);
static void systrace_provide(void *, dtrace_probedesc_t *);
static void systrace_destroy(void *, dtrace_id_t, void *);
static void systrace_enable(void *, dtrace_id_t, void *);
@ -87,9 +109,18 @@ static void systrace_load(void *);
static struct cdevsw systrace_cdevsw = {
.d_version = D_VERSION,
.d_open = systrace_open,
#ifdef LINUX_SYSTRACE
.d_name = "linsystrace",
#else
.d_name = "systrace",
#endif
};
static union {
const char **p_constnames;
char **pp_syscallnames;
} uglyhack = { SYSCALLNAMES };
static dtrace_pattr_t systrace_attr = {
{ DTRACE_STABILITY_EVOLVING, DTRACE_STABILITY_EVOLVING, DTRACE_CLASS_COMMON },
{ DTRACE_STABILITY_PRIVATE, DTRACE_STABILITY_PRIVATE, DTRACE_CLASS_UNKNOWN },
@ -114,12 +145,14 @@ static dtrace_pops_t systrace_pops = {
static struct cdev *systrace_cdev;
static dtrace_provider_id_t systrace_id;
#if !defined(LINUX_SYSTRACE)
/*
* The syscall arguments are processed into a DTrace argument array
* using a generated function. See sys/kern/makesyscalls.sh.
* Probe callback function.
*
* Note: This function is called for _all_ syscalls, regardless of which sysent
* array the syscall comes from. It could be a standard syscall or a
* compat syscall from something like Linux.
*/
#include <kern/systrace_args.c>
static void
systrace_probe(u_int32_t id, int sysnum, struct sysent *sysent, void *params)
{
@ -127,21 +160,20 @@ systrace_probe(u_int32_t id, int sysnum, struct sysent *sysent, void *params)
u_int64_t uargs[8];
/*
* Check if this syscall has a custom argument conversion
* function registered. If so, it is a syscall registered
* by a loaded module.
* Check if this syscall has an argument conversion function
* registered.
*/
if (sysent->sy_systrace_args_func != NULL)
/*
* Convert the syscall parameters using the registered
* function.
*/
(*sysent->sy_systrace_args_func)(params, uargs, &n_args);
(*sysent->sy_systrace_args_func)(sysnum, params, uargs, &n_args);
else
/*
* Use the built-in system call argument conversion
* function to translate the syscall structure fields
* into thhe array of 64-bit values that DTrace
* into the array of 64-bit values that DTrace
* expects.
*/
systrace_args(sysnum, params, uargs, &n_args);
@ -149,6 +181,7 @@ systrace_probe(u_int32_t id, int sysnum, struct sysent *sysent, void *params)
/* Process the probe using the converted argments. */
dtrace_probe(id, uargs[0], uargs[1], uargs[2], uargs[3], uargs[4]);
}
#endif
static void
systrace_getargdesc(void *arg, dtrace_id_t id, void *parg, dtrace_argdesc_t *desc)
@ -172,15 +205,15 @@ systrace_provide(void *arg, dtrace_probedesc_t *desc)
if (desc != NULL)
return;
for (i = 0; i < SYS_MAXSYSCALL; i++) {
for (i = 0; i < MAXSYSCALL; i++) {
if (dtrace_probe_lookup(systrace_id, NULL,
syscallnames[i], "entry") != 0)
uglyhack.pp_syscallnames[i], "entry") != 0)
continue;
(void) dtrace_probe_create(systrace_id, NULL, syscallnames[i],
(void) dtrace_probe_create(systrace_id, NULL, uglyhack.pp_syscallnames[i],
"entry", SYSTRACE_ARTIFICIAL_FRAMES,
(void *)((uintptr_t)SYSTRACE_ENTRY(i)));
(void) dtrace_probe_create(systrace_id, NULL, syscallnames[i],
(void) dtrace_probe_create(systrace_id, NULL, uglyhack.pp_syscallnames[i],
"return", SYSTRACE_ARTIFICIAL_FRAMES,
(void *)((uintptr_t)SYSTRACE_RETURN(i)));
}
@ -209,10 +242,13 @@ systrace_enable(void *arg, dtrace_id_t id, void *parg)
{
int sysnum = SYSTRACE_SYSNUM((uintptr_t)parg);
if (SYSENT[sysnum].sy_systrace_args_func == NULL)
SYSENT[sysnum].sy_systrace_args_func = systrace_args;
if (SYSTRACE_ISENTRY((uintptr_t)parg))
sysent[sysnum].sy_entry = id;
SYSENT[sysnum].sy_entry = id;
else
sysent[sysnum].sy_return = id;
SYSENT[sysnum].sy_return = id;
}
static void
@ -220,8 +256,8 @@ systrace_disable(void *arg, dtrace_id_t id, void *parg)
{
int sysnum = SYSTRACE_SYSNUM((uintptr_t)parg);
sysent[sysnum].sy_entry = 0;
sysent[sysnum].sy_return = 0;
SYSENT[sysnum].sy_entry = 0;
SYSENT[sysnum].sy_return = 0;
}
static void
@ -229,13 +265,15 @@ systrace_load(void *dummy)
{
/* Create the /dev/dtrace/systrace entry. */
systrace_cdev = make_dev(&systrace_cdevsw, 0, UID_ROOT, GID_WHEEL, 0600,
"dtrace/systrace");
DEVNAME);
if (dtrace_register("syscall", &systrace_attr, DTRACE_PRIV_USER,
if (dtrace_register(PROVNAME, &systrace_attr, DTRACE_PRIV_USER,
NULL, &systrace_pops, NULL, &systrace_id) != 0)
return;
#if !defined(LINUX_SYSTRACE)
systrace_probe_func = systrace_probe;
#endif
}
@ -247,7 +285,9 @@ systrace_unload()
if ((error = dtrace_unregister(systrace_id)) != 0)
return (error);
#if !defined(LINUX_SYSTRACE)
systrace_probe_func = NULL;
#endif
destroy_dev(systrace_cdev);
@ -286,7 +326,16 @@ systrace_open(struct cdev *dev __unused, int oflags __unused, int devtype __unus
SYSINIT(systrace_load, SI_SUB_DTRACE_PROVIDER, SI_ORDER_ANY, systrace_load, NULL);
SYSUNINIT(systrace_unload, SI_SUB_DTRACE_PROVIDER, SI_ORDER_ANY, systrace_unload, NULL);
#ifdef LINUX_SYSTRACE
DEV_MODULE(linsystrace, systrace_modevent, NULL);
MODULE_VERSION(linsystrace, 1);
MODULE_DEPEND(linsystrace, linux, 1, 1, 1);
MODULE_DEPEND(linsystrace, systrace, 1, 1, 1);
MODULE_DEPEND(linsystrace, dtrace, 1, 1, 1);
MODULE_DEPEND(linsystrace, opensolaris, 1, 1, 1);
#else
DEV_MODULE(systrace, systrace_modevent, NULL);
MODULE_VERSION(systrace, 1);
MODULE_DEPEND(systrace, dtrace, 1, 1, 1);
MODULE_DEPEND(systrace, opensolaris, 1, 1, 1);
#endif

View File

@ -48,7 +48,7 @@ typedef void (*systrace_probe_func_t)(u_int32_t, int, struct sysent *, void *);
* Used by loaded syscalls to convert arguments to a DTrace array
* of 64-bit arguments.
*/
typedef void (*systrace_args_func_t)(void *, u_int64_t *, int *);
typedef void (*systrace_args_func_t)(int, void *, u_int64_t *, int *);
extern systrace_probe_func_t systrace_probe_func;