From owner-p4-projects@FreeBSD.ORG Tue Jan 22 01:52:46 2008 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id F3DFE16A41A; Tue, 22 Jan 2008 01:52:45 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id A0CD816A417 for ; Tue, 22 Jan 2008 01:52:45 +0000 (UTC) (envelope-from jb@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 8374113C458 for ; Tue, 22 Jan 2008 01:52:45 +0000 (UTC) (envelope-from jb@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.1/8.14.1) with ESMTP id m0M1qjWl047263 for ; Tue, 22 Jan 2008 01:52:45 GMT (envelope-from jb@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.1/8.14.1/Submit) id m0M1qjCK047260 for perforce@freebsd.org; Tue, 22 Jan 2008 01:52:45 GMT (envelope-from jb@freebsd.org) Date: Tue, 22 Jan 2008 01:52:45 GMT Message-Id: <200801220152.m0M1qjCK047260@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to jb@freebsd.org using -f From: John Birrell To: Perforce Change Reviews Cc: Subject: PERFORCE change 133839 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 22 Jan 2008 01:52:46 -0000 http://perforce.freebsd.org/chv.cgi?CH=133839 Change 133839 by jb@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 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