PERFORCE change 133839 for review
John Birrell
jb at FreeBSD.org
Mon Jan 21 17:52:46 PST 2008
http://perforce.freebsd.org/chv.cgi?CH=133839
Change 133839 by jb at jb_freebsd1 on 2008/01/22 01:52:04
Add a new DIF variable called 'execargs' as a special case for FreeBSD
to get the argument string without all the sub-string zero terminators.
Affected files ...
.. //depot/projects/dtrace/src/contrib/opensolaris/lib/libdtrace/common/dt_open.c#20 edit
.. //depot/projects/dtrace/src/sys/contrib/opensolaris/uts/common/dtrace/dtrace.c#19 edit
.. //depot/projects/dtrace/src/sys/contrib/opensolaris/uts/common/sys/dtrace.h#29 edit
Differences ...
==== //depot/projects/dtrace/src/contrib/opensolaris/lib/libdtrace/common/dt_open.c#20 (text) ====
@@ -225,6 +225,8 @@
&dt_idops_type, "uint_t" },
{ "errno", DT_IDENT_SCALAR, 0, DIF_VAR_ERRNO, DT_ATTR_STABCMN, DT_VERS_1_0,
&dt_idops_type, "int" },
+{ "execargs", DT_IDENT_SCALAR, 0, DIF_VAR_EXECARGS,
+ DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "string" },
{ "execname", DT_IDENT_SCALAR, 0, DIF_VAR_EXECNAME,
DT_ATTR_STABCMN, DT_VERS_1_0, &dt_idops_type, "string" },
{ "exit", DT_IDENT_ACTFUNC, 0, DT_ACT_EXIT, DT_ATTR_STABCMN, DT_VERS_1_0,
@@ -1103,6 +1105,7 @@
return (set_open_errno(dtp, errp, EDT_NOMEM));
#endif
+#if defined(sun)
#ifdef __x86
/*
* On x86 systems, __i386 is defined for <sys/isa_defs.h> for 32-bit
@@ -1117,6 +1120,17 @@
return (set_open_errno(dtp, errp, EDT_NOMEM));
}
#endif
+#else
+#if defined(__amd64__) || defined(__i386__)
+ if (dtp->dt_conf.dtc_ctfmodel == CTF_MODEL_LP64) {
+ if (dt_cpp_add_arg(dtp, "-m64") == NULL)
+ return (set_open_errno(dtp, errp, EDT_NOMEM));
+ } else {
+ if (dt_cpp_add_arg(dtp, "-m32") == NULL)
+ return (set_open_errno(dtp, errp, EDT_NOMEM));
+ }
+#endif
+#endif
if (dtp->dt_conf.dtc_difversion < DIF_VERSION)
return (set_open_errno(dtp, errp, EDT_DIFVERS));
==== //depot/projects/dtrace/src/sys/contrib/opensolaris/uts/common/dtrace/dtrace.c#19 (text) ====
@@ -2558,6 +2558,44 @@
}
/*
+ * Return a string from a memoy address which is known to have one or
+ * more concatenated, individually zero terminated, sub-strings.
+ * In the event that the user lacks the privilege to access
+ * arbitrary kernel memory, we copy the string out to scratch memory so that we
+ * don't fail access checking.
+ *
+ * dtrace_dif_variable() uses this routine as a helper for various
+ * builtin values such as 'execargs'.
+ */
+static uintptr_t
+dtrace_dif_varstrz(uintptr_t addr, size_t strsz, dtrace_state_t *state,
+ dtrace_mstate_t *mstate)
+{
+ char *p;
+ size_t i;
+ uintptr_t ret;
+
+ if (mstate->dtms_scratch_ptr + strsz >
+ mstate->dtms_scratch_base + mstate->dtms_scratch_size) {
+ DTRACE_CPUFLAG_SET(CPU_DTRACE_NOSCRATCH);
+ return (0);
+ }
+
+ dtrace_bcopy((const void *)addr, (void *)mstate->dtms_scratch_ptr,
+ strsz);
+
+ /* Replace sub-string termination characters with a space. */
+ for (p = (char *) mstate->dtms_scratch_ptr, i = 0; i < strsz - 1;
+ p++, i++)
+ if (*p == '\0')
+ *p = ' ';
+
+ ret = mstate->dtms_scratch_ptr;
+ mstate->dtms_scratch_ptr += strsz;
+ return (ret);
+}
+
+/*
* This function implements the DIF emulator's variable lookups. The emulator
* passes a reserved variable identifier and optional built-in array index.
*/
@@ -2843,6 +2881,13 @@
return ((uint64_t)curthread->t_tid);
+ case DIF_VAR_EXECARGS: {
+ struct pargs *p_args = curthread->td_proc->p_args;
+
+ return (dtrace_dif_varstrz(
+ (uintptr_t) p_args->ar_args, p_args->ar_length, state, mstate));
+ }
+
case DIF_VAR_EXECNAME:
#if defined(sun)
if (!dtrace_priv_proc(state))
@@ -8455,6 +8500,7 @@
if (v == DIF_VAR_CURTHREAD || v == DIF_VAR_PID ||
v == DIF_VAR_PPID || v == DIF_VAR_TID ||
+ v == DIF_VAR_EXECARGS ||
v == DIF_VAR_EXECNAME || v == DIF_VAR_ZONENAME ||
v == DIF_VAR_UID || v == DIF_VAR_GID)
break;
@@ -8534,6 +8580,7 @@
case DIF_VAR_CURTHREAD:
case DIF_VAR_PID:
case DIF_VAR_TID:
+ case DIF_VAR_EXECARGS:
case DIF_VAR_EXECNAME:
case DIF_VAR_ZONENAME:
break;
==== //depot/projects/dtrace/src/sys/contrib/opensolaris/uts/common/sys/dtrace.h#29 (text) ====
@@ -249,6 +249,7 @@
#define DIF_VAR_UID 0x011e /* process user ID */
#define DIF_VAR_GID 0x011f /* process group ID */
#define DIF_VAR_ERRNO 0x0120 /* thread errno */
+#define DIF_VAR_EXECARGS 0x0121 /* process arguments */
#define DIF_SUBR_RAND 0
#define DIF_SUBR_MUTEX_OWNED 1
More information about the p4-projects
mailing list