Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 8 Dec 2007 00:26:27 GMT
From:      John Birrell <jb@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 130445 for review
Message-ID:  <200712080026.lB80QRJX068943@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=130445

Change 130445 by jb@jb_freebsd1 on 2007/12/08 00:25:53

	Save some WIP. I really wish this file had been coded in multiple files.
	There are too many lines here.

Affected files ...

.. //depot/projects/dtrace/src/sys/contrib/opensolaris/uts/common/dtrace/dtrace.c#2 edit

Differences ...

==== //depot/projects/dtrace/src/sys/contrib/opensolaris/uts/common/dtrace/dtrace.c#2 (text) ====

@@ -66,34 +66,58 @@
  * on capital-f functions.
  */
 #include <sys/errno.h>
+#if !defined(sun)
+#include <sys/time.h>
+#endif
 #include <sys/stat.h>
 #include <sys/modctl.h>
 #include <sys/conf.h>
 #include <sys/systm.h>
+#if defined(sun)
 #include <sys/ddi.h>
 #include <sys/sunddi.h>
+#endif
 #include <sys/cpuvar.h>
 #include <sys/kmem.h>
+#if defined(sun)
 #include <sys/strsubr.h>
+#endif
 #include <sys/sysmacros.h>
 #include <sys/dtrace_impl.h>
 #include <sys/atomic.h>
 #include <sys/cmn_err.h>
+#if defined(sun)
 #include <sys/mutex_impl.h>
 #include <sys/rwlock_impl.h>
+#endif
 #include <sys/ctf_api.h>
+#if defined(sun)
 #include <sys/panic.h>
 #include <sys/priv_impl.h>
+#endif
 #include <sys/policy.h>
+#if defined(sun)
 #include <sys/cred_impl.h>
 #include <sys/procfs_isa.h>
+#endif
 #include <sys/taskq.h>
+#if defined(sun)
 #include <sys/mkdev.h>
 #include <sys/kdi.h>
+#endif
 #include <sys/zone.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
 
+/* FreeBSD includes: */
+#if !defined(sun)
+#include <sys/limits.h>
+#include <sys/kernel.h>
+#include <sys/malloc.h>
+#include <sys/vmem.h>
+#include "dtrace_cddl.h"
+#endif
+
 /*
  * DTrace Tunable Variables
  *
@@ -161,7 +185,9 @@
 /*
  * DTrace Internal Variables
  */
+#if defined(sun)
 static dev_info_t	*dtrace_devi;		/* device info */
+#endif
 static vmem_t		*dtrace_arena;		/* probe ID arena */
 static vmem_t		*dtrace_minor;		/* minor number arena */
 static taskq_t		*dtrace_taskq;		/* task queue */
@@ -222,6 +248,40 @@
 static kmutex_t		dtrace_provider_lock;	/* provider state lock */
 static kmutex_t		dtrace_meta_lock;	/* meta-provider state lock */
 
+#if !defined(sun)
+MALLOC_DEFINE(M_DTRACE, "dtrace", "Dynamic Trace");
+
+/* XXX FreeBSD hacks. */
+static kmutex_t		cpu_lock;
+static kmutex_t		mod_lock;
+
+#define cr_suid		cr_svuid
+#define cr_sgid		cr_svgid
+#define mod_modname	pathname
+#define vuprintf	vprintf
+#define ttoproc(_a)	((_a)->td_proc)
+#define crgetzoneid(_a)	0
+#define	NCPU		32
+#define SNOCD		0
+#define CPU_ON_INTR(_a)	0
+#define M_KMEM		M_DTRACE
+
+#define PRIV_EFFECTIVE		(1 << 0)
+#define PRIV_DTRACE_KERNEL	(1 << 1)
+#define PRIV_DTRACE_PROC	(1 << 2)
+#define PRIV_DTRACE_USER	(1 << 3)
+#define PRIV_PROC_OWNER		(1 << 4)
+#define PRIV_PROC_ZONE		(1 << 5)
+#define PRIV_ALL		~0
+
+
+#endif
+
+#if defined(sun)
+#define curcpu	CPU->cpu_id
+#endif
+
+
 /*
  * DTrace Provider Variables
  *
@@ -241,8 +301,8 @@
 {}
 
 static dtrace_pops_t	dtrace_provider_ops = {
-	(void (*)(void *, const dtrace_probedesc_t *))dtrace_nullop,
-	(void (*)(void *, struct modctl *))dtrace_nullop,
+	(void (*)(void *, dtrace_probedesc_t *))dtrace_nullop,
+	(void (*)(void *, modctl_t *))dtrace_nullop,
 	(void (*)(void *, dtrace_id_t, void *))dtrace_nullop,
 	(void (*)(void *, dtrace_id_t, void *))dtrace_nullop,
 	(void (*)(void *, dtrace_id_t, void *))dtrace_nullop,
@@ -349,7 +409,7 @@
 #define	DTRACE_ALIGNCHECK(addr, size, flags)				\
 	if (addr & (size - 1)) {					\
 		*flags |= CPU_DTRACE_BADALIGN;				\
-		cpu_core[CPU->cpu_id].cpuc_dtrace_illval = addr;	\
+		cpu_core[curcpu].cpuc_dtrace_illval = addr;	\
 		return (0);						\
 	}
 #else
@@ -388,7 +448,7 @@
 	uint##bits##_t rval;						\
 	int i;								\
 	volatile uint16_t *flags = (volatile uint16_t *)		\
-	    &cpu_core[CPU->cpu_id].cpuc_dtrace_flags;			\
+	    &cpu_core[curcpu].cpuc_dtrace_flags;			\
 									\
 	DTRACE_ALIGNCHECK(addr, size, flags);				\
 									\
@@ -403,7 +463,7 @@
 		 * This address falls within a toxic region; return 0.	\
 		 */							\
 		*flags |= CPU_DTRACE_BADADDR;				\
-		cpu_core[CPU->cpu_id].cpuc_dtrace_illval = addr;	\
+		cpu_core[curcpu].cpuc_dtrace_illval = addr;	\
 		return (0);						\
 	}								\
 									\
@@ -446,6 +506,7 @@
 	((act)->dta_kind == DTRACEACT_DIFEXPR &&			\
 	(act)->dta_difo->dtdo_rtype.dtdt_kind == DIF_TYPE_STRING)
 
+/* Function prototype definitions: */
 static size_t dtrace_strlen(const char *, size_t);
 static dtrace_probe_t *dtrace_probe_lookup_id(dtrace_id_t id);
 static void dtrace_enabling_provide(dtrace_provider_t *);
@@ -462,6 +523,14 @@
     dtrace_optval_t);
 static int dtrace_ecb_create_enable(dtrace_probe_t *, void *);
 static void dtrace_helper_provider_destroy(dtrace_helper_provider_t *);
+uint16_t dtrace_load16(uintptr_t);
+uint32_t dtrace_load32(uintptr_t);
+uint64_t dtrace_load64(uintptr_t);
+uint8_t dtrace_load8(uintptr_t);
+void dtrace_dynvar_clean(dtrace_dstate_t *);
+dtrace_dynvar_t *dtrace_dynvar(dtrace_dstate_t *, uint_t, dtrace_key_t *,
+    size_t, dtrace_dynvar_op_t, dtrace_mstate_t *, dtrace_vstate_t *);
+uintptr_t dtrace_dif_varstr(uintptr_t, dtrace_state_t *, dtrace_mstate_t *);
 
 /*
  * DTrace Probe Context Functions
@@ -672,7 +741,7 @@
 dtrace_canload(uint64_t addr, size_t sz, dtrace_mstate_t *mstate,
     dtrace_vstate_t *vstate)
 {
-	volatile uintptr_t *illval = &cpu_core[CPU->cpu_id].cpuc_dtrace_illval;
+	volatile uintptr_t *illval = &cpu_core[curcpu].cpuc_dtrace_illval;
 
 	/*
 	 * If we hold the privilege to read from kernel memory, then
@@ -764,7 +833,7 @@
 	if (s1 == s2 || limit == 0)
 		return (0);
 
-	flags = (volatile uint16_t *)&cpu_core[CPU->cpu_id].cpuc_dtrace_flags;
+	flags = (volatile uint16_t *)&cpu_core[curcpu].cpuc_dtrace_flags;
 
 	do {
 		if (s1 == NULL) {
@@ -818,13 +887,13 @@
 
 		if (kaddr - taddr < tsize) {
 			DTRACE_CPUFLAG_SET(CPU_DTRACE_BADADDR);
-			cpu_core[CPU->cpu_id].cpuc_dtrace_illval = kaddr;
+			cpu_core[curcpu].cpuc_dtrace_illval = kaddr;
 			return (1);
 		}
 
 		if (taddr - kaddr < size) {
 			DTRACE_CPUFLAG_SET(CPU_DTRACE_BADADDR);
-			cpu_core[CPU->cpu_id].cpuc_dtrace_illval = taddr;
+			cpu_core[curcpu].cpuc_dtrace_illval = taddr;
 			return (1);
 		}
 	}
@@ -908,7 +977,7 @@
 {
 	volatile uint16_t *flags;
 
-	flags = (volatile uint16_t *)&cpu_core[CPU->cpu_id].cpuc_dtrace_flags;
+	flags = (volatile uint16_t *)&cpu_core[curcpu].cpuc_dtrace_flags;
 
 	if (s1 == s2)
 		return (0);
@@ -977,6 +1046,7 @@
 static int
 dtrace_priv_proc_common_zone(dtrace_state_t *state)
 {
+#if defined(sun)
 	cred_t *cr, *s_cr = state->dts_cred.dcr_cred;
 
 	/*
@@ -990,6 +1060,9 @@
 		return (1);
 
 	return (0);
+#else
+	return (1);
+#endif
 }
 
 /*
@@ -997,7 +1070,7 @@
  * verify that the process has not setuid or changed credentials.
  */
 static int
-dtrace_priv_proc_common_nocd()
+dtrace_priv_proc_common_nocd(void)
 {
 	proc_t *proc;
 
@@ -1028,7 +1101,7 @@
 	return (1);
 
 bad:
-	cpu_core[CPU->cpu_id].cpuc_dtrace_flags |= CPU_DTRACE_UPRIV;
+	cpu_core[curcpu].cpuc_dtrace_flags |= CPU_DTRACE_UPRIV;
 
 	return (0);
 }
@@ -1044,7 +1117,7 @@
 	    dtrace_priv_proc_common_nocd())
 		return (1);
 
-	cpu_core[CPU->cpu_id].cpuc_dtrace_flags |= CPU_DTRACE_UPRIV;
+	cpu_core[curcpu].cpuc_dtrace_flags |= CPU_DTRACE_UPRIV;
 
 	return (0);
 }
@@ -1055,7 +1128,7 @@
 	if (state->dts_cred.dcr_action & DTRACE_CRA_PROC)
 		return (1);
 
-	cpu_core[CPU->cpu_id].cpuc_dtrace_flags |= CPU_DTRACE_UPRIV;
+	cpu_core[curcpu].cpuc_dtrace_flags |= CPU_DTRACE_UPRIV;
 
 	return (0);
 }
@@ -1066,7 +1139,7 @@
 	if (state->dts_cred.dcr_action & DTRACE_CRA_KERNEL)
 		return (1);
 
-	cpu_core[CPU->cpu_id].cpuc_dtrace_flags |= CPU_DTRACE_KPRIV;
+	cpu_core[curcpu].cpuc_dtrace_flags |= CPU_DTRACE_KPRIV;
 
 	return (0);
 }
@@ -1077,7 +1150,7 @@
 	if (state->dts_cred.dcr_action & DTRACE_CRA_KERNEL_DESTRUCTIVE)
 		return (1);
 
-	cpu_core[CPU->cpu_id].cpuc_dtrace_flags |= CPU_DTRACE_KPRIV;
+	cpu_core[curcpu].cpuc_dtrace_flags |= CPU_DTRACE_KPRIV;
 
 	return (0);
 }
@@ -1188,7 +1261,7 @@
 	uint64_t hashval = DTRACE_DYNHASH_VALID;
 	dtrace_dynhash_t *hash = dstate->dtds_hash;
 	dtrace_dynvar_t *free, *new_free, *next, *dvar, *start, *prev = NULL;
-	processorid_t me = CPU->cpu_id, cpu = me;
+	processorid_t me = curcpu, cpu = me;
 	dtrace_dstate_percpu_t *dcpu = &dstate->dtds_percpu[me];
 	size_t bucket, ksize;
 	size_t chunksize = dstate->dtds_chunksize;
@@ -1279,8 +1352,8 @@
 			while ((lock = *lockp) & 1)
 				continue;
 
-			if (dtrace_casptr((void *)lockp,
-			    (void *)lock, (void *)(lock + 1)) == (void *)lock)
+			if (dtrace_casptr((volatile void *)lockp,
+			    (volatile void *)lock, (volatile void *)(lock + 1)) == (void *)lock)
 				break;
 		}
 
@@ -2245,7 +2318,7 @@
 dtrace_speculation_clean_here(dtrace_state_t *state)
 {
 	dtrace_icookie_t cookie;
-	processorid_t cpu = CPU->cpu_id;
+	processorid_t cpu = curcpu;
 	dtrace_buffer_t *dest = &state->dts_buffer[cpu];
 	dtrace_specid_t i;
 
@@ -2442,7 +2515,7 @@
 	if (mstate->dtms_scratch_ptr + strsz >
 	    mstate->dtms_scratch_base + mstate->dtms_scratch_size) {
 		DTRACE_CPUFLAG_SET(CPU_DTRACE_NOSCRATCH);
-		return (NULL);
+		return (0);
 	}
 
 	dtrace_strcpy((const void *)addr, (void *)mstate->dtms_scratch_ptr,
@@ -2504,6 +2577,7 @@
 		return (mstate->dtms_arg[ndx]);
 
 	case DIF_VAR_UREGS: {
+#ifdef DOODAD
 		klwp_t *lwp;
 
 		if (!dtrace_priv_proc(state))
@@ -2511,11 +2585,14 @@
 
 		if ((lwp = curthread->t_lwp) == NULL) {
 			DTRACE_CPUFLAG_SET(CPU_DTRACE_BADADDR);
-			cpu_core[CPU->cpu_id].cpuc_dtrace_illval = NULL;
+			cpu_core[curcpu].cpuc_dtrace_illval = NULL;
 			return (0);
 		}
 
 		return (dtrace_getreg(lwp->lwp_regs, ndx));
+#else
+		return (0);
+#endif
 	}
 
 	case DIF_VAR_CURTHREAD:
@@ -2638,7 +2715,7 @@
 			 * uint64_t will contain the caller, which is what
 			 * we're after.
 			 */
-			ustack[2] = NULL;
+			ustack[2] = 0;
 			DTRACE_CPUFLAG_SET(CPU_DTRACE_NOFAULT);
 			dtrace_getupcstack(ustack, 3);
 			DTRACE_CPUFLAG_CLEAR(CPU_DTRACE_NOFAULT);
@@ -2676,6 +2753,7 @@
 		if (!dtrace_priv_proc(state))
 			return (0);
 
+#if defined(sun)
 		/*
 		 * Note that we are assuming that an unanchored probe is
 		 * always due to a high-level interrupt.  (And we're assuming
@@ -2693,11 +2771,15 @@
 		 * they leave that task to whomever reaps them.)
 		 */
 		return ((uint64_t)curthread->t_procp->p_pidp->pid_id);
+#else
+		return ((uint64_t)curproc->p_pid);
+#endif
 
 	case DIF_VAR_PPID:
 		if (!dtrace_priv_proc(state))
 			return (0);
 
+#if defined(sun)
 		/*
 		 * See comment in DIF_VAR_PID.
 		 */
@@ -2711,6 +2793,9 @@
 		 * state -- they leave that task to whomever reaps them.)
 		 */
 		return ((uint64_t)curthread->t_procp->p_ppid);
+#else
+		return ((uint64_t)curproc->p_ppid);
+#endif
 
 	case DIF_VAR_TID:
 		/*
@@ -2742,6 +2827,7 @@
 		    state, mstate));
 
 	case DIF_VAR_ZONENAME:
+#if defined(sun)
 		if (!dtrace_priv_proc(state))
 			return (0);
 
@@ -2760,6 +2846,9 @@
 		return (dtrace_dif_varstr(
 		    (uintptr_t)curthread->t_procp->p_zone->zone_name,
 		    state, mstate));
+#else
+		return (0);
+#endif
 
 	case DIF_VAR_UID:
 		if (!dtrace_priv_proc(state))
@@ -2843,8 +2932,8 @@
     dtrace_key_t *tupregs, int nargs,
     dtrace_mstate_t *mstate, dtrace_state_t *state)
 {
-	volatile uint16_t *flags = &cpu_core[CPU->cpu_id].cpuc_dtrace_flags;
-	volatile uintptr_t *illval = &cpu_core[CPU->cpu_id].cpuc_dtrace_illval;
+	volatile uint16_t *flags = &cpu_core[curcpu].cpuc_dtrace_flags;
+	volatile uintptr_t *illval = &cpu_core[curcpu].cpuc_dtrace_illval;
 	dtrace_vstate_t *vstate = &state->dts_vstate;
 
 	union {
@@ -2865,7 +2954,7 @@
 	case DIF_SUBR_MUTEX_OWNED:
 		if (!dtrace_canload(tupregs[0].dttk_value, sizeof (kmutex_t),
 		    mstate, vstate)) {
-			regs[rd] = NULL;
+			regs[rd] = 0;
 			break;
 		}
 
@@ -2879,7 +2968,7 @@
 	case DIF_SUBR_MUTEX_OWNER:
 		if (!dtrace_canload(tupregs[0].dttk_value, sizeof (kmutex_t),
 		    mstate, vstate)) {
-			regs[rd] = NULL;
+			regs[rd] = 0;
 			break;
 		}
 
@@ -2894,7 +2983,7 @@
 	case DIF_SUBR_MUTEX_TYPE_ADAPTIVE:
 		if (!dtrace_canload(tupregs[0].dttk_value, sizeof (kmutex_t),
 		    mstate, vstate)) {
-			regs[rd] = NULL;
+			regs[rd] = 0;
 			break;
 		}
 
@@ -2905,7 +2994,7 @@
 	case DIF_SUBR_MUTEX_TYPE_SPIN:
 		if (!dtrace_canload(tupregs[0].dttk_value, sizeof (kmutex_t),
 		    mstate, vstate)) {
-			regs[rd] = NULL;
+			regs[rd] = 0;
 			break;
 		}
 
@@ -2918,7 +3007,7 @@
 
 		if (!dtrace_canload(tupregs[0].dttk_value, sizeof (uintptr_t),
 		    mstate, vstate)) {
-			regs[rd] = NULL;
+			regs[rd] = 0;
 			break;
 		}
 
@@ -2930,7 +3019,7 @@
 	case DIF_SUBR_RW_WRITE_HELD:
 		if (!dtrace_canload(tupregs[0].dttk_value, sizeof (krwlock_t),
 		    mstate, vstate)) {
-			regs[rd] = NULL;
+			regs[rd] = 0;
 			break;
 		}
 
@@ -2941,7 +3030,7 @@
 	case DIF_SUBR_RW_ISWRITER:
 		if (!dtrace_canload(tupregs[0].dttk_value, sizeof (krwlock_t),
 		    mstate, vstate)) {
-			regs[rd] = NULL;
+			regs[rd] = 0;
 			break;
 		}
 
@@ -2965,7 +3054,7 @@
 		}
 
 		if (!dtrace_canload(src, size, mstate, vstate)) {
-			regs[rd] = NULL;
+			regs[rd] = 0;
 			break;
 		}
 
@@ -2993,7 +3082,7 @@
 		if (scratch_size < size ||
 		    !DTRACE_INSCRATCH(mstate, scratch_size)) {
 			DTRACE_CPUFLAG_SET(CPU_DTRACE_NOSCRATCH);
-			regs[rd] = NULL;
+			regs[rd] = 0;
 			break;
 		}
 
@@ -3043,7 +3132,7 @@
 		 */
 		if (!DTRACE_INSCRATCH(mstate, size)) {
 			DTRACE_CPUFLAG_SET(CPU_DTRACE_NOSCRATCH);
-			regs[rd] = NULL;
+			regs[rd] = 0;
 			break;
 		}
 
@@ -3059,16 +3148,17 @@
 
 	case DIF_SUBR_MSGSIZE:
 	case DIF_SUBR_MSGDSIZE: {
+#ifdef DOODAD
 		uintptr_t baddr = tupregs[0].dttk_value, daddr;
 		uintptr_t wptr, rptr;
 		size_t count = 0;
 		int cont = 0;
 
-		while (baddr != NULL && !(*flags & CPU_DTRACE_FAULT)) {
+		while (baddr != 0 && !(*flags & CPU_DTRACE_FAULT)) {
 
 			if (!dtrace_canload(baddr, sizeof (mblk_t), mstate,
 			    vstate)) {
-				regs[rd] = NULL;
+				regs[rd] = 0;
 				break;
 			}
 
@@ -3112,6 +3202,7 @@
 		if (!(*flags & CPU_DTRACE_FAULT))
 			regs[rd] = count;
 
+#endif
 		break;
 	}
 
@@ -3123,7 +3214,11 @@
 		DTRACE_CPUFLAG_SET(CPU_DTRACE_NOFAULT);
 
 		for (p = curthread->t_procp; p != NULL; p = p->p_parent) {
+#if defined(sun)
 			if (p->p_pidp->pid_id == pid) {
+#else
+			if (p->p_pid == pid) {
+#endif
 				rval = 1;
 				break;
 			}
@@ -3176,7 +3271,7 @@
 		    state->dts_options[DTRACEOPT_STRSIZE]);
 
 		if (!dtrace_canload(addr, sz + 1, mstate, vstate)) {
-			regs[rd] = NULL;
+			regs[rd] = 0;
 			break;
 		}
 
@@ -3199,7 +3294,7 @@
 		uintptr_t limit = addr + state->dts_options[DTRACEOPT_STRSIZE];
 		char c, target = (char)tupregs[1].dttk_value;
 
-		for (regs[rd] = NULL; addr < limit; addr++) {
+		for (regs[rd] = 0; addr < limit; addr++) {
 			if ((c = dtrace_load8(addr)) == target) {
 				regs[rd] = addr;
 
@@ -3212,7 +3307,7 @@
 		}
 
 		if (!dtrace_canload(saddr, addr - saddr, mstate, vstate)) {
-			regs[rd] = NULL;
+			regs[rd] = 0;
 			break;
 		}
 
@@ -3243,13 +3338,13 @@
 		regs[rd] = notfound;
 
 		if (!dtrace_canload((uintptr_t)addr, len + 1, mstate, vstate)) {
-			regs[rd] = NULL;
+			regs[rd] = 0;
 			break;
 		}
 
 		if (!dtrace_canload((uintptr_t)substr, sublen + 1, mstate,
 		    vstate)) {
-			regs[rd] = NULL;
+			regs[rd] = 0;
 			break;
 		}
 
@@ -3383,17 +3478,17 @@
 		 * since both could be non-scratch addresses.
 		 */
 		if (!dtrace_strcanload(tokaddr, size, mstate, vstate)) {
-			regs[rd] = NULL;
+			regs[rd] = 0;
 			break;
 		}
 
 		if (!DTRACE_INSCRATCH(mstate, size)) {
 			DTRACE_CPUFLAG_SET(CPU_DTRACE_NOSCRATCH);
-			regs[rd] = NULL;
+			regs[rd] = 0;
 			break;
 		}
 
-		if (addr == NULL) {
+		if (addr == 0) {
 			/*
 			 * If the address specified is NULL, we use our saved
 			 * strtok pointer from the mstate.  Note that this
@@ -3412,7 +3507,7 @@
 			 * would fail this access check.
 			 */
 			if (!dtrace_strcanload(addr, size, mstate, vstate)) {
-				regs[rd] = NULL;
+				regs[rd] = 0;
 				break;
 			}
 		}
@@ -3452,8 +3547,8 @@
 			 * We return NULL in this case, and we set the saved
 			 * address to NULL as well.
 			 */
-			regs[rd] = NULL;
-			mstate->dtms_strtok = NULL;
+			regs[rd] = 0;
+			mstate->dtms_strtok = 0;
 			break;
 		}
 
@@ -3489,7 +3584,7 @@
 		int64_t i = 0;
 
 		if (!dtrace_canload(s, len + 1, mstate, vstate)) {
-			regs[rd] = NULL;
+			regs[rd] = 0;
 			break;
 		}
 
@@ -3498,7 +3593,7 @@
 
 		if (!DTRACE_INSCRATCH(mstate, size)) {
 			DTRACE_CPUFLAG_SET(CPU_DTRACE_NOSCRATCH);
-			regs[rd] = NULL;
+			regs[rd] = 0;
 			break;
 		}
 
@@ -3530,22 +3625,27 @@
 	}
 
 	case DIF_SUBR_GETMAJOR:
+#ifdef DOODAD
 #ifdef _LP64
 		regs[rd] = (tupregs[0].dttk_value >> NBITSMINOR64) & MAXMAJ64;
 #else
 		regs[rd] = (tupregs[0].dttk_value >> NBITSMINOR) & MAXMAJ;
 #endif
+#endif
 		break;
 
 	case DIF_SUBR_GETMINOR:
+#ifdef DOODAD
 #ifdef _LP64
 		regs[rd] = tupregs[0].dttk_value & MAXMIN64;
 #else
 		regs[rd] = tupregs[0].dttk_value & MAXMIN;
 #endif
+#endif
 		break;
 
 	case DIF_SUBR_DDI_PATHNAME: {
+#ifdef DOODAD
 		/*
 		 * This one is a galactic mess.  We are going to roughly
 		 * emulate ddi_pathname(), but it's made more complicated
@@ -3568,12 +3668,12 @@
 		if ((mstate->dtms_access & DTRACE_ACCESS_KERNEL) == 0) {
 			*flags |= CPU_DTRACE_KPRIV;
 			*illval = daddr;
-			regs[rd] = NULL;
+			regs[rd] = 0;
 		}
 
 		if (!DTRACE_INSCRATCH(mstate, size)) {
 			DTRACE_CPUFLAG_SET(CPU_DTRACE_NOSCRATCH);
-			regs[rd] = NULL;
+			regs[rd] = 0;
 			break;
 		}
 
@@ -3707,7 +3807,7 @@
 			 * node), we're going to use the special path
 			 * "devices".
 			 */
-			if (daddr == NULL)
+			if (daddr == 0)
 				s = "devices";
 
 			len = dtrace_strlen(s, size);
@@ -3730,10 +3830,11 @@
 		if (end < start)
 			DTRACE_CPUFLAG_SET(CPU_DTRACE_NOSCRATCH);
 
-		if (daddr == NULL) {
+		if (daddr == 0) {
 			regs[rd] = (uintptr_t)end;
 			mstate->dtms_scratch_ptr += size;
 		}
+#endif
 
 		break;
 	}
@@ -3747,20 +3848,20 @@
 
 		if (!dtrace_strcanload(s1, size, mstate, vstate) ||
 		    !dtrace_strcanload(s2, size, mstate, vstate)) {
-			regs[rd] = NULL;
+			regs[rd] = 0;
 			break;
 		}
 
 		if (!DTRACE_INSCRATCH(mstate, size)) {
 			DTRACE_CPUFLAG_SET(CPU_DTRACE_NOSCRATCH);
-			regs[rd] = NULL;
+			regs[rd] = 0;
 			break;
 		}
 
 		for (;;) {
 			if (i >= size) {
 				DTRACE_CPUFLAG_SET(CPU_DTRACE_NOSCRATCH);
-				regs[rd] = NULL;
+				regs[rd] = 0;
 				break;
 			}
 
@@ -3773,7 +3874,7 @@
 		for (;;) {
 			if (i >= size) {
 				DTRACE_CPUFLAG_SET(CPU_DTRACE_NOSCRATCH);
-				regs[rd] = NULL;
+				regs[rd] = 0;
 				break;
 			}
 
@@ -3797,7 +3898,7 @@
 
 		if (!DTRACE_INSCRATCH(mstate, size)) {
 			DTRACE_CPUFLAG_SET(CPU_DTRACE_NOSCRATCH);
-			regs[rd] = NULL;
+			regs[rd] = 0;
 			break;
 		}
 
@@ -3855,13 +3956,13 @@
 		int start, end;
 
 		if (!dtrace_canload(src, len + 1, mstate, vstate)) {
-			regs[rd] = NULL;
+			regs[rd] = 0;
 			break;
 		}
 
 		if (!DTRACE_INSCRATCH(mstate, size)) {
 			DTRACE_CPUFLAG_SET(CPU_DTRACE_NOSCRATCH);
-			regs[rd] = NULL;
+			regs[rd] = 0;
 			break;
 		}
 
@@ -3983,13 +4084,13 @@
 		int i = 0, j = 0;
 
 		if (!dtrace_strcanload(src, size, mstate, vstate)) {
-			regs[rd] = NULL;
+			regs[rd] = 0;
 			break;
 		}
 
 		if (!DTRACE_INSCRATCH(mstate, size)) {
 			DTRACE_CPUFLAG_SET(CPU_DTRACE_NOSCRATCH);
-			regs[rd] = NULL;
+			regs[rd] = 0;
 			break;
 		}
 
@@ -4087,6 +4188,7 @@
 	case DIF_SUBR_INET_NTOA:
 	case DIF_SUBR_INET_NTOA6:
 	case DIF_SUBR_INET_NTOP: {
+#ifdef DOODAD
 		size_t size;
 		int af, argi, i;
 		char *base, *end;
@@ -4114,7 +4216,7 @@
 			size = INET_ADDRSTRLEN;
 			if (!DTRACE_INSCRATCH(mstate, size)) {
 				DTRACE_CPUFLAG_SET(CPU_DTRACE_NOSCRATCH);
-				regs[rd] = NULL;
+				regs[rd] = 0;
 				break;
 			}
 			base = (char *)mstate->dtms_scratch_ptr;
@@ -4169,7 +4271,7 @@
 			size = INET6_ADDRSTRLEN;
 			if (!DTRACE_INSCRATCH(mstate, size)) {
 				DTRACE_CPUFLAG_SET(CPU_DTRACE_NOSCRATCH);
-				regs[rd] = NULL;
+				regs[rd] = 0;
 				break;
 			}
 			base = (char *)mstate->dtms_scratch_ptr;
@@ -4279,12 +4381,13 @@
 			 * The user didn't use AH_INET or AH_INET6.
 			 */
 			DTRACE_CPUFLAG_SET(CPU_DTRACE_ILLOP);
-			regs[rd] = NULL;
+			regs[rd] = 0;
 			break;
 		}
 
 inetout:	regs[rd] = (uintptr_t)end + 1;
 		mstate->dtms_scratch_ptr += size;
+#endif
 		break;
 	}
 
@@ -4309,8 +4412,8 @@
 	dtrace_statvar_t *svar;
 	dtrace_dstate_t *dstate = &vstate->dtvs_dynvars;
 	dtrace_difv_t *v;
-	volatile uint16_t *flags = &cpu_core[CPU->cpu_id].cpuc_dtrace_flags;
-	volatile uintptr_t *illval = &cpu_core[CPU->cpu_id].cpuc_dtrace_illval;
+	volatile uint16_t *flags = &cpu_core[curcpu].cpuc_dtrace_flags;
+	volatile uintptr_t *illval = &cpu_core[curcpu].cpuc_dtrace_illval;
 
 	dtrace_key_t tupregs[DIF_DTR_NREGS + 2]; /* +2 for thread and id */
 	uint64_t regs[DIF_DIR_NREGS];
@@ -4578,10 +4681,10 @@
 			uintptr_t s1 = regs[r1];
 			uintptr_t s2 = regs[r2];
 
-			if (s1 != NULL &&
+			if (s1 != 0 &&
 			    !dtrace_strcanload(s1, sz, mstate, vstate))
 				break;
-			if (s2 != NULL &&
+			if (s2 != 0 &&
 			    !dtrace_strcanload(s2, sz, mstate, vstate))
 				break;
 
@@ -4620,7 +4723,7 @@
 					 * then this is to be treated as a
 					 * reference to a NULL variable.
 					 */
-					regs[rd] = NULL;
+					regs[rd] = 0;
 				} else {
 					regs[rd] = a + sizeof (uint64_t);
 				}
@@ -4644,10 +4747,10 @@
 			if (v->dtdv_type.dtdt_flags & DIF_TF_BYREF) {
 				uintptr_t a = (uintptr_t)svar->dtsv_data;
 
-				ASSERT(a != NULL);
+				ASSERT(a != 0);
 				ASSERT(svar->dtsv_size != 0);
 
-				if (regs[rd] == NULL) {
+				if (regs[rd] == 0) {
 					*(uint8_t *)a = UINT8_MAX;
 					break;
 				} else {
@@ -4702,7 +4805,7 @@
 
 				sz += sizeof (uint64_t);
 				ASSERT(svar->dtsv_size == NCPU * sz);
-				a += CPU->cpu_id * sz;
+				a += curcpu * sz;
 
 				if (*(uint8_t *)a == UINT8_MAX) {
 					/*
@@ -4710,7 +4813,7 @@
 					 * then this is to be treated as a
 					 * reference to a NULL variable.
 					 */
-					regs[rd] = NULL;
+					regs[rd] = 0;
 				} else {
 					regs[rd] = a + sizeof (uint64_t);
 				}
@@ -4720,7 +4823,7 @@
 
 			ASSERT(svar->dtsv_size == NCPU * sizeof (uint64_t));
 			tmp = (uint64_t *)(uintptr_t)svar->dtsv_data;
-			regs[rd] = tmp[CPU->cpu_id];
+			regs[rd] = tmp[curcpu];
 			break;
 
 		case DIF_OP_STLS:
@@ -4741,9 +4844,9 @@
 
 				sz += sizeof (uint64_t);
 				ASSERT(svar->dtsv_size == NCPU * sz);
-				a += CPU->cpu_id * sz;
+				a += curcpu * sz;
 
-				if (regs[rd] == NULL) {
+				if (regs[rd] == 0) {
 					*(uint8_t *)a = UINT8_MAX;
 					break;
 				} else {
@@ -4763,7 +4866,7 @@
 
 			ASSERT(svar->dtsv_size == NCPU * sizeof (uint64_t));
 			tmp = (uint64_t *)(uintptr_t)svar->dtsv_data;
-			tmp[CPU->cpu_id] = regs[rd];
+			tmp[curcpu] = regs[rd];
 			break;
 
 		case DIF_OP_LDTS: {
@@ -4824,7 +4927,7 @@
 			 * Given that we're storing to thread-local data,
 			 * we need to flush our predicate cache.
 			 */
-			curthread->t_predcache = NULL;
+			curthread->t_predcache = 0;
 
 			if (dvar == NULL)
 				break;
@@ -4995,7 +5098,7 @@
 			if (size < regs[r1] ||
 			    !DTRACE_INSCRATCH(mstate, size)) {
 				DTRACE_CPUFLAG_SET(CPU_DTRACE_NOSCRATCH);
-				regs[rd] = NULL;
+				regs[rd] = 0;
 				break;
 			}
 
@@ -5141,7 +5244,9 @@
 	c[i++] = ')';
 	c[i] = '\0';
 
+#ifdef DOODAD
 	debug_enter(c);
+#endif
 }
 
 static void
@@ -5192,7 +5297,9 @@
 		curthread->t_dtrace_sig = (uint8_t)sig;
 
 	curthread->t_sig_check = 1;
+#ifdef DOODAD
 	aston(curthread);
+#endif
 }
 
 static void
@@ -5204,7 +5311,9 @@
 	if (!curthread->t_dtrace_stop) {
 		curthread->t_dtrace_stop = 1;
 		curthread->t_sig_check = 1;
+#ifdef DOODAD
 		aston(curthread);
+#endif
 	}
 }
 
@@ -5213,7 +5322,11 @@
 {
 	hrtime_t now;
 	volatile uint16_t *flags;
+#if defined(sun)
 	cpu_t *cpu = CPU;
+#else
+	cpu_t *cpu = pcpu_find(curcpu);
+#endif
 
 	if (dtrace_destructive_disallow)
 		return;
@@ -5257,13 +5370,14 @@

>>> TRUNCATED FOR MAIL (1000 lines) <<<



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200712080026.lB80QRJX068943>