dtrace.c revision 902686d13f8a39cfdc57f5605470369eafa51e1f
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright (c) 2013, Joyent, Inc. All rights reserved.
* Copyright (c) 2012 by Delphix. All rights reserved.
*/
/*
* DTrace - Dynamic Tracing for Solaris
*
* This is the implementation of the Solaris Dynamic Tracing framework
* (DTrace). The user-visible interface to DTrace is described at length in
* the "Solaris Dynamic Tracing Guide". The interfaces between the libdtrace
* library, the in-kernel DTrace framework, and the DTrace providers are
* internal architecture of DTrace is described in the block comments in the
* <sys/dtrace_impl.h> header file. The comments contained within the DTrace
* implementation very much assume mastery of all of these sources; if one has
* an unanswered question about the implementation, one should consult them
* first.
*
* The functions here are ordered roughly as follows:
*
* - Probe context functions
* - Probe hashing functions
* - Non-probe context utility functions
* - Matching functions
* - Provider-to-Framework API functions
* - Probe management functions
* - DIF object functions
* - Format functions
* - Predicate functions
* - ECB functions
* - Buffer functions
* - Enabling functions
* - DOF functions
* - Anonymous enabling functions
* - Consumer state functions
* - Helper functions
* - Hook functions
* - Driver cookbook functions
*
* Each group of functions begins with a block comment labelled the "DTrace
* [Group] Functions", allowing one to find each block by searching forward
* on capital-f functions.
*/
#include <sys/sysmacros.h>
#include <sys/dtrace_impl.h>
#include <sys/mutex_impl.h>
#include <sys/rwlock_impl.h>
#include <sys/priv_impl.h>
#include <sys/cred_impl.h>
#include <sys/procfs_isa.h>
#include "strtolctype.h"
/*
* DTrace Tunable Variables
*
* includes both the name of the DTrace module ("dtrace") and the name of the
* variable. For example:
*
* set dtrace:dtrace_destructive_disallow = 1
*
* In general, the only variables that one should be tuning this way are those
* that affect system-wide DTrace behavior, and for which the default behavior
* is undesirable. Most of these variables are tunable on a per-consumer
* basis using DTrace options, and need not be tuned on a system-wide basis.
* When tuning these variables, avoid pathological values; while some attempt
* is made to verify the integrity of these variables, they are not considered
* part of the supported interface to DTrace, and they are therefore not
* checked comprehensively. Further, these variables should not be tuned
* dynamically via "mdb -kw" or other means; they should only be tuned via
*/
int dtrace_destructive_disallow = 0;
int dtrace_msgdsize_max = 128;
int dtrace_devdepth_max = 32;
int dtrace_err_verbose;
/*
* DTrace External Variables
*
* As dtrace(7D) is a kernel module, any DTrace variables are obviously
* available to DTrace consumers via the backtick (`) syntax. One of these,
* dtrace_zero, is made deliberately so: it is provided as a source of
* well-known, zero-filled memory. While this variable is not documented,
* it is used by some translators as an implementation detail.
*/
/*
* DTrace Internal Variables
*/
static int dtrace_nprobes; /* number of probes */
static int dtrace_opens; /* number of opens */
static int dtrace_helpers; /* number of helpers */
static int dtrace_getf; /* number of unpriv getf()s */
static void *dtrace_softstate; /* softstate pointer */
static int dtrace_toxranges; /* number of toxic ranges */
static int dtrace_toxranges_max; /* size of toxic range array */
static int dtrace_dynvar_failclean; /* dynvars failed to clean */
/*
* DTrace Locking
* DTrace is protected by three (relatively coarse-grained) locks:
*
* (1) dtrace_lock is required to manipulate essentially any DTrace state,
* including enabling state, probes, ECBs, consumer state, helper state,
* etc. Importantly, dtrace_lock is _not_ required when in probe context;
* probe context is lock-free -- synchronization is handled via the
* dtrace_sync() cross call mechanism.
*
* (2) dtrace_provider_lock is required when manipulating provider state, or
* when provider state must be held constant.
*
* (3) dtrace_meta_lock is required when manipulating meta provider state, or
* when meta provider state must be held constant.
*
* The lock ordering between these three locks is dtrace_meta_lock before
* dtrace_provider_lock before dtrace_lock. (In particular, there are
* several places where dtrace_provider_lock is held by the framework as it
* calls into the providers -- which then call back into the framework,
* grabbing dtrace_lock.)
*
* There are two other locks in the mix: mod_lock and cpu_lock. With respect
* to dtrace_provider_lock and dtrace_lock, cpu_lock continues its historical
* role as a coarse-grained lock; it is acquired before both of these locks.
* With respect to dtrace_meta_lock, its behavior is stranger: cpu_lock must
* be acquired _between_ dtrace_meta_lock and any other DTrace locks.
* mod_lock is similar with respect to dtrace_provider_lock in that it must be
* acquired _between_ dtrace_provider_lock and dtrace_lock.
*/
/*
* DTrace Provider Variables
*
* These are the variables relating to DTrace as a provider (that is, the
* provider of the BEGIN, END, and ERROR probes).
*/
static dtrace_pattr_t dtrace_provider_attr = {
};
static void
dtrace_nullop(void)
{}
static int
dtrace_enable_nullop(void)
{
return (0);
}
static dtrace_pops_t dtrace_provider_ops = {
(void (*)(void *, const dtrace_probedesc_t *))dtrace_nullop,
(void (*)(void *, struct modctl *))dtrace_nullop,
(int (*)(void *, dtrace_id_t, void *))dtrace_enable_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,
NULL,
NULL,
NULL,
(void (*)(void *, dtrace_id_t, void *))dtrace_nullop
};
/*
* DTrace Helper Tracing Variables
*
* These variables should be set dynamically to enable helper tracing. The
* only variables that should be set are dtrace_helptrace_enable (which should
* be set to a non-zero value to allocate helper tracing buffers on the next
* non-zero value to deallocate helper tracing buffers on the next close of
* buffer size may also be set via dtrace_helptrace_bufsize.
*/
int dtrace_helptrace_enable = 0;
int dtrace_helptrace_disable = 0;
static uint32_t dtrace_helptrace_next = 0;
static int dtrace_helptrace_wrapped = 0;
/*
* DTrace Error Hashing
*
* On DEBUG kernels, DTrace will track the errors that has seen in a hash
* table. This is very useful for checking coverage of tests that are
* expected to induce DIF or DOF processing errors, and may be useful for
* debugging problems in the DIF code generator or in DOF generation . The
* error hash may be examined with the ::dtrace_errhash MDB dcmd.
*/
#ifdef DEBUG
static const char *dtrace_errlast;
static kthread_t *dtrace_errthread;
static kmutex_t dtrace_errlock;
#endif
/*
* DTrace Macros and Constants
*
* These are various macros that are useful in various spots in the
* implementation, along with a few random constants that have no meaning
* outside of the implementation. There is no real structure to this cpp
* mishmash -- but is there ever?
*/
#define DTRACE_AGGHASHSIZE_SLEW 17
/*
* The key for a thread-local variable consists of the lower 61 bits of the
* t_did, plus the 3 bits of the highest active interrupt above LOCK_LEVEL.
* We add DIF_VARIABLE_MAX to t_did to assure that the thread key is never
* equal to a variable identifier. This is necessary (but not sufficient) to
* assure that global associative arrays never collide with thread-local
* variables. To guarantee that they cannot collide, we must also define the
* order for keying dynamic variables. That order is:
*
* [ key0 ] ... [ keyn ] [ variable-key ] [ tls-key ]
*
* Because the variable-key and the tls-key are in orthogonal spaces, there is
* no way for a global variable key signature to match a thread-local key
* signature.
*/
#define DTRACE_TLS_THRKEY(where) { \
intr++; \
}
#define DT_BSWAP_8(x) ((x) & 0xff)
#define DT_MASK_LO 0x00000000FFFFFFFFULL
#ifndef __x86
*flags |= CPU_DTRACE_BADALIGN; \
return (0); \
}
#else
#endif
/*
* Test whether a range of memory starting at testaddr of size testsz falls
* within the range of memory described by addr, sz. We take care to avoid
* problems with overflow and underflow of the unsigned quantities, and
* disallow all negative sizes. Ranges of size 0 are allowed.
*/
/*
* Test whether alloc_sz bytes will fit in the scratch region. We isolate
* alloc_sz on the righthand side of the comparison in order to avoid overflow
* or underflow in the comparison with it. This is simpler than the INRANGE
* check above, because we know that the dtms_scratch_ptr is valid in the
* range. Allocations of size zero are allowed.
*/
#define DTRACE_LOADFUNC(bits) \
/*CSTYLED*/ \
{ \
/*CSTYLED*/ \
int i; \
\
\
for (i = 0; i < dtrace_toxranges; i++) { \
continue; \
\
continue; \
\
/* \
* This address falls within a toxic region; return 0. \
*/ \
*flags |= CPU_DTRACE_BADADDR; \
return (0); \
} \
\
*flags |= CPU_DTRACE_NOFAULT; \
/*CSTYLED*/ \
*flags &= ~CPU_DTRACE_NOFAULT; \
\
}
#ifdef _LP64
#define dtrace_loadptr dtrace_load64
#else
#define dtrace_loadptr dtrace_load32
#endif
#define DTRACE_DYNHASH_FREE 0
#define DTRACE_DYNHASH_SINK 1
#define DTRACE_DYNHASH_VALID 2
#define DTRACE_MATCH_FAIL -1
#define DTRACE_MATCH_NEXT 0
#define DTRACE_MATCH_DONE 1
#define DTRACE_STATE_ALIGN 64
#define DTRACE_FLAGS2FLT(flags) \
#define DTRACEACT_ISSTRING(act) \
static void dtrace_enabling_provide(dtrace_provider_t *);
static int dtrace_enabling_match(dtrace_enabling_t *, int *);
static void dtrace_enabling_matchall(void);
static void dtrace_enabling_reap(void);
static dtrace_state_t *dtrace_anon_grab(void);
static void dtrace_buffer_drop(dtrace_buffer_t *);
dtrace_state_t *, dtrace_mstate_t *);
static int dtrace_ecb_create_enable(dtrace_probe_t *, void *);
static void dtrace_helper_provider_destroy(dtrace_helper_provider_t *);
static void dtrace_getf_barrier(void);
/*
* DTrace Probe Context Functions
*
* These functions are called from probe context. Because probe context is
* any context in which C may be called, arbitrarily locks may be held,
* interrupts may be disabled, we may be in arbitrary dispatched state, etc.
* As a result, functions called from probe context may only call other DTrace
* support functions -- they may not interact at all with the system at large.
* (Note that the ASSERT macro is made probe-context safe by redefining it in
* terms of dtrace_assfail(), a probe-context safe function.) If arbitrary
* loads are to be performed from probe context, they _must_ be in terms of
* the safe dtrace_load*() variants.
*
* Some functions in this block are not actually called from probe context;
* for these functions, there will be a comment above the function reading
* "Note: not called from probe context."
*/
void
dtrace_panic(const char *format, ...)
{
}
int
dtrace_assfail(const char *a, const char *f, int l)
{
dtrace_panic("assertion failed: %s, file: %s, line: %d", a, f, l);
/*
* We just need something here that even the most clever compiler
* cannot optimize away.
*/
return (a[(uintptr_t)f]);
}
/*
* Atomically increment a specified error counter from probe context.
*/
static void
{
/*
* Most counters stored to in probe context are per-CPU counters.
* However, there are some error conditions that are sufficiently
* arcane that they don't merit per-CPU storage. If these counters
* are incremented concurrently on different CPUs, scalability will be
* adversely affected -- but we don't expect them to be white-hot in a
* correctly constructed enabling...
*/
do {
/*
* If the counter would wrap, set it to 1 -- assuring
* that the counter is never zero when we have seen
* errors. (The counter must be 32-bits because we
* aren't guaranteed a 64-bit compare&swap operation.)
* To save this code both the infamy of being fingered
* by a priggish news story and the indignity of being
* the target of a neo-puritan witch trial, we're
* carefully avoiding any colorful description of the
* likelihood of this condition -- but suffice it to
* say that it is only slightly more likely than the
* overflow of predicate cache IDs, as discussed in
* dtrace_predicate_create().
*/
nval = 1;
}
}
/*
* Use the DTRACE_LOADFUNC macro to define functions for each of loading a
* uint8_t, a uint16_t, a uint32_t and a uint64_t.
*/
DTRACE_LOADFUNC(16)
DTRACE_LOADFUNC(32)
DTRACE_LOADFUNC(64)
static int
{
return (0);
return (0);
return (0);
return (1);
}
static int
{
int i;
for (i = 0; i < nsvars; i++) {
continue;
return (1);
}
return (0);
}
/*
* Check to see if the address is within a memory region to which a store may
* be issued. This includes the DTrace scratch areas, and any DTrace variable
* region. The caller of dtrace_canstore() is responsible for performing any
* alignment checks that are needed before stores are actually executed.
*/
static int
{
/*
* First, check to see if the address is in scratch space...
*/
return (1);
/*
* Now check to see if it's a dynamic variable. This check will pick
* up both thread-local variables and any global dynamically-allocated
* variables.
*/
/*
* Before we assume that we can store here, we need to make
* sure that it isn't in our metadata -- storing to our
* dynamic variable metadata would corrupt our state. For
* the range to not include any dynamic variable metadata,
* it must:
*
* (1) Start above the hash table that is at the base of
* the dynamic variable space
*
* (2) Have a starting chunk offset that is beyond the
* dtrace_dynvar_t that is at the base of every chunk
*
* (3) Not span a chunk boundary
*
*/
return (0);
if (chunkoffs < sizeof (dtrace_dynvar_t))
return (0);
return (0);
return (1);
}
/*
* Finally, check the static local and global variables. These checks
* take the longest, so we perform them last.
*/
return (1);
return (1);
return (0);
}
/*
* Convenience routine to check to see if the address is within a memory
* region in which a load may be issued given the user's privilege level;
* if not, it sets the appropriate error flags and loads 'addr' into the
* illegal value slot.
*
* DTrace subroutines (DIF_SUBR_*) should use this helper to implement
* appropriate memory access protection.
*/
static int
{
/*
* If we hold the privilege to read from kernel memory, then
* everything is readable.
*/
return (1);
/*
* You can obviously read that which you can store.
*/
return (1);
/*
* We're allowed to read from our own string table.
*/
return (1);
proc_t *p;
/*
* When we have privileges to the current process, there are
* several context-related kernel structures that are safe to
* read, even absent the privilege to read from kernel memory.
* These reads are safe because these structures contain only
* state that (1) we're permitted to read, (2) is harmless or
* (3) contains pointers to additional kernel state that we're
* not permitted to read (and as such, do not present an
* opportunity for privilege escalation). Finally (and
* critically), because of the nature of their relation with
* the current thread context, the memory associated with these
* structures cannot change over the duration of probe context,
* and it is therefore impossible for this memory to be
* deallocated and reallocated as something else while it's
* being operated upon.
*/
return (1);
return (1);
}
return (1);
}
return (1);
}
return (1);
}
}
vnodeops_t *op;
/*
* When getf() returns a file_t, the enabling is implicitly
* granted the (transient) right to read the returned file_t
* as well as the v_path and v_op->vnop_name of the underlying
* vnode. These accesses are allowed after a successful
* getf() because the members that they refer to cannot change
* once set -- and the barrier logic in the kernel's closef()
* path assures that the file_t and its referenced vode_t
* cannot themselves be stale (that is, it impossible for
* either dtms_getf itself or its f_vnode member to reference
* freed memory).
*/
return (1);
return (1);
return (1);
}
return (1);
return (1);
}
return (1);
}
}
}
return (0);
}
/*
* Convenience routine to check to see if a given string is within a memory
* region in which a load may be issued given the user's privilege level;
* this exists so that we don't need to issue unnecessary dtrace_strlen()
* calls in the event that the user has all privileges.
*/
static int
{
/*
* If we hold the privilege to read from kernel memory, then
* everything is readable.
*/
return (1);
return (1);
return (0);
}
/*
* Convenience routine to check to see if a given variable is within a memory
* region in which a load may be issued given the user's privilege level.
*/
static int
{
/*
* If we hold the privilege to read from kernel memory, then
* everything is readable.
*/
return (1);
else
}
/*
* Convert a string to a signed integer using safe loads.
*
* NOTE: This function uses various macros from strtolctype.h to manipulate
* digit values, etc -- these have all been checked to ensure they make
* no additional function calls.
*/
static int64_t
{
int x;
/*
* Consume any whitespace preceding digits.
*/
pos++;
/*
* Handle an explicit sign if one is present.
*/
if (c == '-' || c == '+') {
if (c == '-')
c = dtrace_load8(++pos);
}
/*
* Check for an explicit hexadecimal prefix ("0x" or "0X") and skip it
* if present.
*/
pos += 2;
c = ccc;
}
/*
* Read in contiguous digits until the first non-digit character.
*/
c = dtrace_load8(++pos))
}
/*
* Compare two strings using safe loads.
*/
static int
{
return (0);
do {
c1 = '\0';
} else {
}
c2 = '\0';
} else {
}
return (0);
}
/*
* Compute strlen(s) for a string using safe memory accesses. The additional
* len parameter is used to specify a maximum length to ensure completion.
*/
static size_t
{
break;
}
return (len);
}
/*
* Check if an address falls within a toxic region.
*/
static int
{
int i;
for (i = 0; i < dtrace_toxranges; i++) {
return (1);
}
return (1);
}
}
return (0);
}
/*
* Copy src to dst using safe memory accesses. The src is assumed to be unsafe
* memory specified by the DIF program. The dst is assumed to be safe memory
* that we can store to directly because it is managed by DTrace. As with
* standard bcopy, overlapping copies are handled properly.
*/
static void
{
if (len != 0) {
do {
} while (--len != 0);
} else {
do {
} while (--len != 0);
}
}
}
/*
* Copy src to dst using safe memory accesses, up to either the specified
* length, or the point that a nul byte is encountered. The src is assumed to
* be unsafe memory specified by the DIF program. The dst is assumed to be
* safe memory that we can store to directly because it is managed by DTrace.
* Unlike dtrace_bcopy(), overlapping regions are not handled.
*/
static void
{
if (len != 0) {
do {
} while (--len != 0 && c != '\0');
}
}
/*
* Copy src to dst, deriving the size and type from the specified (BYREF)
* variable type. The src is assumed to be unsafe memory specified by the DIF
* program. The dst is assumed to be DTrace variable memory that is of the
* specified type; we assume that we can store to directly.
*/
static void
{
} else {
}
}
/*
* Compare s1 to s2 using safe memory accesses. The s1 data is assumed to be
* unsafe memory specified by the DIF program. The s2 data is assumed to be
* safe memory that we can access directly because it is managed by DTrace.
*/
static int
{
return (0);
return (1);
do {
return (1);
}
return (0);
}
/*
* Zero the specified region using a simple byte-by-byte loop. Note that this
* is for safe DTrace-managed memory only.
*/
static void
{
*cp++ = 0;
}
static void
{
}
/*
* Shift the 128-bit value in a by b. If b is positive, shift left.
* If b is negative, shift right.
*/
static void
dtrace_shift_128(uint64_t *a, int b)
{
if (b == 0)
return;
if (b < 0) {
b = -b;
if (b >= 64) {
a[0] = a[1] >> (b - 64);
a[1] = 0;
} else {
a[0] >>= b;
mask -= 1;
a[1] >>= b;
}
} else {
if (b >= 64) {
a[1] = a[0] << (b - 64);
a[0] = 0;
} else {
a[1] <<= b;
mask = a[0] >> (64 - b);
a[1] |= mask;
a[0] <<= b;
}
}
}
/*
* The basic idea is to break the 2 64-bit values into 4 32-bit values,
* use native multiplication on those, and then re-combine into the
* resulting 128-bit value.
*
* (hi1 << 32 + lo1) * (hi2 << 32 + lo2) =
* hi1 * hi2 << 64 +
* hi1 * lo2 << 32 +
* hi2 * lo1 << 32 +
* lo1 * lo2
*/
static void
{
tmp[1] = 0;
tmp[1] = 0;
}
/*
* This privilege check should be used by actions and subroutines to
* verify that the user credentials of the process that enabled the
* invoking ECB match the target credentials
*/
static int
{
/*
* We should always have a non-NULL state cred here, since if cred
* is null (anonymous tracing), we fast-path bypass this routine.
*/
return (1);
return (0);
}
/*
* This privilege check should be used by actions and subroutines to
* verify that the zone of the process that enabled the invoking ECB
* matches the target credentials
*/
static int
{
/*
* We should always have a non-NULL state cred here, since if cred
* is null (anonymous tracing), we fast-path bypass this routine.
*/
return (1);
return (0);
}
/*
* This privilege check should be used by actions and subroutines to
* verify that the process has not setuid or changed credentials.
*/
static int
{
return (1);
return (0);
}
static int
{
goto bad;
if (((action & DTRACE_CRA_PROC_DESTRUCTIVE_ALLZONE) == 0) &&
goto bad;
if (((action & DTRACE_CRA_PROC_DESTRUCTIVE_ALLUSER) == 0) &&
goto bad;
if (((action & DTRACE_CRA_PROC_DESTRUCTIVE_CREDCHG) == 0) &&
dtrace_priv_proc_common_nocd() == 0)
goto bad;
return (1);
bad:
return (0);
}
static int
{
return (1);
if (dtrace_priv_proc_common_zone(state) &&
return (1);
}
return (0);
}
static int
{
return (1);
return (0);
}
static int
{
return (1);
return (0);
}
static int
{
return (1);
return (0);
}
/*
* Determine if the dte_cond of the specified ECB allows for processing of
* the current probe to continue. Note that this routine may allow continued
* processing, but with access(es) stripped from the mstate's dtms_access
* field.
*/
static int
{
int mode = DTRACE_MODE_NOPRIV_DROP;
}
/*
* If the dte_cond bits indicate that this consumer is only allowed to
* see user-mode firings of this probe, check that the probe was fired
* while in a user context. If that's not the case, use the policy
* specified by the provider to determine if we drop the probe or
* merely restrict operation.
*/
if (!(mode & DTRACE_MODE_USER)) {
if (mode & DTRACE_MODE_NOPRIV_DROP)
return (0);
}
}
/*
* This is more subtle than it looks. We have to be absolutely certain
* that CRED() isn't going to change out from under us so it's only
* legit to examine that structure if we're in constrained situations.
* Currently, the only times we'll this check is if a non-super-user
* has enabled the profile or syscall providers -- providers that
* allow visibility of all processes. For the profile case, the check
* above will ensure that we're examining a user context.
*/
if (mode & DTRACE_MODE_NOPRIV_DROP)
return (0);
}
}
/*
* If our dte_cond is set to DTRACE_COND_ZONEOWNER and we are not
* in our zone, check to see if our mode policy is to restrict rather
* than to drop; if to restrict, strip away both DTRACE_ACCESS_PROC
* and DTRACE_ACCESS_ARGS
*/
if (mode & DTRACE_MODE_NOPRIV_DROP)
return (0);
mstate->dtms_access &=
}
}
/*
* By merits of being in this code path at all, we have limited
* privileges. If the provider has indicated that limited privileges
* are to denote restricted operation, strip off the ability to access
* arguments.
*/
return (1);
}
/*
* Note: not called from probe context. This function is called
* asynchronously (and at a regular interval) from outside of probe context to
* clean the dirty dynamic variable lists on all CPUs. Dynamic variable
* cleaning is explained in detail in <sys/dtrace_impl.h>.
*/
void
{
int i, j, work = 0;
for (i = 0; i < NCPU; i++) {
/*
* If the dirty list is NULL, there is no dirty work to do.
*/
continue;
/*
* If the rinsing list is non-NULL, then it is because
* this CPU was selected to accept another CPU's
* dirty list -- and since that time, dirty buffers
* have accumulated. This is a highly unlikely
* condition, but we choose to ignore the dirty
* buffers -- they'll be picked up a future cleanse.
*/
continue;
}
/*
* If the clean list is non-NULL, then we're in a
* situation where a CPU has done deallocations (we
* have a non-NULL dirty list) but no allocations (we
* also have a non-NULL clean list). We can't simply
* move the dirty list into the clean list on this
* CPU, yet we also don't want to allow this condition
* to persist, lest a short clean list prevent a
* massive dirty list from being cleaned (which in
* turn could lead to otherwise avoidable dynamic
* drops). To deal with this, we look for some CPU
* with a NULL clean list, NULL dirty list, and NULL
* rinsing list -- and then we borrow this CPU to
* rinse our dirty list.
*/
for (j = 0; j < NCPU; j++) {
continue;
continue;
continue;
break;
}
if (j == NCPU) {
/*
* We were unable to find another CPU that
* could accept this dirty list -- we are
* therefore unable to clean it now.
*/
continue;
}
}
work = 1;
/*
* Atomically move the dirty list aside.
*/
do {
/*
* Before we zap the dirty list, set the rinsing list.
* (This allows for a potential assertion in
* dtrace_dynvar(): if a free dynamic variable appears
* on a hash chain, either the dirty list or the
* rinsing list for some CPU must be non-NULL.)
*/
}
if (!work) {
/*
* We have no work to do; we can simply return.
*/
return;
}
dtrace_sync();
for (i = 0; i < NCPU; i++) {
continue;
/*
* We are now guaranteed that no hash chain contains a pointer
* into this dirty list; we can make it clean.
*/
}
/*
* Before we actually set the state to be DTRACE_DSTATE_CLEAN, make
* sure that all CPUs have seen all of the dtdsc_clean pointers.
* This prevents a race whereby a CPU incorrectly decides that
* the state should be something other than DTRACE_DSTATE_CLEAN
* after dtrace_dynvar_clean() has completed.
*/
dtrace_sync();
}
/*
* Depending on the value of the op parameter, this function looks-up,
* allocates or deallocates an arbitrarily-keyed dynamic variable. If an
* allocation is requested, this function will return a pointer to a
* dtrace_dynvar_t corresponding to the allocated variable -- or NULL if no
* variable can be allocated. If NULL is returned, the appropriate counter
* will be incremented.
*/
{
uint_t i;
/*
* Hash the key. As with aggregations, we use Jenkins' "One-at-a-time"
* algorithm. For the by-value portions, we perform the algorithm in
* 16-bit chunks (as opposed to 8-bit chunks). This speeds things up a
* bit, and seems to have only a minute effect on distribution. For
* the by-reference data, we perform "One-at-a-time" iterating (safely)
* over each referenced byte. It's painful to do this, but it's much
* better than pathological hash distribution. The efficacy of the
* hashing algorithm (and a comparison with other algorithms) may be
* found by running the ::dtrace_dynstat MDB dcmd.
*/
for (i = 0; i < nkeys; i++) {
} else {
/*
* This is incredibly painful, but it beats the hell
* out of the alternative.
*/
break;
for (j = 0; j < size; j++) {
}
}
}
return (NULL);
/*
* There is a remote chance (ideally, 1 in 2^31) that our hashval
* comes out to be one of our two sentinel hash values. If this
* actually happens, we set the hashval to be a value known to be a
* non-sentinel value.
*/
/*
* Yes, it's painful to do a divide here. If the cycle count becomes
* important here, tricks can be pulled to reduce it. (However, it's
* critical that hash collisions be kept to an absolute minimum;
* they're much more painful than a divide.) It's better to have a
* solution that generates few collisions and still keeps things
* relatively simple.
*/
if (op == DTRACE_DYNVAR_DEALLOC) {
for (;;) {
continue;
if (dtrace_casptr((void *)lockp,
break;
}
}
top:
op != DTRACE_DYNVAR_DEALLOC));
/*
* We've reached the sink, and therefore the
* end of the hash chain; we can kick out of
* the loop knowing that we have seen a valid
* snapshot of state.
*/
break;
}
/*
* We've gone off the rails: somewhere along
* the line, one of the members of this hash
* chain was deleted. Note that we could also
* detect this by simply letting this loop run
* to completion, as we would eventually hit
* the end of the dirty list. However, we
* want to avoid running the length of the
* dirty list unnecessarily (it might be quite
* long), so we catch this as early as
* possible by detecting the hash marker. In
* this case, we simply set dvar to NULL and
* break; the conditional after the loop will
* send us back to top.
*/
break;
}
goto next;
}
goto next;
goto next; /* size or type mismatch */
if (dtrace_bcmp(
goto next;
} else {
goto next;
}
}
if (op != DTRACE_DYNVAR_DEALLOC)
return (dvar);
} else {
/*
* We have failed to atomically swing the
* hash table head pointer, presumably because
* of a conflicting allocation on another CPU.
* We need to reread the hash chain and try
* again.
*/
goto top;
}
}
/*
* Now set the hash value to indicate that it's free.
*/
/*
* Set the next pointer to point at the dirty list, and
* atomically swing the dirty pointer to the newly freed dvar.
*/
do {
/*
* Finally, unlock this hash bucket.
*/
return (NULL);
next:
continue;
}
/*
* If dvar is NULL, it is because we went off the rails:
* one of the elements that we traversed in the hash chain
* was deleted while we were traversing it. In this case,
* we assert that we aren't doing a dealloc (deallocs lock
* the hash bucket to prevent themselves from racing with
* one another), and retry the hash chain traversal.
*/
goto top;
}
if (op != DTRACE_DYNVAR_ALLOC) {
/*
* If we are not to allocate a new variable, we want to
* return NULL now. Before we return, check that the value
* of the lock word hasn't changed. If it has, we may have
* seen an inconsistent snapshot.
*/
if (op == DTRACE_DYNVAR_NOALLOC) {
goto top;
} else {
}
return (NULL);
}
/*
* We need to allocate a new dynamic variable. The size we need is the
* size of dtrace_dynvar plus the size of nkeys dtrace_key_t's plus the
* size of any auxiliary key data (rounded up to 8-byte alignment) plus
* the size of any referred-to data (dsize). We then round the final
* size up to the chunksize for allocation.
*/
/*
* This should be pretty much impossible, but could happen if, say,
* strange DIF specified the tuple. Ideally, this should be an
* assertion and not an error condition -- but that requires that the
* chunksize calculation in dtrace_difo_chunksize() be absolutely
* bullet-proof. (That is, it must not be able to be fooled by
* malicious DIF.) Given the lack of backwards branches in DIF,
* solving this would presumably not amount to solving the Halting
* Problem -- but it still seems awfully hard.
*/
dcpu->dtdsc_drops++;
return (NULL);
}
do {
void *rval;
/*
* We're out of dynamic variable space on
* this CPU. Unless we have tried all CPUs,
* we'll try to allocate from a different
* CPU.
*/
switch (dstate->dtds_state) {
case DTRACE_DSTATE_CLEAN: {
cpu = 0;
goto retry;
(void) dtrace_cas32(sp,
/*
* To increment the correct bean
* counter, take another lap.
*/
goto retry;
}
case DTRACE_DSTATE_DIRTY:
break;
case DTRACE_DSTATE_RINSING:
break;
case DTRACE_DSTATE_EMPTY:
dcpu->dtdsc_drops++;
break;
}
return (NULL);
}
/*
* The clean list appears to be non-empty. We want to
* move the clean list to the free list; we start by
* moving the clean pointer aside.
*/
/*
* We are in one of two situations:
*
* (a) The clean list was switched to the
* free list by another CPU.
*
* (b) The clean list was added to by the
* cleansing cyclic.
*
* In either of these situations, we can
* just reattempt the free list allocation.
*/
goto retry;
}
/*
* Now we'll move the clean list to our free list.
* It's impossible for this to fail: the only way
* the free list can be updated is through this
* code path, and only one CPU can own the clean list.
* Thus, it would only be possible for this to fail if
* this code were racing with dtrace_dynvar_clean().
* (That is, if dtrace_dynvar_clean() updated the clean
* list, and we ended up racing to update the free
* list.) This race is prevented by the dtrace_sync()
* in dtrace_dynvar_clean() -- which flushes the
* owners of the clean lists out before resetting
* the clean lists.
*/
goto retry;
}
/*
* We have now allocated a new chunk. We copy the tuple keys into the
* tuple array and copy any referenced key data into the data space
* following the tuple array. As we do this, we relocate dttk_value
* in the final tuple to point to the key data address in the chunk.
*/
for (i = 0; i < nkeys; i++) {
if (kesize != 0) {
} else {
}
}
return (dvar);
/*
* The cas has failed. Either another CPU is adding an element to
* this hash chain, or another CPU is deleting an element from this
* hash chain. The simplest way to deal with both of these cases
* (though not necessarily the most efficient) is to free our
* allocated block and tail-call ourselves. Note that the free is
* to the dirty list and _not_ to the free list. This is to prevent
* races with allocators, above.
*/
do {
}
/*ARGSUSED*/
static void
{
}
/*ARGSUSED*/
static void
{
}
static void
{
int i, zero = DTRACE_QUANTIZE_ZEROBUCKET;
if (val < 0) {
for (i = 0; i < zero; i++) {
if (val <= DTRACE_QUANTIZE_BUCKETVAL(i)) {
return;
}
}
} else {
if (val < DTRACE_QUANTIZE_BUCKETVAL(i)) {
return;
}
}
return;
}
ASSERT(0);
}
static void
{
/*
* This is an underflow.
*/
return;
}
return;
}
/*
* This is an overflow.
*/
}
static int
{
/*
* If our value is less than our factor taken to the power of the
* low order of magnitude, it goes into the zeroth bucket.
*/
return (0);
/*
* with a high magnitude that allows 64-bits to
* overflow, but we nonetheless protect against this
* by explicitly checking for overflow, and clamping
* our value accordingly.
*/
}
/*
* If our value lies within this order of magnitude,
* determine its position by taking the offset within
* the order of magnitude, dividing by the bucket
* width, and adding to our (accumulated) base.
*/
}
}
/*
* Our value is greater than or equal to our factor taken to the
* power of one plus the high magnitude -- return the top bucket.
*/
return (base);
}
static void
{
}
/*ARGSUSED*/
static void
{
data[0]++;
}
/*ARGSUSED*/
static void
{
data[0]++;
/*
* What we want to say here is:
*
* data[2] += nval * nval;
*
* But given that nval is 64-bit, we could easily overflow, so
* we do this as 128-bit arithmetic.
*/
if (snval < 0)
}
/*ARGSUSED*/
static void
{
}
/*ARGSUSED*/
static void
{
}
/*
* Aggregate given the tuple in the principal data buffer, and the aggregating
* action denoted by the specified dtrace_aggregation_t. The aggregation
* buffer is specified as the buf parameter. This routine does not return
* failure; if there is no space in the aggregation buffer, the data will be
* dropped, and a corresponding counter incremented.
*/
static void
{
return;
if (!agg->dtag_hasarg) {
/*
* Currently, only quantize() and lquantize() take additional
* arguments, and they have the same semantics: an increment
* value that defaults to 1 when not present. If additional
* aggregating actions take arguments, the setting of the
* default argument value will presumably have to become more
* sophisticated...
*/
arg = 1;
}
return;
}
/*
* The metastructure is always at the bottom of the buffer.
*/
sizeof (dtrace_aggbuffer_t));
if (buf->dtb_offset == 0) {
/*
* We just kludge up approximately 1/8th of the size to be
* buckets. If this guess ends up being routinely
* off-the-mark, we may need to dynamically readjust this
* based on past performance.
*/
/*
* We've been given a ludicrously small buffer;
* increment our drop count and leave.
*/
return;
}
/*
* And now, a pathetic attempt to try to get a an odd (or
* perchance, a prime) hash size for better hash distribution.
*/
for (i = 0; i < agb->dtagb_hashsize; i++)
}
/*
* Calculate the hash value based on the key. Note that we _don't_
* include the aggid in the hashing (but we will store it as part of
* the key). The hashing algorithm is Bob Jenkins' "One-at-a-time"
* algorithm: a simple, quick algorithm that has no known funnels, and
* gets good distribution in practice. The efficacy of the hashing
* algorithm (and a comparison with other algorithms) may be found by
* running the ::dtrace_aggstat MDB dcmd.
*/
for (; i < limit; i++) {
break;
}
}
/*
* Yes, the divide here is expensive -- but it's generally the least
* of the performance issues given the amount of data that we iterate
* over to compute hash values, compare data, etc.
*/
continue;
for (; i < limit; i++) {
goto next;
break;
}
}
/*
* We are aggregating on the same value in the same
* aggregation with two different aggregating actions.
* (This should have been picked up in the compiler,
* so we may be dealing with errant or devious DIF.)
* This is an error condition; we indicate as much,
* and return.
*/
return;
}
/*
* This is a hit: we need to apply the aggregator to
* the value at this key.
*/
return;
next:
continue;
}
/*
* We didn't find it. We need to allocate some zero-filled space,
* link it into the hash table appropriately, and apply the aggregator
* to the (zero-filled) value.
*/
/*
* If we don't have enough room to both allocate a new key _and_
* its associated data, increment the drop count and return.
*/
return;
}
/*CONSTCOND*/
/*
* Now copy the data across.
*/
for (i = sizeof (dtrace_aggid_t); i < size; i++)
/*
* Because strings are not zeroed out by default, we need to iterate
* looking for actions that store strings, and we need to explicitly
* pad these strings out with zeroes.
*/
int nul;
if (!DTRACEACT_ISSTRING(act))
continue;
if (nul) {
kdata[i] = '\0';
continue;
}
if (data[i] != '\0')
continue;
nul = 1;
}
}
kdata[i] = 0;
/*
* Finally, apply the aggregator.
*/
}
/*
* Given consumer state, this routine finds a speculation in the INACTIVE
* state and transitions it into the ACTIVE state. If there is no speculation
* in the INACTIVE state, 0 is returned. In this case, no error counter is
* incremented -- it is up to the caller to take appropriate action.
*/
static int
{
int i = 0;
while (i < state->dts_nspeculations) {
if (current != DTRACESPEC_INACTIVE) {
if (current == DTRACESPEC_COMMITTINGMANY ||
current == DTRACESPEC_COMMITTING ||
i++;
continue;
}
return (i + 1);
}
/*
* We couldn't find a speculation. If we found as much as a single
* busy speculation buffer, we'll attribute this failure as "busy"
* instead of "unavail".
*/
do {
return (0);
}
/*
* This routine commits an active speculation. If the specified speculation
* is not in a valid state to perform a commit(), this routine will silently do
* nothing. The state of the specified speculation is transitioned according
* to the state transition diagram outlined in <sys/dtrace_impl.h>
*/
static void
{
if (which == 0)
return;
return;
}
do {
if (current == DTRACESPEC_COMMITTINGMANY)
break;
switch (current) {
case DTRACESPEC_INACTIVE:
case DTRACESPEC_DISCARDING:
return;
case DTRACESPEC_COMMITTING:
/*
* This is only possible if we are (a) commit()'ing
* without having done a prior speculate() on this CPU
* and (b) racing with another commit() on a different
* CPU. There's nothing to do -- we just assert that
* our offset is 0.
*/
return;
case DTRACESPEC_ACTIVE:
break;
case DTRACESPEC_ACTIVEONE:
/*
* This speculation is active on one CPU. If our
* buffer offset is non-zero, we know that the one CPU
* must be us. Otherwise, we are committing on a
* different CPU from the speculate(), and we must
* rely on being asynchronously cleaned.
*/
if (src->dtb_offset != 0) {
break;
}
/*FALLTHROUGH*/
case DTRACESPEC_ACTIVEMANY:
break;
default:
ASSERT(0);
}
/*
* We have set the state to indicate that we are committing this
* speculation. Now reserve the necessary space in the destination
* buffer.
*/
goto out;
}
/*
* We have sufficient space to copy the speculative buffer into the
* primary buffer. First, modify the speculative buffer, filling
* in the timestamp of all entries with the current time. The data
* must have the commit() time rather than the time it was traced,
* so that all entries in the primary buffer are in timestamp order.
*/
saddr += sizeof (dtrace_epid_t);
continue;
}
}
/*
* Copy the buffer across. (Note that this is a
* highly subobtimal bcopy(); in the unlikely event that this becomes
* a serious performance issue, a high-performance DTrace-specific
* bcopy() should obviously be invented.)
*/
/*
* First, the aligned portion.
*/
}
/*
* Now any left-over bit...
*/
/*
* Finally, commit the reserved space in the destination buffer.
*/
out:
/*
* If we're lucky enough to be the only active CPU on this speculation
* buffer, we can just set the state back to DTRACESPEC_INACTIVE.
*/
if (current == DTRACESPEC_ACTIVE ||
}
src->dtb_offset = 0;
}
/*
* This routine discards an active speculation. If the specified speculation
* is not in a valid state to perform a discard(), this routine will silently
* do nothing. The state of the specified speculation is transitioned
* according to the state transition diagram outlined in <sys/dtrace_impl.h>
*/
static void
{
if (which == 0)
return;
return;
}
do {
switch (current) {
case DTRACESPEC_INACTIVE:
case DTRACESPEC_COMMITTING:
case DTRACESPEC_DISCARDING:
return;
case DTRACESPEC_ACTIVE:
case DTRACESPEC_ACTIVEMANY:
break;
case DTRACESPEC_ACTIVEONE:
if (buf->dtb_offset != 0) {
} else {
}
break;
default:
ASSERT(0);
}
buf->dtb_offset = 0;
}
/*
* Note: not called from probe context. This function is called
* asynchronously from cross call context to clean any speculations that are
* in the COMMITTINGMANY or DISCARDING states. These speculations may not be
* transitioned back to the INACTIVE state until all CPUs have cleaned the
* speculation.
*/
static void
{
return;
}
for (i = 0; i < state->dts_nspeculations; i++) {
continue;
src->dtb_offset = 0;
continue;
}
continue;
if (src->dtb_offset == 0)
continue;
}
}
/*
* Note: not called from probe context. This function is called
* asynchronously (and at a regular interval) to clean any speculations that
* are in the COMMITTINGMANY or DISCARDING states. If it discovers that there
* is work to be done, it cross calls all CPUs to perform that work;
* COMMITMANY and DISCARDING speculations may not be transitioned back to the
* INACTIVE state until they have been cleaned by all CPUs.
*/
static void
{
for (i = 0; i < state->dts_nspeculations; i++) {
continue;
work++;
}
if (!work)
return;
/*
* We now know that all CPUs have committed or discarded their
* speculation buffers, as appropriate. We can now set the state
* to inactive.
*/
for (i = 0; i < state->dts_nspeculations; i++) {
if (!spec->dtsp_cleaning)
continue;
spec->dtsp_cleaning = 0;
}
}
/*
* Called as part of a speculate() to get the speculative buffer associated
* with a given speculation. Returns NULL if the specified speculation is not
* in an ACTIVE state. If the speculation is in the ACTIVEONE state -- and
* the active CPU is not the specified CPU -- the speculation will be
* atomically transitioned into the ACTIVEMANY state.
*/
static dtrace_buffer_t *
{
if (which == 0)
return (NULL);
return (NULL);
}
do {
switch (current) {
case DTRACESPEC_INACTIVE:
case DTRACESPEC_DISCARDING:
return (NULL);
case DTRACESPEC_COMMITTING:
return (NULL);
case DTRACESPEC_ACTIVEONE:
/*
* This speculation is currently active on one CPU.
* Check the offset in the buffer; if it's non-zero,
* that CPU must be us (and we leave the state alone).
* If it's zero, assume that we're starting on a new
* CPU -- and change the state to indicate that the
* speculation is active on more than one CPU.
*/
if (buf->dtb_offset != 0)
return (buf);
break;
case DTRACESPEC_ACTIVEMANY:
return (buf);
case DTRACESPEC_ACTIVE:
break;
default:
ASSERT(0);
}
return (buf);
}
/*
* Return a string. 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 'execname' and 'probefunc.'
*/
{
/*
* The easy case: this probe is allowed to read all of memory, so
* we can just return this as a vanilla pointer.
*/
return (addr);
/*
* This is the tougher case: we copy the string in question from
* kernel memory into scratch memory and return it that way: this
* ensures that we won't trip up when access checking tests the
* BYREF return value.
*/
return (NULL);
}
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.
*/
static uint64_t
{
/*
* If we're accessing one of the uncached arguments, we'll turn this
* into a reference in the args array.
*/
if (v >= DIF_VAR_ARG0 && v <= DIF_VAR_ARG9) {
ndx = v - DIF_VAR_ARG0;
v = DIF_VAR_ARGS;
}
switch (v) {
case DIF_VAR_ARGS:
return (0);
}
else
/*
* This is regrettably required to keep the compiler
* from tail-optimizing the call to dtrace_getarg().
* The condition always evaluates to true, but the
* compiler has no way of figuring that out a priori.
* (None of this would be necessary if the compiler
* could be relied upon to _always_ tail-optimize
* the call to dtrace_getarg() -- but it can't.)
*/
return (val);
ASSERT(0);
}
case DIF_VAR_UREGS: {
return (0);
return (0);
}
}
case DIF_VAR_VMREGS: {
if (!dtrace_priv_kernel(state))
return (0);
return (rval);
}
case DIF_VAR_CURTHREAD:
return (0);
case DIF_VAR_TIMESTAMP:
}
return (mstate->dtms_timestamp);
case DIF_VAR_VTIMESTAMP:
ASSERT(dtrace_vtime_references != 0);
return (curthread->t_dtrace_vtime);
case DIF_VAR_WALLTIMESTAMP:
}
return (mstate->dtms_walltimestamp);
case DIF_VAR_IPL:
if (!dtrace_priv_kernel(state))
return (0);
}
case DIF_VAR_EPID:
case DIF_VAR_ID:
case DIF_VAR_STACKDEPTH:
if (!dtrace_priv_kernel(state))
return (0);
}
return (mstate->dtms_stackdepth);
case DIF_VAR_USTACKDEPTH:
return (0);
/*
* See comment in DIF_VAR_PID.
*/
CPU_ON_INTR(CPU)) {
mstate->dtms_ustackdepth = 0;
} else {
}
}
return (mstate->dtms_ustackdepth);
case DIF_VAR_CALLER:
if (!dtrace_priv_kernel(state))
return (0);
/*
* If this is an unanchored probe, we are
* required to go through the slow path:
* dtrace_caller() only guarantees correct
* results for anchored probes.
*/
} else if ((mstate->dtms_caller =
/*
* We have failed to do this the quick way;
* we must resort to the slower approach of
* calling dtrace_getpcstack().
*/
}
}
return (mstate->dtms_caller);
case DIF_VAR_UCALLER:
return (0);
/*
* dtrace_getupcstack() fills in the first uint64_t
* with the current PID. The second uint64_t will
* be the program counter at user-level. The third
* uint64_t will contain the caller, which is what
* we're after.
*/
}
return (mstate->dtms_ucaller);
case DIF_VAR_PROBEPROV:
return (dtrace_dif_varstr(
case DIF_VAR_PROBEMOD:
return (dtrace_dif_varstr(
case DIF_VAR_PROBEFUNC:
return (dtrace_dif_varstr(
case DIF_VAR_PROBENAME:
return (dtrace_dif_varstr(
case DIF_VAR_PID:
return (0);
/*
* Note that we are assuming that an unanchored probe is
* always due to a high-level interrupt. (And we're assuming
* that there is only a single high level interrupt.)
*/
/*
* It is always safe to dereference one's own t_procp pointer:
* it always points to a valid, allocated proc structure.
* Further, it is always safe to dereference the p_pidp member
* of one's own proc structure. (These are truisms becuase
* threads and processes don't clean up their own state --
* they leave that task to whomever reaps them.)
*/
case DIF_VAR_PPID:
return (0);
/*
* See comment in DIF_VAR_PID.
*/
/*
* It is always safe to dereference one's own t_procp pointer:
* it always points to a valid, allocated proc structure.
* (This is true because threads don't clean up their own
* state -- they leave that task to whomever reaps them.)
*/
case DIF_VAR_TID:
/*
* See comment in DIF_VAR_PID.
*/
return (0);
case DIF_VAR_EXECNAME:
return (0);
/*
* See comment in DIF_VAR_PID.
*/
/*
* It is always safe to dereference one's own t_procp pointer:
* it always points to a valid, allocated proc structure.
* (This is true because threads don't clean up their own
* state -- they leave that task to whomever reaps them.)
*/
return (dtrace_dif_varstr(
case DIF_VAR_ZONENAME:
return (0);
/*
* See comment in DIF_VAR_PID.
*/
/*
* It is always safe to dereference one's own t_procp pointer:
* it always points to a valid, allocated proc structure.
* (This is true because threads don't clean up their own
* state -- they leave that task to whomever reaps them.)
*/
return (dtrace_dif_varstr(
case DIF_VAR_UID:
return (0);
/*
* See comment in DIF_VAR_PID.
*/
/*
* It is always safe to dereference one's own t_procp pointer:
* it always points to a valid, allocated proc structure.
* (This is true because threads don't clean up their own
* state -- they leave that task to whomever reaps them.)
*
* Additionally, it is safe to dereference one's own process
* credential, since this is never NULL after process birth.
*/
case DIF_VAR_GID:
return (0);
/*
* See comment in DIF_VAR_PID.
*/
/*
* It is always safe to dereference one's own t_procp pointer:
* it always points to a valid, allocated proc structure.
* (This is true because threads don't clean up their own
* state -- they leave that task to whomever reaps them.)
*
* Additionally, it is safe to dereference one's own process
* credential, since this is never NULL after process birth.
*/
case DIF_VAR_ERRNO: {
return (0);
/*
* See comment in DIF_VAR_PID.
*/
return (0);
/*
* It is always safe to dereference one's own t_lwp pointer in
* the event that this pointer is non-NULL. (This is true
* because threads and lwps don't clean up their own state --
* they leave that task to whomever reaps them.)
*/
return (0);
}
default:
return (0);
}
}
typedef enum dtrace_json_state {
DTRACE_JSON_REST = 1,
/*
* This function possesses just enough knowledge about JSON to extract a single
* value from a JSON string and store it in the scratch buffer. It is able
* to extract nested object values, and members of arrays by index.
*
* elemlist is a list of JSON keys, stored as packed NUL-terminated strings, to
* be looked up as we descend into the object tree. e.g.
*
* foo[0].bar.baz[32] --> "foo" NUL "0" NUL "bar" NUL "baz" NUL "32" NUL
* with nelems = 5.
*
* The run time of this function must be bounded above by strsize to limit the
* amount of work done in probe context. As such, it is implemented as a
* simple state machine, reading one character at a time using safe loads
* until we find the requested element, hit a parsing error or run off the
* end of the object or string.
*
* As there is no way for a subroutine to return an error without interrupting
* clause execution, we simply return NULL in the event of a missing key or any
* other error condition. Each NULL return in this function is commented with
* the error condition it represents -- parsing or otherwise.
*
* The set of states for the state machine closely matches the JSON
* specification (http://json.org/). Briefly:
*
* DTRACE_JSON_REST:
* Skip whitespace until we find either a top-level Object, moving
* to DTRACE_JSON_OBJECT; or an Array, moving to DTRACE_JSON_VALUE.
*
* DTRACE_JSON_OBJECT:
* Locate the next key String in an Object. Sets a flag to denote
* the next String as a key string and moves to DTRACE_JSON_STRING.
*
* DTRACE_JSON_COLON:
* Skip whitespace until we find the colon that separates key Strings
* from their values. Once found, move to DTRACE_JSON_VALUE.
*
* DTRACE_JSON_VALUE:
* Detects the type of the next value (String, Number, Identifier, Object
* or Array) and routes to the states that process that type. Here we also
* deal with the element selector list if we are requested to traverse down
* into the object tree.
*
* DTRACE_JSON_COMMA:
* Skip whitespace until we find the comma that separates key-value pairs
* in Objects (returning to DTRACE_JSON_OBJECT) or values in Arrays
* (similarly DTRACE_JSON_VALUE). All following literal value processing
* states return to this state at the end of their value, unless otherwise
* noted.
*
* DTRACE_JSON_NUMBER, DTRACE_JSON_NUMBER_FRAC, DTRACE_JSON_NUMBER_EXP:
* Processes a Number literal from the JSON, including any exponent
* component that may be present. Numbers are returned as strings, which
* may be passed to strtoll() if an integer is required.
*
* DTRACE_JSON_IDENTIFIER:
* Processes a "true", "false" or "null" literal in the JSON.
*
* DTRACE_JSON_STRING, DTRACE_JSON_STRING_ESCAPE,
* DTRACE_JSON_STRING_ESCAPE_UNICODE:
* Processes a String literal from the JSON, whether the String denotes
* a key, a value or part of a larger Object. Handles all escape sequences
* present in the specification, including four-digit unicode characters,
* but merely includes the escape sequence without converting it to the
* actual escaped character. If the String is flagged as a key, we
* move to DTRACE_JSON_COLON rather than DTRACE_JSON_COMMA.
*
* DTRACE_JSON_COLLECT_OBJECT:
* This state collects an entire Object (or Array), correctly handling
* embedded strings. If the full element selector list matches this nested
* object, we return the Object in full as a string. If not, we use this
* state to skip to the next value at this level and continue processing.
*
* NOTE: This function uses various macros from strtolctype.h to manipulate
* digit values, etc -- these have all been checked to ensure they make
* no additional function calls.
*/
static char *
char *dest)
{
uint8_t escape_unicount = 0;
if (cc == '\0')
return (NULL);
switch (state) {
case DTRACE_JSON_REST:
break;
if (cc == '{') {
break;
}
if (cc == '[') {
array_pos = 0;
break;
}
/*
* ERROR: expected to find a top-level object or array.
*/
return (NULL);
case DTRACE_JSON_OBJECT:
break;
if (cc == '"') {
break;
}
/*
* ERROR: either the object did not start with a key
* string, or we've run off the end of the object
* without finding the requested key.
*/
return (NULL);
case DTRACE_JSON_STRING:
if (cc == '\\') {
*dd++ = '\\';
break;
}
if (cc == '"') {
if (collect_object) {
/*
* We don't reset the dest here, as
* the string is part of a larger
* object being collected.
*/
break;
}
*dd = '\0';
if (string_is_key) {
size) == 0)
} else if (found_key) {
if (nelems > 1) {
/*
* We expected an object, not
* this string.
*/
return (NULL);
}
return (dest);
}
break;
}
break;
if (cc == 'u') {
escape_unicount = 0;
} else {
}
break;
/*
* ERROR: invalid unicode escape, expected
* four valid hexidecimal digits.
*/
return (NULL);
}
if (++escape_unicount == 4)
break;
case DTRACE_JSON_COLON:
break;
if (cc == ':') {
break;
}
/*
* ERROR: expected a colon.
*/
return (NULL);
case DTRACE_JSON_COMMA:
break;
if (cc == ',') {
if (in_array) {
if (++array_pos == array_elem)
} else {
}
break;
}
/*
* ERROR: either we hit an unexpected character, or
* we reached the end of the object or array without
* finding the requested key.
*/
return (NULL);
case DTRACE_JSON_IDENTIFIER:
break;
}
*dd = '\0';
if (found_key) {
if (nelems > 1) {
/*
* ERROR: We expected an object,
* not this identifier.
*/
return (NULL);
}
return (dest);
} else {
cur--;
break;
}
}
/*
* ERROR: we did not recognise the identifier as one
* of those in the JSON specification.
*/
return (NULL);
case DTRACE_JSON_NUMBER:
if (cc == '.') {
break;
}
/*
* ERROR: specification explicitly excludes
* hexidecimal or octal numbers.
*/
return (NULL);
}
/* FALLTHRU */
case DTRACE_JSON_NUMBER_FRAC:
break;
}
/*
* ERROR: expect sign as part of exponent only.
*/
return (NULL);
}
/* FALLTHRU */
case DTRACE_JSON_NUMBER_EXP:
break;
}
*dd = '\0';
if (found_key) {
if (nelems > 1) {
/*
* ERROR: We expected an object, not
* this number.
*/
return (NULL);
}
return (dest);
}
cur--;
break;
case DTRACE_JSON_VALUE:
break;
/*
* If our element selector directs us
* to descend into this nested object,
* then move to the next selector
* element in the list and restart the
* state machine.
*/
while (*elem != '\0')
elem++;
elem++; /* skip the inter-element NUL */
nelems--;
if (in_array) {
array_pos = 0;
found_key = array_elem == 0 ?
} else {
}
break;
}
/*
* Otherwise, we wish to either skip this
* nested object or return it in full.
*/
if (cc == '[')
brackets = 1;
else
braces = 1;
break;
}
if (cc == '"') {
break;
}
/*
* Here we deal with true, false and null.
*/
break;
}
break;
}
/*
* ERROR: unexpected character at start of value.
*/
return (NULL);
if (cc == '\0')
/*
* ERROR: unexpected end of input.
*/
return (NULL);
if (cc == '"') {
break;
}
if (cc == ']') {
if (brackets-- == 0) {
/*
* ERROR: unbalanced brackets.
*/
return (NULL);
}
} else if (cc == '}') {
if (braces-- == 0) {
/*
* ERROR: unbalanced braces.
*/
return (NULL);
}
} else if (cc == '{') {
braces++;
} else if (cc == '[') {
brackets++;
}
if (found_key) {
*dd = '\0';
return (dest);
}
}
break;
}
}
return (NULL);
}
/*
* Emulate the execution of DTrace ID subroutines invoked by the call opcode.
* Notice that we don't bother validating the proper number of arguments or
* their types in the tuple stack. This isn't needed because all argument
* interpretation is safe because of our load safety -- the worst that can
* happen is that a bogus program can obtain bogus results.
*/
static void
{
union {
} m;
union {
} r;
switch (subr) {
case DIF_SUBR_RAND:
break;
case DIF_SUBR_MUTEX_OWNED:
break;
}
if (MUTEX_TYPE_ADAPTIVE(&m.mi))
else
break;
case DIF_SUBR_MUTEX_OWNER:
break;
}
if (MUTEX_TYPE_ADAPTIVE(&m.mi) &&
else
break;
break;
}
break;
case DIF_SUBR_MUTEX_TYPE_SPIN:
break;
}
break;
case DIF_SUBR_RW_READ_HELD: {
break;
}
break;
}
case DIF_SUBR_RW_WRITE_HELD:
break;
}
break;
case DIF_SUBR_RW_ISWRITER:
break;
}
break;
case DIF_SUBR_BCOPY: {
/*
* We need to be sure that the destination is in the scratch
* region -- no other region is allowed.
*/
*flags |= CPU_DTRACE_BADADDR;
break;
}
break;
}
break;
}
case DIF_SUBR_ALLOCA:
case DIF_SUBR_COPYIN: {
/*
* This action doesn't require any credential checks since
* probes will not activate in user contexts to which the
* enabling user does not have permissions.
*/
/*
* Rounding up the user allocation size could have overflowed
* a large, bogus allocation (like -1ULL) to 0.
*/
if (scratch_size < size ||
break;
}
if (subr == DIF_SUBR_COPYIN) {
}
break;
}
case DIF_SUBR_COPYINTO: {
/*
* This action doesn't require any credential checks since
* probes will not activate in user contexts to which the
* enabling user does not have permissions.
*/
*flags |= CPU_DTRACE_BADADDR;
break;
}
break;
}
case DIF_SUBR_COPYINSTR: {
/*
* This action doesn't require any credential checks since
* probes will not activate in user contexts to which the
* enabling user does not have permissions.
*/
break;
}
break;
}
case DIF_SUBR_MSGSIZE:
case DIF_SUBR_MSGDSIZE: {
int cont = 0;
vstate)) {
break;
}
*flags |= CPU_DTRACE_BADADDR;
break;
}
/*
* We want to prevent against denial-of-service here,
* so we're only going to search the list for
* dtrace_msgdsize_max mblks.
*/
if (cont++ > dtrace_msgdsize_max) {
*flags |= CPU_DTRACE_ILLOP;
break;
}
if (subr == DIF_SUBR_MSGDSIZE) {
if (dtrace_load8(daddr +
continue;
}
}
if (!(*flags & CPU_DTRACE_FAULT))
break;
}
case DIF_SUBR_PROGENYOF: {
proc_t *p;
int rval = 0;
rval = 1;
break;
}
}
break;
}
case DIF_SUBR_SPECULATION:
break;
case DIF_SUBR_COPYOUT: {
if (!dtrace_destructive_disallow &&
}
break;
}
case DIF_SUBR_COPYOUTSTR: {
if (!dtrace_destructive_disallow &&
}
break;
}
case DIF_SUBR_STRLEN: {
break;
}
break;
}
case DIF_SUBR_STRCHR:
case DIF_SUBR_STRRCHR: {
/*
* We're going to iterate over the string looking for the
* specified character. We will iterate until we have reached
* the string length or we have found the character. If this
* is DIF_SUBR_STRRCHR, we will look for the last occurrence
* of the specified character instead of the first.
*/
if (subr == DIF_SUBR_STRCHR)
break;
}
if (c == '\0')
break;
}
break;
}
break;
}
case DIF_SUBR_STRSTR:
case DIF_SUBR_INDEX:
case DIF_SUBR_RINDEX: {
/*
* We're going to iterate over the string looking for the
* specified string. We will iterate until we have reached
* the string length or we have found the string. (Yes, this
* is done in the most naive way possible -- but considering
* that the string we're searching for is likely to be
* relatively short, the complexity of Rabin-Karp or similar
* hardly seems merited.)
*/
int inc = 1;
break;
}
vstate)) {
break;
}
/*
* strstr() and index()/rindex() have similar semantics if
* both strings are the empty string: strstr() returns a
* pointer to the (empty) string, and index() and rindex()
* both return index 0 (regardless of any position argument).
*/
if (subr == DIF_SUBR_STRSTR)
else
break;
}
if (subr != DIF_SUBR_STRSTR) {
if (subr == DIF_SUBR_RINDEX) {
inc = -1;
}
/*
* Both index() and rindex() take an optional position
* argument that denotes the starting position.
*/
if (nargs == 3) {
/*
* If the position argument to index() is
* negative, Perl implicitly clamps it at
* zero. This semantic is a little surprising
* given the special meaning of negative
* positions to similar Perl functions like
* substr(), but it appears to reflect a
* notion that index() can start from a
* negative index and increment its way up to
* the string. Given this notion, Perl's
* rindex() is at least self-consistent in
* that it implicitly clamps positions greater
* than the string length to be the string
* length. Where Perl completely loses
* coherence, however, is when the specified
* substring is the empty string (""). In
* this case, even if the position is
* negative, rindex() returns 0 -- and even if
* the position is greater than the length,
* index() returns the string length. These
* semantics violate the notion that index()
* should never return a value less than the
* specified position and that rindex() should
* never return a value greater than the
* specified position. (One assumes that
* these semantics are artifacts of Perl's
* implementation and not the results of
* deliberate design -- it beggars belief that
* even Larry Wall could desire such oddness.)
* While in the abstract one would wish for
* consistent position semantics across
* substr(), index() and rindex() -- or at the
* very least self-consistent position
* semantics for index() and rindex() -- we
* instead opt to keep with the extant Perl
* semantics, in all their broken glory. (Do
* we have more desire to maintain Perl's
* semantics than Perl does? Probably.)
*/
if (subr == DIF_SUBR_RINDEX) {
if (pos < 0) {
if (sublen == 0)
break;
}
} else {
if (pos < 0)
pos = 0;
if (sublen == 0)
break;
}
}
}
}
if (subr != DIF_SUBR_STRSTR) {
/*
* As D index() and rindex() are
* modeled on Perl (and not on awk),
* we return a zero-based (and not a
* one-based) index. (For you Perl
* weenies: no, we're not going to add
* $[ -- and shouldn't you be at a con
* or something?)
*/
break;
}
break;
}
}
break;
}
case DIF_SUBR_STRTOK: {
int i;
/*
* Check both the token buffer and (later) the input buffer,
* since both could be non-scratch addresses.
*/
break;
}
break;
}
/*
* If the address specified is NULL, we use our saved
* strtok pointer from the mstate. Note that this
* means that the saved strtok pointer is _only_
* valid within multiple enablings of the same probe --
* it behaves like an implicit clause-local variable.
*/
} else {
/*
* If the user-specified address is non-NULL we must
* access check it. This is the only time we have
* a chance to do so, since this address may reside
* in the string table of this clause-- future calls
* (when we fetch addr from mstate->dtms_strtok)
* would fail this access check.
*/
break;
}
}
/*
* First, zero the token map, and then process the token
* string -- setting a bit in the map for every character
* found in the token string.
*/
for (i = 0; i < sizeof (tokmap); i++)
tokmap[i] = 0;
break;
}
/*
* We're looking for a character that is _not_ contained
* in the token string.
*/
break;
break;
}
if (c == '\0') {
/*
* We reached the end of the string without finding
* any character that was not in the token string.
* We return NULL in this case, and we set the saved
* address to NULL as well.
*/
break;
}
/*
* From here on, we're copying into the destination string.
*/
break;
break;
dest[i++] = c;
}
dest[i] = '\0';
break;
}
case DIF_SUBR_SUBSTR: {
char *d = (char *)mstate->dtms_scratch_ptr;
int64_t i;
break;
}
break;
}
if (nargs <= 2)
if (index < 0) {
index = 0;
}
}
remaining = 0;
} else if (remaining < 0) {
}
for (i = 0; i < remaining; i++) {
break;
}
d[i] = '\0';
break;
}
case DIF_SUBR_JSON: {
int nelems = 1;
break;
}
break;
}
/*
* Read the element selector and split it up into a packed list
* of strings.
*/
/*
* If the first element selector key is
* actually an array index then ignore the
* bracket.
*/
continue;
}
if (cc == ']')
continue;
nelems++;
cc = '\0';
}
}
*ee++ = '\0';
break;
}
case DIF_SUBR_TOUPPER:
case DIF_SUBR_TOLOWER: {
int64_t i;
if (subr == DIF_SUBR_TOUPPER) {
lower = 'a';
upper = 'z';
convert = 'A';
} else {
lower = 'A';
upper = 'Z';
convert = 'a';
}
break;
}
break;
}
for (i = 0; i < size - 1; i++) {
if ((c = dtrace_load8(s + i)) == '\0')
break;
dest[i] = c;
}
dest[i] = '\0';
break;
}
case DIF_SUBR_GETMAJOR:
#ifdef _LP64
#else
#endif
break;
case DIF_SUBR_GETMINOR:
#ifdef _LP64
#else
#endif
break;
case DIF_SUBR_DDI_PATHNAME: {
/*
* This one is a galactic mess. We are going to roughly
* emulate ddi_pathname(), but it's made more complicated
* by the fact that we (a) want to include the minor name and
* (b) must proceed iteratively instead of recursively.
*/
char *s;
/*
* Due to all the pointer jumping we do and context we must
* rely upon, we just mandate that the user must have kernel
* read privileges to use this routine.
*/
*flags |= CPU_DTRACE_KPRIV;
}
break;
}
*end = '\0';
/*
* We want to have a name for the minor. In order to do this,
* we need to walk the minor list from the devinfo. We want
* to be sure that we don't infinitely walk a circular list,
* so we check for circularity by sending a scout pointer
* ahead two elements for every element that we iterate over;
* if the list is circular, these will ultimately point to the
* same element. You may recognize this little trick as the
* answer to a stupid interview question -- one that always
* seems to be asked by those who had to have it laboriously
* explained to them, and who can't even concisely describe
* the conditions under which one would be forced to resort to
* this technique. Needless to say, those conditions are
* found here -- and probably only here. Is this the only use
* of this infamous trick in shipping, production code? If it
* isn't, it probably should be...
*/
if (minor != -1) {
uint64_t m;
#ifdef _LP64
#else
#endif
if (m != minor) {
continue;
continue;
continue;
*flags |= CPU_DTRACE_ILLOP;
break;
}
continue;
}
/*
* We have the minor data. Now we need to
* copy the minor's name into the end of the
* pathname.
*/
if (*flags & CPU_DTRACE_FAULT)
break;
if (len != 0) {
break;
*end = ':';
}
for (i = 1; i <= len; i++)
break;
}
}
if (*flags & CPU_DTRACE_FAULT)
break;
if (devi_state >= DS_INITIALIZED) {
s = (char *)dtrace_loadptr(daddr +
if (*flags & CPU_DTRACE_FAULT)
break;
if (len != 0) {
break;
*end = '@';
}
for (i = 1; i <= len; i++)
}
/*
* Now for the node name...
*/
s = (char *)dtrace_loadptr(daddr +
/*
* If our parent is NULL (that is, if we're the root
* node), we're going to use the special path
* "devices".
*/
s = "devices";
if (*flags & CPU_DTRACE_FAULT)
break;
break;
for (i = 1; i <= len; i++)
*end = '/';
if (depth++ > dtrace_devdepth_max) {
*flags |= CPU_DTRACE_ILLOP;
break;
}
}
}
break;
}
case DIF_SUBR_STRJOIN: {
char *d = (char *)mstate->dtms_scratch_ptr;
int i = 0;
break;
}
break;
}
for (;;) {
if (i >= size) {
break;
}
i--;
break;
}
}
for (;;) {
if (i >= size) {
break;
}
break;
}
if (i < size) {
mstate->dtms_scratch_ptr += i;
}
break;
}
case DIF_SUBR_STRTOLL: {
int base = 10;
if (nargs > 1) {
*flags |= CPU_DTRACE_ILLOP;
break;
}
}
break;
}
break;
}
case DIF_SUBR_LLTOSTR: {
int base = 10;
if (nargs > 1) {
*flags |= CPU_DTRACE_ILLOP;
break;
}
}
break;
}
} else {
}
}
if (i == 0 && base == 16)
*end-- = '0';
if (base == 16)
*end-- = 'x';
*end-- = '0';
if (i < 0 && base == 10)
*end-- = '-';
break;
}
case DIF_SUBR_HTONS:
case DIF_SUBR_NTOHS:
#ifdef _BIG_ENDIAN
#else
#endif
break;
case DIF_SUBR_HTONL:
case DIF_SUBR_NTOHL:
#ifdef _BIG_ENDIAN
#else
#endif
break;
case DIF_SUBR_HTONLL:
case DIF_SUBR_NTOHLL:
#ifdef _BIG_ENDIAN
#else
#endif
break;
case DIF_SUBR_DIRNAME:
case DIF_SUBR_BASENAME: {
break;
}
break;
}
/*
* The basename and dirname for a zero-length string is
* defined to be "."
*/
if (len == 0) {
len = 1;
}
/*
* Start from the back of the string, moving back toward the
* front until we see a character that isn't a slash. That
* character is the last character in the basename.
*/
for (i = len - 1; i >= 0; i--) {
break;
}
if (i >= 0)
lastbase = i;
/*
* Starting from the last character in the basename, move
* towards the front until we find a slash. The character
* that we processed immediately before that is the first
* character in the basename.
*/
for (; i >= 0; i--) {
break;
}
if (i >= 0)
firstbase = i + 1;
/*
* Now keep going until we find a non-slash character. That
* character is the last character in the dirname.
*/
for (; i >= 0; i--) {
break;
}
if (i >= 0)
lastdir = i;
if (lastbase == -1) {
/*
* We didn't find a non-slash character. We know that
* the length is non-zero, so the whole string must be
* slashes. In either the dirname or the basename
* case, we return '/'.
*/
}
if (firstbase == -1) {
/*
* The entire string consists only of a basename
* component. If we're looking for dirname, we need
* to change our string to be just "."; if we're
* looking for a basename, we'll just set the first
* character of the basename to be 0.
*/
if (subr == DIF_SUBR_DIRNAME) {
lastdir = 0;
} else {
firstbase = 0;
}
}
if (subr == DIF_SUBR_DIRNAME) {
if (lastdir == -1) {
/*
* We know that we have a slash in the name --
* or lastdir would be set to 0, above. And
* because lastdir is -1, we know that this
* slash must be the first character. (That
* is, the full string must be of the form
* "/basename".) In this case, the last
* character of the directory name is 0.
*/
lastdir = 0;
}
start = 0;
} else {
}
dest[j] = '\0';
break;
}
case DIF_SUBR_GETF: {
break;
}
/*
* This is safe because fi_nfiles only increases, and the
* fi_list array is not freed when the array size doubles.
* (See the comment in flist_grow() for details on the
* management of the u_finfo structure.)
*/
break;
}
case DIF_SUBR_CLEANPATH: {
int i = 0, j = 0;
zone_t *z;
break;
}
break;
}
/*
* Move forward, loading each character.
*/
do {
c = dtrace_load8(src + i++);
next:
break;
if (c != '/') {
dest[j++] = c;
continue;
}
c = dtrace_load8(src + i++);
if (c == '/') {
/*
* We have two slashes -- we can just advance
* to the next character.
*/
goto next;
}
if (c != '.') {
/*
* This is not "." and it's not ".." -- we can
* just store the "/" and this character and
* drive on.
*/
dest[j++] = '/';
dest[j++] = c;
continue;
}
c = dtrace_load8(src + i++);
if (c == '/') {
/*
* This is a "/./" component. We're not going
* to store anything in the destination buffer;
* we're just going to go to the next component.
*/
goto next;
}
if (c != '.') {
/*
* This is not ".." -- we can just store the
* "/." and this character and continue
* processing.
*/
dest[j++] = '/';
dest[j++] = '.';
dest[j++] = c;
continue;
}
c = dtrace_load8(src + i++);
if (c != '/' && c != '\0') {
/*
* This is not ".." -- it's "..[mumble]".
* We'll store the "/.." and this character
* and continue processing.
*/
dest[j++] = '/';
dest[j++] = '.';
dest[j++] = '.';
dest[j++] = c;
continue;
}
/*
* This is "/../" or "/..\0". We need to back up
* our destination pointer until we find a "/".
*/
i--;
while (j != 0 && dest[--j] != '/')
continue;
if (c == '\0')
dest[++j] = '/';
} while (c != '\0');
dest[j] = '\0';
/*
* If we've done a getf() as a part of this ECB and we
* don't have kernel access (and we're not in the global
* zone), check if the path we cleaned up begins with
* the zone's root path, and trim it off if so. Note
* that this is an output cleanliness issue, not a
* security issue: knowing one's zone root path does
* not enable privilege escalation.
*/
}
break;
}
case DIF_SUBR_INET_NTOA:
case DIF_SUBR_INET_NTOA6:
case DIF_SUBR_INET_NTOP: {
if (subr == DIF_SUBR_INET_NTOP) {
argi = 1;
} else {
argi = 0;
}
/*
* Safely load the IPv4 address.
*/
/*
* Check an IPv4 string will fit in scratch.
*/
break;
}
/*
* Stringify as a dotted decimal quad.
*/
*end-- = '\0';
for (i = 3; i >= 0; i--) {
if (val == 0) {
*end-- = '0';
} else {
}
}
if (i > 0)
*end-- = '.';
}
const char digits[] = "0123456789abcdef";
/*
* Stringify using RFC 1884 convention 2 - 16 bit
* hexadecimal values with a zero-run compression.
* Lower case hexadecimal digits are used.
* eg, fe80::214:4fff:fe0b:76c8.
* The IPv4 embedded form is returned for inet_ntop,
* just the IPv4 string is returned for inet_ntoa6.
*/
/*
* Safely load the IPv6 address.
*/
/*
* Check an IPv6 string will fit in scratch.
*/
break;
}
*end-- = '\0';
/*
* Find the longest run of 16 bit zero values
* for the single allowed zero compression - "::".
*/
firstzero = -1;
tryzero = -1;
numzero = 1;
for (i = 0; i < sizeof (struct in6_addr); i++) {
tryzero = i;
continue;
}
if (tryzero != -1 &&
i == sizeof (struct in6_addr) - 1)) {
tryzero = -1;
continue;
}
tryzero = -1;
i == sizeof (struct in6_addr) - 1)
numzero += 2;
}
}
/*
* Check for an IPv4 embedded address.
*/
if (IN6_IS_ADDR_V4MAPPED(&ip6) ||
IN6_IS_ADDR_V4COMPAT(&ip6)) {
for (i = sizeof (struct in6_addr) - 1;
i >= DTRACE_V4MAPPED_OFFSET; i--) {
if (val == 0) {
*end-- = '0';
} else {
}
}
if (i > DTRACE_V4MAPPED_OFFSET)
*end-- = '.';
}
if (subr == DIF_SUBR_INET_NTOA6)
goto inetout;
/*
* Set v6end to skip the IPv4 address that
* we have already stringified.
*/
v6end = 10;
}
/*
* Build the IPv6 string by working through the
* address in reverse.
*/
for (i = v6end; i >= 0; i -= 2) {
*end-- = ':';
*end-- = ':';
i -= numzero - 2;
continue;
}
*end-- = ':';
if (val == 0) {
*end-- = '0';
} else {
}
}
}
} else {
/*
* The user didn't use AH_INET or AH_INET6.
*/
break;
}
break;
}
}
}
/*
* Emulate the execution of DTrace IR instructions specified by the given
* DIF object. This function is deliberately void of assertions as all of
* the necessary checks are handled by a call to dtrace_difo_validate().
*/
static uint64_t
{
dtrace_difv_t *v;
/*
* We stash the current DIF object into the machine state: we need it
* for subsequent access checking.
*/
switch (DIF_INSTR_OP(instr)) {
case DIF_OP_OR:
break;
case DIF_OP_XOR:
break;
case DIF_OP_AND:
break;
case DIF_OP_SLL:
break;
case DIF_OP_SRL:
break;
case DIF_OP_SUB:
break;
case DIF_OP_ADD:
break;
case DIF_OP_MUL:
break;
case DIF_OP_SDIV:
*flags |= CPU_DTRACE_DIVZERO;
} else {
}
break;
case DIF_OP_UDIV:
*flags |= CPU_DTRACE_DIVZERO;
} else {
}
break;
case DIF_OP_SREM:
*flags |= CPU_DTRACE_DIVZERO;
} else {
}
break;
case DIF_OP_UREM:
*flags |= CPU_DTRACE_DIVZERO;
} else {
}
break;
case DIF_OP_NOT:
break;
case DIF_OP_MOV:
break;
case DIF_OP_CMP:
cc_v = 0;
break;
case DIF_OP_TST:
break;
case DIF_OP_BA:
break;
case DIF_OP_BE:
if (cc_z)
break;
case DIF_OP_BNE:
if (cc_z == 0)
break;
case DIF_OP_BG:
break;
case DIF_OP_BGU:
break;
case DIF_OP_BGE:
break;
case DIF_OP_BGEU:
if (cc_c == 0)
break;
case DIF_OP_BL:
break;
case DIF_OP_BLU:
if (cc_c)
break;
case DIF_OP_BLE:
break;
case DIF_OP_BLEU:
break;
case DIF_OP_RLDSB:
break;
/*FALLTHROUGH*/
case DIF_OP_LDSB:
break;
case DIF_OP_RLDSH:
break;
/*FALLTHROUGH*/
case DIF_OP_LDSH:
break;
case DIF_OP_RLDSW:
break;
/*FALLTHROUGH*/
case DIF_OP_LDSW:
break;
case DIF_OP_RLDUB:
break;
/*FALLTHROUGH*/
case DIF_OP_LDUB:
break;
case DIF_OP_RLDUH:
break;
/*FALLTHROUGH*/
case DIF_OP_LDUH:
break;
case DIF_OP_RLDUW:
break;
/*FALLTHROUGH*/
case DIF_OP_LDUW:
break;
case DIF_OP_RLDX:
break;
/*FALLTHROUGH*/
case DIF_OP_LDX:
break;
case DIF_OP_ULDSB:
break;
case DIF_OP_ULDSH:
break;
case DIF_OP_ULDSW:
break;
case DIF_OP_ULDUB:
break;
case DIF_OP_ULDUH:
break;
case DIF_OP_ULDUW:
break;
case DIF_OP_ULDX:
break;
case DIF_OP_RET:
break;
case DIF_OP_NOP:
break;
case DIF_OP_SETX:
break;
case DIF_OP_SETS:
break;
case DIF_OP_SCMP: {
break;
break;
break;
}
case DIF_OP_LDGA:
break;
case DIF_OP_LDGS:
if (id >= DIF_VAR_OTHER_UBASE) {
uintptr_t a;
break;
}
/*
* If the 0th byte is set to UINT8_MAX
* then this is to be treated as a
* reference to a NULL variable.
*/
} else {
}
break;
}
break;
case DIF_OP_STGS:
break;
} else {
*(uint8_t *)a = 0;
a += sizeof (uint64_t);
}
if (!dtrace_vcanload(
break;
(void *)a, &v->dtdv_type);
break;
}
break;
case DIF_OP_LDTA:
/*
* There are no DTrace built-in thread-local arrays at
* present. This opcode is saved for future work.
*/
*flags |= CPU_DTRACE_ILLOP;
break;
case DIF_OP_LDLS:
if (id < DIF_VAR_OTHER_UBASE) {
/*
* For now, this has no meaning.
*/
break;
}
/*
* If the 0th byte is set to UINT8_MAX
* then this is to be treated as a
* reference to a NULL variable.
*/
} else {
}
break;
}
break;
case DIF_OP_STLS:
break;
} else {
*(uint8_t *)a = 0;
a += sizeof (uint64_t);
}
if (!dtrace_vcanload(
break;
(void *)a, &v->dtdv_type);
break;
}
break;
case DIF_OP_LDTS: {
sizeof (uint64_t), DTRACE_DYNVAR_NOALLOC,
break;
}
} else {
}
break;
}
case DIF_OP_STTS: {
/*
* Given that we're storing to thread-local data,
* we need to flush our predicate cache.
*/
break;
if (!dtrace_vcanload(
break;
} else {
}
break;
}
case DIF_OP_SRA:
break;
case DIF_OP_CALL:
break;
case DIF_OP_PUSHTR:
if (ttop == DIF_DTR_NREGS) {
*flags |= CPU_DTRACE_TUPOFLOW;
break;
}
if (r1 == DIF_TYPE_STRING) {
/*
* If this is a string type and the size is 0,
* we'll use the system-wide default string
* size. Note that we are _not_ looking at
* the value of the DTRACEOPT_STRSIZE option;
* had this been set, we would expect to have
* a non-zero size value in the "pushtr".
*/
dtrace_strsize_default) + 1;
} else {
}
break;
case DIF_OP_PUSHTV:
if (ttop == DIF_DTR_NREGS) {
*flags |= CPU_DTRACE_TUPOFLOW;
break;
}
break;
case DIF_OP_POPTS:
if (ttop != 0)
ttop--;
break;
case DIF_OP_FLUSHTS:
ttop = 0;
break;
case DIF_OP_LDGAA:
case DIF_OP_LDTAA: {
} else {
}
break;
}
} else {
}
break;
}
case DIF_OP_STGAA:
case DIF_OP_STTAA: {
} else {
}
break;
if (!dtrace_vcanload(
break;
} else {
}
break;
}
case DIF_OP_ALLOCS: {
/*
* Rounding up the user allocation size could have
* overflowed large, bogus allocations (like -1ULL) to
* 0.
*/
break;
}
break;
}
case DIF_OP_COPYS:
*flags |= CPU_DTRACE_BADADDR;
break;
}
break;
break;
case DIF_OP_STB:
*flags |= CPU_DTRACE_BADADDR;
break;
}
break;
case DIF_OP_STH:
*flags |= CPU_DTRACE_BADADDR;
break;
}
*flags |= CPU_DTRACE_BADALIGN;
break;
}
break;
case DIF_OP_STW:
*flags |= CPU_DTRACE_BADADDR;
break;
}
*flags |= CPU_DTRACE_BADALIGN;
break;
}
break;
case DIF_OP_STX:
*flags |= CPU_DTRACE_BADADDR;
break;
}
*flags |= CPU_DTRACE_BADALIGN;
break;
}
break;
}
}
if (!(*flags & CPU_DTRACE_FAULT))
return (rval);
return (0);
}
static void
{
char *msg = "dtrace: breakpoint action at probe ";
char *ecbmsg = " (ecb ";
return;
/*
* It's impossible to be taking action on the NULL probe.
*/
/*
* This is a poor man's (destitute man's?) sprintf(): we want to
* print the provider name, module name, function name and name of
* the probe, along with the hex address of the ECB with the breakpoint
* action -- all of which we must place in the character buffer by
* hand.
*/
while (*msg != '\0')
c[i++] = *msg++;
c[i++] = *str;
c[i++] = ':';
c[i++] = *str;
c[i++] = ':';
c[i++] = *str;
c[i++] = ':';
c[i++] = *str;
while (*ecbmsg != '\0')
c[i++] = *ecbmsg++;
while (shift >= 0) {
shift -= 4;
}
c[i++] = ')';
c[i] = '\0';
debug_enter(c);
}
static void
{
/*
* It's impossible to be taking action on the NULL probe.
*/
return;
if (dtrace_panicked != NULL)
return;
return;
/*
* We won the right to panic. (We want to be sure that only one
* thread calls panic() from dtrace_probe(), and that panic() is
* called exactly once.)
*/
dtrace_panic("dtrace: panic action at probe %s:%s:%s:%s (ecb %p)",
}
static void
{
return;
return;
}
/*
* raise() has a queue depth of 1 -- we ignore all subsequent
* invocations of the raise() action.
*/
if (curthread->t_dtrace_sig == 0)
}
static void
dtrace_action_stop(void)
{
return;
if (!curthread->t_dtrace_stop) {
}
}
static void
{
return;
now = dtrace_gethrtime();
/*
* We need to advance the mark to the current time.
*/
cpu->cpu_dtrace_chilled = 0;
}
/*
* Now check to see if the requested chill time would take us over
* the maximum amount of time allowed in the chill interval. (Or
* worse, if the calculation itself induces overflow.)
*/
*flags |= CPU_DTRACE_ILLOP;
return;
}
continue;
/*
* Normally, we assure that the value of the variable "timestamp" does
* not change within an ECB. The presence of chill() represents an
* exception to this rule, however.
*/
}
static void
{
char *sym;
/*
* Should be taking a faster path if string space has not been
* allocated.
*/
/*
* We will first allocate some temporary space for the frame pointers.
*/
/*
* Not enough room for our frame pointers -- need to indicate
* that we ran out of scratch space.
*/
return;
}
/*
* Now get a stack with both program counters and frame pointers.
*/
/*
* If that faulted, we're cooked.
*/
if (*flags & CPU_DTRACE_FAULT)
goto out;
/*
* Now we want to walk up the stack, calling the USTACK helper. For
* each iteration, we restore the scratch pointer.
*/
for (i = 0; i < nframes; i++) {
break;
/*
* If we faulted while running the helper, we're going to
* clear the fault and null out the corresponding string.
*/
if (*flags & CPU_DTRACE_FAULT) {
*flags &= ~CPU_DTRACE_FAULT;
continue;
}
continue;
}
/*
* Now copy in the string that the helper returned to us.
*/
break;
}
offs += j + 1;
}
/*
* If we didn't have room for all of the strings, we don't
* abort processing -- this needn't be a fatal error -- but we
* still want to increment a counter (dts_stkstroverflows) to
* allow this condition to be warned about. (If this is from
* a jstack() action, it is easily tuned via jstackstrsize.)
*/
}
out:
}
static void
{
/*
* If this is a string, we're going to only load until we find the zero
* byte -- after which we'll store zero bytes.
*/
char c = '\0' + 1;
size_t s;
for (s = 0; s < size; s++) {
c = dtrace_load8(val++);
if (*flags & CPU_DTRACE_FAULT)
break;
}
if (c == '\0' && intuple)
break;
}
} else {
uint8_t c;
if (dtkind == DIF_TF_BYREF) {
c = dtrace_load8(val++);
} else if (dtkind == DIF_TF_BYUREF) {
if (*flags & CPU_DTRACE_FAULT)
break;
}
valoffs++, c);
}
}
}
/*
* If you're looking for the epicenter of DTrace, you just found it. This
* is the function called by the provider to fire a probe -- from which all
* subsequent probe-context DTrace activity emanates.
*/
void
{
/*
* Kick out immediately if this CPU is still being born (in which case
* curthread will be set to -1) or the current thread can't allow
* probes in its current context.
*/
return;
CPU->cpu_dtrace_probes++;
/*
* We have hit in the predicate cache; we know that
* this predicate would evaluate to be false.
*/
return;
}
if (panic_quiesce) {
/*
* We don't trace anything if we're panicking.
*/
return;
}
now = dtrace_gethrtime();
vtime = dtrace_vtime_references != 0;
uint64_t tracememsize = 0;
int committed = 0;
/*
* A little subtlety with the following (seemingly innocuous)
* declaration of the automatic 'val': by looking at the
* code, you might think that it could be declared in the
* action processing loop, below. (That is, it's only used in
* the action processing loop.) However, it must be declared
* out of that scope because in the case of DIF expression
* arguments to aggregating actions, one iteration of the
* action loop will use the last iteration's value.
*/
#ifdef lint
#else
#endif
*flags &= ~CPU_DTRACE_ERROR;
if (prov == dtrace_provider) {
/*
* If dtrace itself is the provider of this probe,
* we're only going to continue processing the ECB if
* arg0 (the dtrace_state_t) is equal to the ECB's
* creating state. (This prevents disjoint consumers
* from seeing one another's metaprobes.)
*/
continue;
}
/*
* We're not currently active. If our provider isn't
* the dtrace pseudo provider, we're not interested.
*/
if (prov != dtrace_provider)
continue;
/*
* Now we must further check if we are in the BEGIN
* probe. If we are, we will only continue processing
* if we're still in WARMUP -- if one BEGIN enabling
* has invoked the exit() action, we don't want to
* evaluate subsequent BEGIN enablings.
*/
continue;
}
}
continue;
/*
* We seem to be dead. Unless we (a) have kernel
* destructive permissions (b) have explicitly enabled
* destructive actions and (c) destructive actions have
* not been disabled, we're going to transition into
* the KILLED state, from which no further processing
* on this state will be performed.
*/
if (!dtrace_priv_kernel_destructive(state) ||
do {
continue;
}
}
continue;
}
}
int rval;
/*
* Update the predicate cache...
*/
}
continue;
}
}
uint64_t v = 0xbad;
v = dtrace_dif_emulate(dp,
if (*flags & CPU_DTRACE_ERROR)
continue;
/*
* Note that we always pass the expression
* value from the previous iteration of the
* action loop. This value will only be used
* if there is an expression argument to the
* aggregating action, denoted by the
* dtag_hasarg field.
*/
continue;
}
case DTRACEACT_STOP:
&mstate))
continue;
case DTRACEACT_BREAKPOINT:
continue;
case DTRACEACT_PANIC:
continue;
case DTRACEACT_STACK:
if (!dtrace_priv_kernel(state))
continue;
continue;
case DTRACEACT_JSTACK:
case DTRACEACT_USTACK:
continue;
/*
* See comment in DIF_VAR_PID.
*/
CPU_ON_INTR(CPU)) {
int depth = DTRACE_USTACK_NFRAMES(
continue;
}
/*
* This is the slow path -- we have
* allocated string space, and we're
* getting the stack of a process that
* has helpers. Call into a separate
* routine to perform this processing.
*/
continue;
}
/*
* Clear the string space, since there's no
* helper to do it for us.
*/
int depth = DTRACE_USTACK_NFRAMES(
valoffs);
}
continue;
default:
break;
}
if (*flags & CPU_DTRACE_ERROR)
continue;
case DTRACEACT_SPECULATE: {
*flags |= CPU_DTRACE_DROP;
continue;
}
if (offs < 0) {
*flags |= CPU_DTRACE_DROP;
continue;
}
continue;
sizeof (dtrace_rechdr_t));
/*
* When the speculation is committed, all of
* the records in the speculative buffer will
* have their timestamps set to the commit
* time. Until then, it is set to a sentinel
* value, for debugability.
*/
continue;
}
case DTRACEACT_CHILL:
continue;
case DTRACEACT_RAISE:
&mstate))
continue;
case DTRACEACT_COMMIT:
/*
* We need to commit our buffer state.
*/
committed = 1;
continue;
case DTRACEACT_DISCARD:
continue;
case DTRACEACT_DIFEXPR:
case DTRACEACT_LIBACT:
case DTRACEACT_PRINTF:
case DTRACEACT_PRINTA:
case DTRACEACT_SYSTEM:
case DTRACEACT_FREOPEN:
case DTRACEACT_TRACEMEM:
break;
tracememsize = val;
break;
case DTRACEACT_SYM:
case DTRACEACT_MOD:
if (!dtrace_priv_kernel(state))
continue;
break;
case DTRACEACT_USYM:
case DTRACEACT_UMOD:
case DTRACEACT_UADDR: {
continue;
continue;
}
case DTRACEACT_EXIT: {
/*
* For the exit action, we are going to attempt
* to atomically set our activity to be
* draining. If this fails (either because
* another CPU has beat us to the exit action,
* or because our current activity is something
* other than ACTIVE or WARMUP), we will
* continue. This assures that the exit action
* can be successfully recorded at most once
* when we're in the ACTIVE state. If we're
* encountering the exit() action while in
* COOLDOWN, however, we want to honor the new
* status code. (We know that we're the only
* thread in COOLDOWN, so there is no race.)
*/
if (current == DTRACE_ACTIVITY_COOLDOWN)
break;
if (current != DTRACE_ACTIVITY_WARMUP)
DTRACE_ACTIVITY_DRAINING) != current) {
*flags |= CPU_DTRACE_DROP;
continue;
}
break;
}
default:
ASSERT(0);
}
if (tracememsize != 0 &&
tracememsize = 0;
}
continue;
continue;
}
switch (size) {
case 0:
break;
case sizeof (uint8_t):
break;
case sizeof (uint16_t):
break;
case sizeof (uint32_t):
break;
case sizeof (uint64_t):
break;
default:
/*
* Any other size should have been returned by
* reference, not by value.
*/
ASSERT(0);
break;
}
}
if (*flags & CPU_DTRACE_DROP)
continue;
if (*flags & CPU_DTRACE_FAULT) {
int ndx;
buf->dtb_errors++;
/*
* There's nothing we can do -- we had an
* error on the error probe. We bump an
* error counter to at least indicate that
* this condition happened.
*/
continue;
}
if (vtime) {
/*
* Before recursing on dtrace_probe(), we
* need to explicitly clear out our start
* time to prevent it from being accumulated
* into t_dtrace_vtime.
*/
curthread->t_dtrace_start = 0;
}
/*
* Iterate over the actions to figure out which action
* we were processing when we experienced the error.
* Note that act points _past_ the faulting action; if
* act is ecb->dte_action, the fault was in the
* predicate, if it's ecb->dte_action->dta_next it's
* in action #1, and so on.
*/
continue;
continue;
}
if (!committed)
}
end = dtrace_gethrtime();
if (vtime)
}
/*
* DTrace Probe Hashing Functions
*
* The functions in this section (and indeed, the functions in remaining
* sections) are not _called_ from probe context. (Any exceptions to this are
* marked with a "Note:".) Rather, they are called from elsewhere in the
* DTrace framework to look-up probes in, add probes to and remove probes from
* the DTrace probe hashes. (Each probe is hashed by each element of the
* probe tuple -- allowing for fast lookups, regardless of what was
* specified.)
*/
static uint_t
dtrace_hash_str(char *p)
{
unsigned int g;
while (*p) {
if ((g = (hval & 0xf0000000)) != 0)
hval ^= g >> 24;
hval &= ~g;
}
return (hval);
}
static dtrace_hash_t *
{
sizeof (dtrace_hashbucket_t *), KM_SLEEP);
return (hash);
}
static void
{
#ifdef DEBUG
int i;
#endif
}
static void
{
for (i = 0; i < size; i++) {
}
}
}
static void
{
goto add;
}
return;
}
hash->dth_nbuckets++;
add:
}
}
static dtrace_probe_t *
{
return (bucket->dthb_chain);
}
return (NULL);
}
static int
{
}
return (NULL);
}
static void
{
/*
* Find the bucket that we're removing this probe from.
*/
break;
}
/*
* The removed probe was the only probe on this
* bucket; we need to remove the bucket.
*/
if (b == bucket) {
} else {
b = b->dthb_next;
}
hash->dth_nbuckets--;
return;
}
} else {
}
}
/*
* DTrace Utility Functions
*
* These are random utility functions that are _not_ called from probe context.
*/
static int
dtrace_badattr(const dtrace_attribute_t *a)
{
return (a->dtat_name > DTRACE_STABILITY_MAX ||
a->dtat_data > DTRACE_STABILITY_MAX ||
a->dtat_class > DTRACE_CLASS_MAX);
}
/*
* Return a duplicate copy of a string. If the specified string is NULL,
* this function returns a zero-length string.
*/
static char *
dtrace_strdup(const char *str)
{
return (new);
}
#define DTRACE_ISALPHA(c) \
(((c) >= 'a' && (c) <= 'z') || ((c) >= 'A' && (c) <= 'Z'))
static int
dtrace_badname(const char *s)
{
char c;
if (s == NULL || (c = *s++) == '\0')
return (0);
return (1);
while ((c = *s++) != '\0') {
c != '-' && c != '_' && c != '.' && c != '`')
return (1);
}
return (0);
}
static void
{
/*
* For DTRACE_PRIV_ALL, the uid and zoneid don't matter.
*/
} else {
priv = 0;
priv |= DTRACE_PRIV_USER;
priv |= DTRACE_PRIV_PROC;
}
}
#ifdef DTRACE_ERRDEBUG
static void
dtrace_errdebug(const char *str)
{
int occupied = 0;
while (occupied++ < DTRACE_ERRHASHSZ) {
goto out;
}
continue;
}
goto out;
}
panic("dtrace: undersized error hash");
out:
}
#endif
/*
* DTrace Matching Functions
*
* These functions are used to match groups of probes, given some elements of
* a probe tuple, or some globbed expressions for elements of a probe tuple.
*/
static int
{
if (priv != DTRACE_PRIV_ALL) {
/*
* No PRIV_DTRACE_* privileges...
*/
DTRACE_PRIV_KERNEL)) == 0)
return (0);
/*
* No matching bits, but there were bits to match...
*/
return (0);
/*
* Need to have permissions to the process, but don't...
*/
return (0);
}
/*
* Need to be in the same zone unless we possess the
* privilege to examine all zones.
*/
return (0);
}
}
return (1);
}
/*
* dtrace_match_probe compares a dtrace_probe_t to a pre-compiled key, which
* consists of input pattern strings and an ops-vector to evaluate them.
* This function returns >0 for match, 0 for no match, and <0 for error.
*/
static int
{
int rv;
if (pvp->dtpv_defunct)
return (0);
return (rv);
return (rv);
return (rv);
return (rv);
return (0);
return (rv);
}
/*
* dtrace_match_glob() is a safe kernel implementation of the gmatch(3GEN)
* interface for matching a glob pattern 'p' to an input string 's'. Unlike
* libc's version, the kernel version only applies to 8-bit ASCII strings.
* In addition, all of the recursion cases except for '*' matching have been
* unwound. For '*', we still implement recursive evaluation, but a depth
* counter is maintained and matching is aborted if we recurse too deep.
* The function returns 0 if no match, >0 if match, and <0 if recursion error.
*/
static int
dtrace_match_glob(const char *s, const char *p, int depth)
{
const char *olds;
char s1, c;
int gs;
if (depth > DTRACE_PROBEKEY_MAXDEPTH)
return (-1);
if (s == NULL)
s = ""; /* treat NULL as empty string */
top:
olds = s;
s1 = *s++;
if (p == NULL)
return (0);
if ((c = *p++) == '\0')
return (s1 == '\0');
switch (c) {
case '[': {
char lc = '\0';
if (s1 == '\0')
return (0);
if (*p == '!') {
notflag = 1;
p++;
}
if ((c = *p++) == '\0')
return (0);
do {
if ((c = *p++) == '\0')
return (0);
if (c == '\\' && (c = *p++) == '\0')
return (0);
if (notflag) {
ok++;
else
return (0);
ok++;
} else if (c == '\\' && (c = *p++) == '\0')
return (0);
lc = c; /* save left-hand 'c' for next iteration */
if (notflag) {
if (s1 != c)
ok++;
else
return (0);
} else if (s1 == c)
ok++;
if ((c = *p++) == '\0')
return (0);
} while (c != ']');
if (ok)
goto top;
return (0);
}
case '\\':
if ((c = *p++) == '\0')
return (0);
/*FALLTHRU*/
default:
if (c != s1)
return (0);
/*FALLTHRU*/
case '?':
if (s1 != '\0')
goto top;
return (0);
case '*':
while (*p == '*')
p++; /* consecutive *'s are identical to a single one */
if (*p == '\0')
return (1);
for (s = olds; *s != '\0'; s++) {
return (gs);
}
return (0);
}
}
/*ARGSUSED*/
static int
dtrace_match_string(const char *s, const char *p, int depth)
{
}
/*ARGSUSED*/
static int
dtrace_match_nul(const char *s, const char *p, int depth)
{
return (1); /* always match the empty pattern */
}
/*ARGSUSED*/
static int
dtrace_match_nonzero(const char *s, const char *p, int depth)
{
return (s != NULL && s[0] != '\0');
}
static int
{
dtrace_id_t i;
/*
* If the probe ID is specified in the key, just lookup by ID and
* invoke the match callback once if a matching probe is found.
*/
return (DTRACE_MATCH_FAIL);
nmatched++;
}
return (nmatched);
}
/*
* We want to find the most distinct of the module name, function
* name, and name. So for each one that is not a glob pattern or
* empty string, we perform a lookup in the corresponding hash and
* use the hash table with the fewest collisions to do our search.
*/
hash = dtrace_bymod;
}
}
}
/*
* If we did not select a hash table, iterate over every probe and
* invoke our callback for each one that matches our input probe key.
*/
for (i = 0; i < dtrace_nprobes; i++) {
zoneid) <= 0)
continue;
nmatched++;
if (rc == DTRACE_MATCH_FAIL)
return (DTRACE_MATCH_FAIL);
break;
}
}
return (nmatched);
}
/*
* If we selected a hash table, iterate over each probe of the same key
* name and invoke the callback for every probe that matches the other
* attributes of our input probe key.
*/
continue;
nmatched++;
if (rc == DTRACE_MATCH_FAIL)
return (DTRACE_MATCH_FAIL);
break;
}
}
return (nmatched);
}
/*
* Return the function pointer dtrace_probecmp() should use to compare the
* specified pattern with a string. For NULL or empty patterns, we select
* dtrace_match_nul(). For glob pattern strings, we use dtrace_match_glob().
* For non-empty non-glob strings, we use dtrace_match_string().
*/
static dtrace_probekey_f *
dtrace_probekey_func(const char *p)
{
char c;
if (p == NULL || *p == '\0')
return (&dtrace_match_nul);
while ((c = *p++) != '\0') {
if (c == '[' || c == '?' || c == '*' || c == '\\')
return (&dtrace_match_glob);
}
return (&dtrace_match_string);
}
/*
* Build a probe comparison key for use with dtrace_match_probe() from the
* given probe description. By convention, a null key only matches anchored
* probes: if each field is the empty string, reset dtpk_fmatch to
* dtrace_match_nonzero().
*/
static void
{
}
/*
* DTrace Provider-to-Framework API Functions
*
* These functions implement much of the Provider-to-Framework API, as
* the functions in the API for probe management (found below), and
* dtrace_probe() itself (found above).
*/
/*
* Register the calling provider with the DTrace framework. This should
* generally be called by DTrace providers in their attach(9E) entry point.
*/
int
{
return (EINVAL);
}
"provider name", name);
return (EINVAL);
}
"provider ops", name);
return (EINVAL);
}
"provider attributes", name);
return (EINVAL);
}
if (priv & ~DTRACE_PRIV_ALL) {
"privilege attributes", name);
return (EINVAL);
}
if ((priv & DTRACE_PRIV_KERNEL) &&
"dtps_mode() op for given privilege attributes", name);
return (EINVAL);
}
}
(void (*)(void *, const dtrace_probedesc_t *))dtrace_nullop;
}
(void (*)(void *, struct modctl *))dtrace_nullop;
}
(void (*)(void *, dtrace_id_t, void *))dtrace_nullop;
(void (*)(void *, dtrace_id_t, void *))dtrace_nullop;
}
if (pops == &dtrace_provider_ops) {
/*
* We make sure that the DTrace provider is at the head of
* the provider chain.
*/
return (0);
}
/*
* If there is at least one provider registered, we'll add this
* provider after the first provider.
*/
if (dtrace_provider != NULL) {
} else {
}
if (dtrace_retained != NULL) {
/*
* Now we need to call dtrace_enabling_matchall() -- which
* will acquire cpu_lock and dtrace_lock. We therefore need
* to drop all of our locks before calling into it...
*/
return (0);
}
return (0);
}
/*
* Unregister the specified provider from the DTrace framework. This should
* generally be called by DTrace providers in their detach(9E) entry point.
*/
int
{
(int (*)(void *, dtrace_id_t, void *))dtrace_enable_nullop) {
/*
* If DTrace itself is the provider, we're called with locks
* already held.
*/
self = 1;
/*
* There's another provider here; return failure.
*/
return (EBUSY);
}
} else {
}
/*
* probes, we refuse to let providers slither away, unless this
* provider has already been explicitly invalidated.
*/
if (!old->dtpv_defunct &&
if (!self) {
}
return (EBUSY);
}
/*
* Attempt to destroy the probes associated with this provider.
*/
for (i = 0; i < dtrace_nprobes; i++) {
continue;
continue;
continue;
/*
* If we are trying to unregister a defunct provider, and the
* provider was made defunct within the interval dictated by
* dtrace_unregister_defunct_reap, we'll (asynchronously)
* attempt to reap our enablings. To denote that the provider
* should reattempt to unregister itself at some point in the
* future, we will return a differentiable error code (EAGAIN
* instead of EBUSY) in this case.
*/
noreap = 1;
if (!self) {
}
if (noreap)
return (EBUSY);
(void) taskq_dispatch(dtrace_taskq,
return (EAGAIN);
}
/*
* All of the probes for this provider are disabled; we can safely
* remove all of them from their hash chains and from the probe array.
*/
for (i = 0; i < dtrace_nprobes; i++) {
continue;
continue;
dtrace_probes[i] = NULL;
} else {
}
}
/*
* The provider's probes have been removed from the hash chains and
* from the probe array. Now issue a dtrace_sync() to be sure that
* everyone has cleared out from any probe array processing.
*/
dtrace_sync();
}
} else {
panic("attempt to unregister non-existent "
"dtrace provider %p\n", (void *)id);
}
}
if (!self) {
}
return (0);
}
/*
* Invalidate the specified provider. All subsequent probe lookups for the
* specified provider will fail, but its probes will not be removed.
*/
void
{
(int (*)(void *, dtrace_id_t, void *))dtrace_enable_nullop);
}
/*
* Indicate whether or not DTrace has attached.
*/
int
dtrace_attached(void)
{
/*
* dtrace_provider will be non-NULL iff the DTrace driver has
* attached. (It's non-NULL because DTrace is always itself a
* provider.)
*/
return (dtrace_provider != NULL);
}
/*
* Remove all the unenabled probes for the given provider. This function is
* not unlike dtrace_unregister(), except that it doesn't remove the provider
* -- just as many of its associated probes as it can.
*/
int
{
int i;
/*
* Make sure this isn't the dtrace provider itself.
*/
(int (*)(void *, dtrace_id_t, void *))dtrace_enable_nullop);
/*
* Attempt to destroy the probes associated with this provider.
*/
for (i = 0; i < dtrace_nprobes; i++) {
continue;
continue;
continue;
dtrace_probes[i] = NULL;
}
return (0);
}
/*
* DTrace Probe Management Functions
*
* The functions in this section perform the DTrace probe management,
* including functions to create probes, look-up probes, and call into the
* providers to request that probes be provided. Some of these functions are
* in the Provider-to-Framework API; these functions can be identified by the
* fact that they are not declared "static".
*/
/*
* Create a probe with the specified module name, function name, and name.
*/
{
if (provider == dtrace_provider) {
} else {
}
VM_BESTFIT | VM_SLEEP);
if (nsize == 0) {
nsize = sizeof (dtrace_probe_t *);
}
if (dtrace_probes == NULL) {
dtrace_nprobes = 1;
} else {
dtrace_sync();
/*
* All CPUs are now seeing the new probes array; we can
* safely free the old array.
*/
dtrace_nprobes <<= 1;
}
}
if (provider != dtrace_provider)
return (id);
}
static dtrace_probe_t *
{
return (NULL);
}
static int
{
return (DTRACE_MATCH_DONE);
}
/*
* Look up a probe based on provider and one or more of module name, function
* name and probe name.
*/
{
int match;
}
/*
* Returns the probe argument associated with the specified probe.
*/
void *
{
return (rval);
}
/*
* Copy a probe into a probe description.
*/
static void
{
}
/*
* Called to indicate that a probe -- or probes -- should be provided by a
* specfied provider. If the specified description is NULL, the provider will
* be told to provide all of its probes. (This is done whenever a new
* consumer comes along, or whenever a retained enabling is to be matched.) If
* the specified description is non-NULL, the provider is given the
* opportunity to dynamically provide the specified probe, allowing providers
* to support the creation of probes on-the-fly. (So-called _autocreated_
* probes.) If the provider is NULL, the operations will be applied to all
* providers; if the provider is non-NULL the operations will only be applied
* to the specified provider. The dtrace_provider_lock must be held, and the
* dtrace_lock must _not_ be held -- the provider's dtps_provide() operation
* will need to grab the dtrace_lock when it reenters the framework through
* dtrace_probe_lookup(), dtrace_probe_create(), etc.
*/
static void
{
int all = 0;
all = 1;
}
do {
/*
* First, call the blanket provide operation.
*/
/*
* Now call the per-module provide operation. We will grab
* mod_lock to prevent the list from being modified. Note
* that this also prevents the mod_busy bits from changing.
* (mod_busy can only be changed with mod_lock held.)
*/
do {
continue;
}
/*
* Iterate over each probe, and call the Framework-to-Provider API function
* denoted by offs.
*/
static void
{
void (*func)(void *, dtrace_id_t, void *);
int i;
/*
* We disable interrupts to walk through the probe array. This is
* safe -- the dtrace_sync() in dtrace_unregister() assures that we
* won't see stale data.
*/
for (i = 0; i < dtrace_nprobes; i++) {
continue;
/*
* This probe isn't enabled -- don't call the function.
*/
continue;
}
func = *((void(**)(void *, dtrace_id_t, void *))
}
}
static int
{
/*
* If we're passed a NULL description, we're being asked to
* create an ECB with a NULL probe.
*/
return (0);
}
enab));
}
/*
* DTrace Helper Provider Functions
*/
static void
{
}
static void
{
}
static void
{
char *strtab;
void *parg;
/*
* See dtrace_helper_provider_validate().
*/
}
/*
* Create the provider.
*/
return;
/*
* Create the probes.
*/
for (i = 0; i < nprobes; i++) {
} else {
dhpb.dthpb_nenoffs = 0;
}
}
}
static void
{
int i;
for (i = 0; i < dof->dofh_secnum; i++) {
continue;
}
/*
* We may have just created probes, so we must now rematch against
* any retained enablings. Note that this call will acquire both
* cpu_lock and dtrace_lock; the fact that we are holding
* dtrace_meta_lock now is what defines the ordering with respect to
* these three locks.
*/
}
static void
{
char *strtab;
/*
* Create the provider.
*/
}
static void
{
int i;
for (i = 0; i < dof->dofh_secnum; i++) {
continue;
}
}
/*
* DTrace Meta Provider-to-Framework API Functions
*
* These functions implement the Meta Provider-to-Framework API, as described
*/
int
{
int i;
/*
* We strictly don't need the name, but we hold onto it for
* debuggability. All hail error queues!
*/
"invalid name");
return (EINVAL);
}
"invalid ops", name);
return (EINVAL);
}
if (dtrace_meta_pid != NULL) {
"user-land meta-provider exists", name);
return (EINVAL);
}
/*
* If there are providers and probes ready to go, pass them
* off to the new meta provider now.
*/
for (i = 0; i < help->dthps_nprovs; i++) {
}
help->dthps_deferred = 0;
}
return (0);
}
int
{
if (old == dtrace_meta_pid) {
pp = &dtrace_meta_pid;
} else {
panic("attempt to unregister non-existent "
"dtrace meta-provider %p\n", (void *)old);
}
return (EBUSY);
}
return (0);
}
/*
* DTrace DIF Object Functions
*/
static int
{
if (dtrace_err_verbose) {
}
#ifdef DTRACE_ERRDEBUG
#endif
return (1);
}
/*
* Validate a DTrace DIF object by checking the IR instructions. The following
* rules are currently enforced by dtrace_difo_validate():
*
* 1. Each instruction must have a valid opcode
* 2. Each register, string, variable, or subroutine reference must be valid
* 3. No instruction can modify register %r0 (must be zero)
* 4. All instruction reserved bits must be set to zero
* 5. The last instruction must be a "ret" instruction
* 6. All branch targets must reference a valid instruction _after_ the branch
*/
static int
{
int err = 0, i;
int kcheckload;
dp->dtdo_destructive = 0;
switch (op) {
case DIF_OP_OR:
case DIF_OP_XOR:
case DIF_OP_AND:
case DIF_OP_SLL:
case DIF_OP_SRL:
case DIF_OP_SRA:
case DIF_OP_SUB:
case DIF_OP_ADD:
case DIF_OP_MUL:
case DIF_OP_SDIV:
case DIF_OP_UDIV:
case DIF_OP_SREM:
case DIF_OP_UREM:
case DIF_OP_COPYS:
if (rd == 0)
break;
case DIF_OP_NOT:
case DIF_OP_MOV:
case DIF_OP_ALLOCS:
if (r2 != 0)
if (rd == 0)
break;
case DIF_OP_LDSB:
case DIF_OP_LDSH:
case DIF_OP_LDSW:
case DIF_OP_LDUB:
case DIF_OP_LDUH:
case DIF_OP_LDUW:
case DIF_OP_LDX:
if (r2 != 0)
if (rd == 0)
if (kcheckload)
break;
case DIF_OP_RLDSB:
case DIF_OP_RLDSH:
case DIF_OP_RLDSW:
case DIF_OP_RLDUB:
case DIF_OP_RLDUH:
case DIF_OP_RLDUW:
case DIF_OP_RLDX:
if (r2 != 0)
if (rd == 0)
break;
case DIF_OP_ULDSB:
case DIF_OP_ULDSH:
case DIF_OP_ULDSW:
case DIF_OP_ULDUB:
case DIF_OP_ULDUH:
case DIF_OP_ULDUW:
case DIF_OP_ULDX:
if (r2 != 0)
if (rd == 0)
break;
case DIF_OP_STB:
case DIF_OP_STH:
case DIF_OP_STW:
case DIF_OP_STX:
if (r2 != 0)
if (rd == 0)
break;
case DIF_OP_CMP:
case DIF_OP_SCMP:
if (rd != 0)
break;
case DIF_OP_TST:
break;
case DIF_OP_BA:
case DIF_OP_BE:
case DIF_OP_BNE:
case DIF_OP_BG:
case DIF_OP_BGU:
case DIF_OP_BGE:
case DIF_OP_BGEU:
case DIF_OP_BL:
case DIF_OP_BLU:
case DIF_OP_BLE:
case DIF_OP_BLEU:
label);
}
label);
}
break;
case DIF_OP_RET:
break;
case DIF_OP_NOP:
case DIF_OP_POPTS:
case DIF_OP_FLUSHTS:
break;
case DIF_OP_SETX:
}
if (rd == 0)
break;
case DIF_OP_SETS:
}
if (rd == 0)
break;
case DIF_OP_LDGA:
case DIF_OP_LDTA:
if (r1 > DIF_VAR_ARRAY_MAX)
if (rd == 0)
break;
case DIF_OP_LDGS:
case DIF_OP_LDTS:
case DIF_OP_LDLS:
case DIF_OP_LDGAA:
case DIF_OP_LDTAA:
if (v < DIF_VAR_OTHER_MIN || v > DIF_VAR_OTHER_MAX)
if (rd == 0)
break;
case DIF_OP_STGS:
case DIF_OP_STTS:
case DIF_OP_STLS:
case DIF_OP_STGAA:
case DIF_OP_STTAA:
if (v < DIF_VAR_OTHER_UBASE || v > DIF_VAR_OTHER_MAX)
break;
case DIF_OP_CALL:
if (subr > DIF_SUBR_MAX)
if (rd == 0)
if (subr == DIF_SUBR_COPYOUT ||
subr == DIF_SUBR_COPYOUTSTR) {
}
if (subr == DIF_SUBR_GETF) {
/*
* If we have a getf() we need to record that
* in our state. Note that our state can be
* NULL if this is a helper -- but in that
* case, the call to getf() is itself illegal,
* and will be caught (slightly later) when
* the helper is validated.
*/
}
break;
case DIF_OP_PUSHTR:
break;
case DIF_OP_PUSHTV:
if (type != DIF_TYPE_CTF)
break;
default:
}
}
"expected 'ret' as last DIF instruction\n");
}
/*
* If we're not returning by reference, the size must be either
* 0 or the size of one of the base types.
*/
case 0:
case sizeof (uint8_t):
case sizeof (uint16_t):
case sizeof (uint32_t):
case sizeof (uint64_t):
break;
default:
}
}
if (v->dtdv_scope != DIFV_SCOPE_GLOBAL &&
v->dtdv_scope != DIFV_SCOPE_THREAD &&
v->dtdv_scope != DIFV_SCOPE_LOCAL) {
v->dtdv_scope);
break;
}
if (v->dtdv_kind != DIFV_KIND_ARRAY &&
v->dtdv_kind != DIFV_KIND_SCALAR) {
v->dtdv_kind);
break;
}
break;
}
if (id < DIF_VAR_OTHER_UBASE)
continue;
/*
* For user-defined variables, we need to check that this
* definition is identical to any previous definition that we
* encountered.
*/
switch (v->dtdv_scope) {
case DIFV_SCOPE_GLOBAL:
}
break;
case DIFV_SCOPE_THREAD:
break;
case DIFV_SCOPE_LOCAL:
}
break;
}
break;
}
if (v->dtdv_scope == DIFV_SCOPE_GLOBAL &&
break;
}
}
continue;
break;
}
break;
}
}
return (err);
}
/*
* Validate a DTrace DIF object that it is to be used as a helper. Helpers
* are much more constrained than normal DIFOs. Specifically, they may
* not:
*
* 1. Make calls to subroutines other than copyin(), copyinstr() or
* miscellaneous string routines
* 2. Access DTrace variables other than the args[] array, and the
* curthread, pid, ppid, tid, execname, zonename, uid and gid variables.
* 3. Have thread-local variables.
* 4. Have dynamic variables.
*/
static int
{
int err = 0;
switch (op) {
case DIF_OP_OR:
case DIF_OP_XOR:
case DIF_OP_AND:
case DIF_OP_SLL:
case DIF_OP_SRL:
case DIF_OP_SRA:
case DIF_OP_SUB:
case DIF_OP_ADD:
case DIF_OP_MUL:
case DIF_OP_SDIV:
case DIF_OP_UDIV:
case DIF_OP_SREM:
case DIF_OP_UREM:
case DIF_OP_COPYS:
case DIF_OP_NOT:
case DIF_OP_MOV:
case DIF_OP_RLDSB:
case DIF_OP_RLDSH:
case DIF_OP_RLDSW:
case DIF_OP_RLDUB:
case DIF_OP_RLDUH:
case DIF_OP_RLDUW:
case DIF_OP_RLDX:
case DIF_OP_ULDSB:
case DIF_OP_ULDSH:
case DIF_OP_ULDSW:
case DIF_OP_ULDUB:
case DIF_OP_ULDUH:
case DIF_OP_ULDUW:
case DIF_OP_ULDX:
case DIF_OP_STB:
case DIF_OP_STH:
case DIF_OP_STW:
case DIF_OP_STX:
case DIF_OP_ALLOCS:
case DIF_OP_CMP:
case DIF_OP_SCMP:
case DIF_OP_TST:
case DIF_OP_BA:
case DIF_OP_BE:
case DIF_OP_BNE:
case DIF_OP_BG:
case DIF_OP_BGU:
case DIF_OP_BGE:
case DIF_OP_BGEU:
case DIF_OP_BL:
case DIF_OP_BLU:
case DIF_OP_BLE:
case DIF_OP_BLEU:
case DIF_OP_RET:
case DIF_OP_NOP:
case DIF_OP_POPTS:
case DIF_OP_FLUSHTS:
case DIF_OP_SETX:
case DIF_OP_SETS:
case DIF_OP_LDGA:
case DIF_OP_LDLS:
case DIF_OP_STGS:
case DIF_OP_STLS:
case DIF_OP_PUSHTR:
case DIF_OP_PUSHTV:
break;
case DIF_OP_LDGS:
if (v >= DIF_VAR_OTHER_UBASE)
break;
if (v >= DIF_VAR_ARG0 && v <= DIF_VAR_ARG9)
break;
if (v == DIF_VAR_CURTHREAD || v == DIF_VAR_PID ||
v == DIF_VAR_PPID || v == DIF_VAR_TID ||
v == DIF_VAR_EXECNAME || v == DIF_VAR_ZONENAME ||
v == DIF_VAR_UID || v == DIF_VAR_GID)
break;
break;
case DIF_OP_LDTA:
case DIF_OP_LDTS:
case DIF_OP_LDGAA:
case DIF_OP_LDTAA:
break;
case DIF_OP_STTS:
case DIF_OP_STGAA:
case DIF_OP_STTAA:
break;
case DIF_OP_CALL:
if (subr == DIF_SUBR_ALLOCA ||
subr == DIF_SUBR_BCOPY ||
subr == DIF_SUBR_COPYIN ||
subr == DIF_SUBR_COPYINTO ||
subr == DIF_SUBR_COPYINSTR ||
subr == DIF_SUBR_INDEX ||
subr == DIF_SUBR_INET_NTOA ||
subr == DIF_SUBR_INET_NTOA6 ||
subr == DIF_SUBR_INET_NTOP ||
subr == DIF_SUBR_JSON ||
subr == DIF_SUBR_LLTOSTR ||
subr == DIF_SUBR_STRTOLL ||
subr == DIF_SUBR_RINDEX ||
subr == DIF_SUBR_STRCHR ||
subr == DIF_SUBR_STRJOIN ||
subr == DIF_SUBR_STRRCHR ||
subr == DIF_SUBR_STRSTR ||
subr == DIF_SUBR_HTONS ||
subr == DIF_SUBR_HTONL ||
subr == DIF_SUBR_HTONLL ||
subr == DIF_SUBR_NTOHS ||
subr == DIF_SUBR_NTOHL ||
subr == DIF_SUBR_NTOHLL)
break;
break;
default:
}
}
return (err);
}
/*
* Returns 1 if the expression in the DIF object can be cached on a per-thread
* basis; 0 if not.
*/
static int
{
int i;
return (0);
for (i = 0; i < dp->dtdo_varlen; i++) {
if (v->dtdv_scope != DIFV_SCOPE_GLOBAL)
continue;
switch (v->dtdv_id) {
case DIF_VAR_CURTHREAD:
case DIF_VAR_PID:
case DIF_VAR_TID:
case DIF_VAR_EXECNAME:
case DIF_VAR_ZONENAME:
break;
default:
return (0);
}
}
/*
* This DIF object may be cacheable. Now we need to look for any
* array loading instructions, any memory loading instructions, or
* any stores to thread-local variables.
*/
return (0);
}
return (1);
}
static void
{
int i;
dp->dtdo_refcnt++;
/*
* We need to check this DIF object for references to the variable
* DIF_VAR_VTIMESTAMP.
*/
for (i = 0; i < dp->dtdo_varlen; i++) {
if (v->dtdv_id != DIF_VAR_VTIMESTAMP)
continue;
if (dtrace_vtime_references++ == 0)
}
}
/*
* This routine calculates the dynamic variable chunksize for a given DIF
* object. The calculation is not fool-proof, and can probably be tricked by
* malicious DIF -- but it works for all compiler-generated DIF. Because this
* calculation is likely imperfect, dtrace_dynvar() is able to gracefully fail
* if a dynamic variable size exceeds the chunksize.
*/
static void
{
switch (op) {
case DIF_OP_SETX:
continue;
case DIF_OP_STTS:
nkeys = 2;
break;
case DIF_OP_STGAA:
case DIF_OP_STTAA:
if (op == DIF_OP_STTAA) {
} else {
}
break;
case DIF_OP_PUSHTR:
if (ttop == DIF_DTR_NREGS)
return;
/*
* If the register for the size of the "pushtr"
* is %r0 (or the value is 0) and the type is
* a string, we'll use the system-wide default
* string size.
*/
} else {
if (srd == 0)
return;
}
break;
case DIF_OP_PUSHTV:
if (ttop == DIF_DTR_NREGS)
return;
break;
case DIF_OP_FLUSHTS:
ttop = 0;
break;
case DIF_OP_POPTS:
if (ttop != 0)
ttop--;
break;
}
sval = 0;
srd = 0;
if (nkeys == 0)
continue;
/*
* We have a dynamic variable allocation; calculate its size.
*/
size = sizeof (dtrace_dynvar_t);
/*
* Now we need to determine the size of the stored data.
*/
for (i = 0; i < dp->dtdo_varlen; i++) {
break;
}
}
if (i == dp->dtdo_varlen)
return;
/*
* We have the size. If this is larger than the chunk size
* for our dynamic variable state, reset the chunk size.
*/
}
}
static void
{
for (i = 0; i < dp->dtdo_varlen; i++) {
int *np;
continue;
switch (scope) {
case DIFV_SCOPE_THREAD:
ntlocals = 1;
if (osz != 0) {
}
}
continue;
case DIFV_SCOPE_LOCAL:
sizeof (uint64_t));
else
break;
case DIFV_SCOPE_GLOBAL:
sizeof (uint64_t);
break;
default:
ASSERT(0);
}
newsvars = 1;
if (oldsize != 0) {
}
}
}
}
svar->dtsv_refcnt++;
}
}
static dtrace_difo_t *
{
}
}
}
return (new);
}
static void
{
int i;
for (i = 0; i < dp->dtdo_varlen; i++) {
int *np;
switch (scope) {
case DIFV_SCOPE_THREAD:
continue;
case DIFV_SCOPE_LOCAL:
break;
case DIFV_SCOPE_GLOBAL:
break;
default:
ASSERT(0);
}
continue;
if (--svar->dtsv_refcnt > 0)
continue;
}
}
}
static void
{
int i;
for (i = 0; i < dp->dtdo_varlen; i++) {
if (v->dtdv_id != DIF_VAR_VTIMESTAMP)
continue;
if (--dtrace_vtime_references == 0)
}
if (--dp->dtdo_refcnt == 0)
}
/*
* DTrace Format Functions
*/
static uint16_t
{
return (ndx + 1);
}
}
/*
* This is only likely if a denial-of-service attack is being
* attempted. As such, it's okay to fail silently here.
*/
return (0);
}
/*
* For simplicity, we always resize the formats array to be exactly the
* number of formats.
*/
}
return (ndx + 1);
}
static void
{
char *fmt;
}
static void
{
int i;
if (state->dts_nformats == 0) {
return;
}
for (i = 0; i < state->dts_nformats; i++) {
continue;
}
state->dts_nformats = 0;
}
/*
* DTrace Predicate Functions
*/
static dtrace_predicate_t *
{
if (!dtrace_difo_cacheable(dp))
return (pred);
if (dtrace_predcache_id == DTRACE_CACHEIDNONE) {
/*
* This is only theoretically possible -- we have had 2^32
* cacheable predicates on this machine. We cannot allow any
* more predicates to become cacheable: as unlikely as it is,
* there may be a thread caching a (now stale) predicate cache
* ID. (N.B.: the temptation is being successfully resisted to
* have this cmn_err() "Holy shit -- we executed this code!")
*/
return (pred);
}
return (pred);
}
static void
{
pred->dtp_refcnt++;
}
static void
{
if (--pred->dtp_refcnt == 0) {
}
}
/*
* DTrace Action Description Functions
*/
static dtrace_actdesc_t *
{
return (act);
}
static void
{
act->dtad_refcnt++;
}
static void
{
if (--act->dtad_refcnt != 0)
return;
if (DTRACEACT_ISPRINTFLIKE(kind)) {
}
}
/*
* DTrace ECB Functions
*/
static dtrace_ecb_t *
{
/*
* The default size is the size of the default action: recording
* the header.
*/
if (necbs == 0) {
necbs = 1;
}
/*
* If this state is active, we must dtrace_sync()
* before we can free the old dts_ecbs array: we're
* coming in hot, and there may be active ring
* buffer processing (which indexes into the dts_ecbs
* array) on another CPU.
*/
dtrace_sync();
}
}
return (ecb);
}
static int
{
/*
* This is the NULL probe -- there's nothing to do.
*/
return (0);
}
/*
* We're the first ECB on this probe.
*/
} else {
/*
* This probe is already active. Swing the last pointer to
* point to the new ECB, and issue a dtrace_sync() to assure
* that all CPUs have seen the change.
*/
probe->dtpr_predcache = 0;
dtrace_sync();
return (0);
}
}
static void
{
/*
* If we record anything, we always record the dtrace_rechdr_t. (And
* we always record it first.)
*/
} else if (act->dta_intuple) {
if (curneeded == UINT32_MAX) {
/*
* This is the first record in a tuple. Align
* curneeded to be at offset 4 in an 8-byte
* aligned block.
*/
sizeof (uint64_t), sizeof (dtrace_aggid_t));
sizeof (uint64_t)));
}
} else {
/* tuples must be followed by an aggregation */
}
}
/*
* If the size is still sizeof (dtrace_rechdr_t), then all
* actions store no data; set the size to 0.
*/
}
ecb->dte_needed);
}
static dtrace_action_t *
{
case DTRACEAGG_MIN:
break;
case DTRACEAGG_MAX:
break;
case DTRACEAGG_COUNT:
break;
case DTRACEAGG_QUANTIZE:
sizeof (uint64_t);
break;
case DTRACEAGG_LQUANTIZE: {
goto err;
break;
}
case DTRACEAGG_LLQUANTIZE: {
int64_t v;
goto err;
/*
* Now check that the number of steps evenly divides a power
* of the factor. (This assures both integer bucket size and
* linearity within each magnitude.)
*/
continue;
goto err;
break;
}
case DTRACEAGG_AVG:
break;
case DTRACEAGG_STDDEV:
break;
case DTRACEAGG_SUM:
break;
default:
goto err;
}
if (ntuple == 0)
goto err;
/*
* We must make sure that we have enough actions for the n-tuple.
*/
break;
if (--ntuple == 0) {
/*
* This is the action with which our n-tuple begins.
*/
goto success;
}
}
/*
* This n-tuple is short by ntuple elements. Return failure.
*/
err:
return (NULL);
/*
* If the last action in the tuple has a size of zero, it's actually
* an expression argument for the aggregating action.
*/
}
/*
* We need to allocate an id for this aggregation.
*/
VM_BESTFIT | VM_SLEEP);
if (naggs == 0) {
naggs = 1;
}
}
}
}
return (&agg->dtag_action);
}
static void
{
}
static int
{
/*
* If this is an aggregating action, there must be neither
* a speculate nor a commit on the action chain.
*/
return (EINVAL);
return (EINVAL);
}
return (EINVAL);
} else {
}
case DTRACEACT_PRINTF:
case DTRACEACT_PRINTA:
case DTRACEACT_SYSTEM:
case DTRACEACT_FREOPEN:
case DTRACEACT_DIFEXPR:
/*
* We know that our arg is a string -- turn it into a
* format.
*/
format = 0;
} else {
}
/*FALLTHROUGH*/
case DTRACEACT_LIBACT:
case DTRACEACT_TRACEMEM:
return (EINVAL);
break;
return (EINVAL);
}
break;
case DTRACEACT_STACK:
}
break;
case DTRACEACT_JSTACK:
/*FALLTHROUGH*/
case DTRACEACT_USTACK:
}
/*
* Save a slot for the pid.
*/
break;
case DTRACEACT_SYM:
case DTRACEACT_MOD:
sizeof (uint64_t)) ||
return (EINVAL);
break;
case DTRACEACT_USYM:
case DTRACEACT_UMOD:
case DTRACEACT_UADDR:
return (EINVAL);
/*
* We have a slot for the pid, plus a slot for the
* argument. To keep things simple (aligned with
* bitness-neutral sizing), we store each as a 64-bit
* quantity.
*/
break;
case DTRACEACT_STOP:
case DTRACEACT_BREAKPOINT:
case DTRACEACT_PANIC:
break;
case DTRACEACT_CHILL:
case DTRACEACT_DISCARD:
case DTRACEACT_RAISE:
return (EINVAL);
break;
case DTRACEACT_EXIT:
return (EINVAL);
break;
case DTRACEACT_SPECULATE:
return (EINVAL);
return (EINVAL);
break;
case DTRACEACT_COMMIT: {
return (EINVAL);
}
return (EINVAL);
break;
}
default:
return (EINVAL);
}
/*
* If this is a data-storing action or a speculate,
* we must be sure that there isn't a commit on the
* action chain.
*/
return (EINVAL);
}
}
}
break;
}
}
} else {
}
return (0);
}
static void
{
act->dta_refcnt--;
} else {
} else {
}
}
}
}
static void
{
/*
* We disable the ECB by removing it from its probe.
*/
/*
* This is the NULL probe; there is nothing to disable.
*/
return;
}
break;
}
} else {
}
}
/*
* The ECB has been disconnected from the probe; now sync to assure
* that all CPUs have seen the change before returning.
*/
dtrace_sync();
/*
* That was the last ECB on the probe; clear the predicate
* cache ID for the probe, disable it and sync one more time
* to assure that we'll never hit it again.
*/
dtrace_sync();
} else {
/*
* There is at least one ECB remaining on the probe. If there
* is _exactly_ one, set the probe's predicate cache ID to be
* the predicate cache ID of the remaining ECB.
*/
if (p != NULL)
}
}
}
static void
{
}
static dtrace_ecb_t *
{
}
/*
* If the provider shows more leg than the consumer is old
* enough to see, we need to enable the appropriate implicit
* predicate bits to prevent the ecb from activating at
* revealing times.
*
* Providers specifying DTRACE_PRIV_USER at register time
* are stating that they need the /proc-style privilege
* model to be enforced, and this is what DTRACE_COND_OWNER
* and DTRACE_COND_ZONEOWNER will then do at probe time.
*/
/*
* If the provider shows us kernel innards and the user
* is lacking sufficient privilege, enable the
* DTRACE_COND_USERMODE implicit predicate.
*/
}
if (dtrace_ecb_create_cache != NULL) {
/*
* If we have a cached ecb, we'll use its action list instead
* of creating our own (saving both time and space).
*/
act->dta_refcnt++;
}
return (ecb);
}
return (NULL);
}
}
return (dtrace_ecb_create_cache = ecb);
}
static int
{
/*
* This probe was created in a generation for which this
* enabling has previously created ECBs; we don't want to
* enable it again, so just kick out.
*/
return (DTRACE_MATCH_NEXT);
}
return (DTRACE_MATCH_DONE);
if (dtrace_ecb_enable(ecb) < 0)
return (DTRACE_MATCH_FAIL);
return (DTRACE_MATCH_NEXT);
}
static dtrace_ecb_t *
{
return (NULL);
}
static dtrace_aggregation_t *
{
return (NULL);
}
/*
* DTrace Buffer Functions
*
* The following functions manipulate DTrace buffers. Most of these functions
* are called in the context of establishing or processing consumer state;
* exceptions are explicitly noted.
*/
/*
* Note: called from cross call context. This function switches the two
* buffers on a given CPU. The atomicity of this operation is assured by
* disabling interrupts while the actual switch takes place; the disabling of
* interrupts serializes the execution with any execution of dtrace_probe() on
* the same CPU.
*/
static void
{
now = dtrace_gethrtime();
buf->dtb_offset = 0;
buf->dtb_errors = 0;
}
/*
* Note: called from cross call context. This function activates a buffer
* on a CPU. As with dtrace_buffer_switch(), the atomicity of the operation
* is guaranteed by the disabling of interrupts.
*/
static void
{
/*
* We might like to assert that the buffer is marked inactive,
* but this isn't necessarily true: the buffer for the CPU
* that processes the BEGIN probe has its buffer activated
* manually. In this case, we take the (harmless) action
* re-clearing the bit INACTIVE bit.
*/
}
}
static int
{
*factor = 1;
if (size > dtrace_nonroot_maxsize &&
return (EFBIG);
do {
continue;
/*
* 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.
*/
continue;
}
goto err;
buf->dtb_offset = 0;
if (flags & DTRACEBUF_NOSWITCH)
continue;
goto err;
return (0);
err:
do {
continue;
desired += 2;
allocated++;
}
allocated++;
}
return (ENOMEM);
}
/*
* Note: called from probe context. This function just increments the drop
* count on a buffer. It has been made a function to allow for the
* possibility of understanding the source of mysterious drop counts. (A
* problem for which one may be particularly disappointed that DTrace cannot
* be used to understand DTrace.)
*/
static void
{
}
/*
* Note: called from probe context. This function is called to reserve space
* in a buffer. If mstate is non-NULL, sets the scratch base and size in the
* mstate. Returns the new offset in the buffer, or a negative value if an
* error has occurred.
*/
static intptr_t
{
return (-1);
return (-1);
}
/*
* Assert that our alignment is off by a number which
* is itself sizeof (uint32_t) aligned.
*/
(sizeof (uint32_t) - 1)));
}
return (-1);
}
return (offs);
return (offs);
}
return (-1);
goto out;
}
/*
* For a ring buffer, life is quite a bit more complicated. Before
* we can store any padding, we need to adjust our wrapping offset.
* (If we've never before wrapped or we're not about to, no adjustment
* is required.)
*/
/*
* We can't fit in the end of the buffer. First, a
* sanity check that we can fit in the buffer at all.
*/
return (-1);
}
/*
* We're going to be storing at the top of the buffer,
* so now we need to deal with the wrapped offset. We
* only reset our wrapped offset to 0 if it is
* currently greater than the current offset. If it
* is less than the current offset, it is because a
* previous allocation induced a wrap -- but the
* allocation didn't subsequently take the space due
* to an error or false predicate evaluation. In this
* case, we'll just leave the wrapped offset alone: if
* the wrapped offset hasn't been advanced far enough
* for this allocation, it will be adjusted in the
* lower loop.
*/
woffs = 0;
} else {
woffs = 0;
}
/*
* Now we know that we're going to be storing to the
* top of the buffer and that there is room for us
* there. We need to clear the buffer from the current
* offset to the end (there may be old gunk there).
*/
/*
* We need to set our offset to zero. And because we
* are wrapping, we need to set the bit indicating as
* much. We can also adjust our needed space back
* down to the space required by the ECB -- we know
* that the top of the buffer is aligned.
*/
offs = 0;
} else {
/*
* There is room for us in the buffer, so we simply
* need to check the wrapped offset.
*/
/*
* The wrapped offset is less than the offset.
* This can happen if we allocated buffer space
* that induced a wrap, but then we didn't
* subsequently take the space due to an error
* or false predicate evaluation. This is
* okay; we know that _this_ allocation isn't
* going to induce a wrap. We still can't
* reset the wrapped offset to be zero,
* however: the space may have been trashed in
* the previous failed probe attempt. But at
* least the wrapped offset doesn't need to
* be adjusted at all...
*/
goto out;
}
}
if (epid == DTRACE_EPIDNONE) {
} else {
}
/*
* We've reached the end of the buffer; we want
* to set the wrapped offset to 0 and break
* out. However, if the offs is 0, then we're
* in a strange edge-condition: the amount of
* space that we want to reserve plus the size
* of the record that we're overwriting is
* greater than the size of the buffer. This
* is problematic because if we reserve the
* space but subsequently don't consume it (due
* to a failed predicate or error) the wrapped
* offset will be 0 -- yet the EPID at offset 0
* will not be committed. This situation is
* relatively easy to deal with: if we're in
* this case, the buffer is indistinguishable
* from one that hasn't wrapped; we need only
* finish the job by clearing the wrapped bit,
* explicitly setting the offset to be 0, and
* zero'ing out the old data in the buffer.
*/
if (offs == 0) {
buf->dtb_offset = 0;
}
woffs = 0;
break;
}
}
/*
* We have a wrapped offset. It may be that the wrapped offset
* has become zero -- that's okay.
*/
}
out:
/*
* Now we can plow the buffer with any necessary padding.
*/
/*
* Assert that our alignment is off by a number which
* is itself sizeof (uint32_t) aligned.
*/
(sizeof (uint32_t) - 1)));
}
return (-1);
}
}
return (offs);
/*
* For ring buffers and fill buffers, the scratch space is always
* the inactive buffer.
*/
return (offs);
}
static void
{
return;
/*
* We need to polish the ring buffer. There are three cases:
*
* - The first (and presumably most common) is that there is no gap
* between the buffer offset and the wrapped offset. In this case,
* there is nothing in the buffer that isn't valid data; we can
* mark the buffer as polished and return.
*
* - The second (less common than the first but still more common
* than the third) is that there is a gap between the buffer offset
* and the wrapped offset, and the wrapped offset is larger than the
* buffer offset. This can happen because of an alignment issue, or
* can happen because of a call to dtrace_buffer_reserve() that
* didn't subsequently consume the buffer space. In this case,
* we need to zero the data from the buffer offset to the wrapped
* offset.
*
* - The third (and least common) is that there is a gap between the
* buffer offset and the wrapped offset, but the wrapped offset is
* _less_ than the buffer offset. This can only happen because a
* call to dtrace_buffer_reserve() induced a wrap, but the space
* was not subsequently consumed. In this case, we need to zero the
* space from the offset to the end of the buffer _and_ from the
* top of the buffer to the wrapped offset.
*/
}
}
}
/*
* This routine determines if data generated at the specified time has likely
* been entirely consumed at user-level. This routine is called to determine
* if an ECB on a defunct probe (but for an active enabling) can be safely
* disabled and destroyed.
*/
static int
{
int i;
for (i = 0; i < NCPU; i++) {
continue;
return (0);
return (0);
return (0);
}
return (1);
}
static void
{
int i;
for (i = 0; i < NCPU; i++) {
continue;
}
}
}
}
/*
* DTrace Enabling Functions
*/
static dtrace_enabling_t *
{
return (enab);
}
static void
{
/*
* We can't add to enablings after we've enabled them, or after we've
* retained them.
*/
return;
}
if (enab->dten_maxdesc == 0) {
} else {
}
}
static void
{
/*
* We're going to create a new ECB description that matches the
* specified ECB in every way, but has the specified probe description.
*/
}
static void
{
int i;
for (i = 0; i < enab->dten_ndesc; i++) {
}
}
static void
{
int i;
for (i = 0; i < enab->dten_ndesc; i++) {
}
}
/*
* If this was a retained enabling, decrement the dts_nretained count
* and take it off of the dtrace_retained list.
*/
dtrace_retained == enab) {
}
if (dtrace_retained == enab) {
if (dtrace_retained != NULL)
}
} else {
}
}
}
static int
{
/*
* We only allow each state to retain dtrace_retain_max enablings.
*/
return (ENOSPC);
state->dts_nretained++;
if (dtrace_retained == NULL) {
return (0);
}
return (0);
}
static int
{
/*
* Iterate over all retained enablings, looking for enablings that
* match the specified state.
*/
int i;
/*
* dtvs_state can only be NULL for helper enablings -- and
* helper enablings can't be retained.
*/
continue;
/*
* Now iterate over each probe description; we're looking for
* an exact match to the specified probe description.
*/
for (i = 0; i < enab->dten_ndesc; i++) {
continue;
continue;
continue;
continue;
/*
* We have a winning probe! Add it to our growing
* enabling.
*/
found = 1;
}
}
return (err);
}
return (0);
}
static void
{
/*
* Iterate over all retained enablings, destroy the enablings retained
* for the specified state.
*/
/*
* dtvs_state can only be NULL for helper enablings -- and
* helper enablings can't be retained.
*/
}
}
}
static int
{
int i = 0;
int total_matched = 0, matched = 0;
for (i = 0; i < enab->dten_ndesc; i++) {
enab->dten_error = 0;
/*
* If a provider failed to enable a probe then get out and
* let the consumer know we failed.
*/
return (EBUSY);
total_matched += matched;
if (enab->dten_error != 0) {
/*
* If we get an error half-way through enabling the
* probes, we kick out -- perhaps with some number of
* them enabled. Leaving enabled probes enabled may
* be slightly confusing for user-level, but we expect
* that no one will attempt to actually drive on in
* the face of such errors. If this is an anonymous
* enabling (indicated with a NULL nmatched pointer),
* we cmn_err() a message. We aren't expecting to
* get such an error -- such as it can exist at all,
* it would be a result of corrupted DOF in the driver
* properties.
*/
"error on %p: %d", (void *)ep,
enab->dten_error);
}
return (enab->dten_error);
}
}
return (0);
}
static void
dtrace_enabling_matchall(void)
{
/*
* Iterate over all retained enablings to see if any probes match
* against them. We only perform this operation on enablings for which
* we have sufficient permissions by virtue of being in the global zone
* or in the same zone as the DTrace client. Because we can be called
* after dtrace_detach() has been called, we cannot assert that there
* are retained enablings. We can safely load from dtrace_retained,
* however: the taskq_destroy() at the end of dtrace_detach() will
* block pending our completion.
*/
}
}
/*
* If an enabling is to be enabled without having matched probes (that is, if
* dtrace_state_go() is to be called on the underlying dtrace_state_t), the
* enabling must be _primed_ by creating an ECB for every ECB description.
* This must be done to assure that we know the number of speculations, the
* number of aggregations, the minimum buffer size needed, etc. before we
* transition out of DTRACE_ACTIVITY_INACTIVE. To do this without actually
* enabling any probes, we create ECBs for every ECB decription, but with a
* NULL probe -- which is exactly what this function does.
*/
static void
{
int i;
continue;
/*
* We don't want to prime an enabling more than once, lest
* we allow a malicious user to induce resource exhaustion.
* (The ECBs that result from priming an enabling aren't
* leaked -- but they also aren't deallocated until the
* consumer state is destroyed.)
*/
if (enab->dten_primed)
continue;
for (i = 0; i < enab->dten_ndesc; i++) {
}
}
}
/*
* Called to indicate that probes should be provided due to retained
* enablings. This is implemented in terms of dtrace_probe_provide(), but it
* must take an initial lap through the enabling calling the dtps_provide()
* entry point explicitly to allow for autocreated probes.
*/
static void
{
int i, all = 0;
all = 1;
}
do {
for (i = 0; i < enab->dten_ndesc; i++) {
/*
* Process the retained enablings again if
* they have changed while we weren't holding
* dtrace_lock.
*/
if (gen != dtrace_retained_gen)
goto retry;
}
}
}
/*
* Called to reap ECBs that are attached to probes from defunct providers.
*/
static void
dtrace_enabling_reap(void)
{
int i;
for (i = 0; i < dtrace_nprobes; i++) {
continue;
continue;
continue;
/*
* We have ECBs on a defunct provider: we want to reap these
* ECBs to allow the provider to unregister. The destruction
* of these ECBs must be done carefully: if we destroy the ECB
* and the consumer later wishes to consume an EPID that
* corresponds to the destroyed ECB (and if the EPID metadata
* has not been previously consumed), the consumer will abort
* processing on the unknown EPID. To reduce (but not, sadly,
* eliminate) the possibility of this, we will only destroy an
* ECB for a defunct provider if, for the state that
* corresponds to the ECB:
*
* (a) There is no speculative tracing (which can effectively
* cache an EPID for an arbitrary amount of time).
*
* (b) The principal buffers have been switched twice since the
* provider became defunct.
*
* (c) The aggregation buffers are of zero size or have been
* switched twice since the provider became defunct.
*
* We use dts_speculates to determine (a) and call a function
* (dtrace_buffer_consumed()) to determine (b) and (c). Note
* that as soon as we've been unable to destroy one of the ECBs
* associated with the probe, we quit trying -- reaping is only
* fruitful in as much as we can destroy all ECBs associated
* with the defunct provider's probes.
*/
if (state->dts_speculates)
break;
break;
break;
}
}
}
/*
* DTrace DOF Functions
*/
/*ARGSUSED*/
static void
{
if (dtrace_err_verbose)
#ifdef DTRACE_ERRDEBUG
#endif
}
/*
* Create DOF out of a currently enabled state. Right now, we only create
* DOF containing the run-time options -- but this could be expanded to create
* complete DOF representing the enabled state.
*/
static dof_hdr_t *
{
sizeof (dof_optdesc_t) * DTRACEOPT_MAX;
dof->dofh_flags = 0;
/*
* Fill in the option section header...
*/
for (i = 0; i < DTRACEOPT_MAX; i++) {
opt[i].dofo_option = i;
}
return (dof);
}
static dof_hdr_t *
{
/*
* First, we're going to copyin() the sizeof (dof_hdr_t).
*/
return (NULL);
}
/*
* Now we'll allocate the entire DOF and copy it in -- provided
* that the length isn't outrageous.
*/
return (NULL);
}
return (NULL);
}
return (NULL);
}
return (dof);
}
static dof_hdr_t *
dtrace_dof_property(const char *name)
{
unsigned int len, i;
/*
* Unfortunately, array of values in .conf files are always (and
* only) interpreted to be integer arrays. We must read our DOF
* as an integer array, and then squeeze it into a byte array.
*/
return (NULL);
for (i = 0; i < len; i++)
return (NULL);
}
return (NULL);
}
if (loadsz >= dtrace_dof_maxsize) {
return (NULL);
}
return (dof);
}
static void
{
}
/*
* Return the dof_sec_t pointer corresponding to a given section index. If the
* index is not valid, dtrace_dof_error() is called and NULL is returned. If
* a type other than DOF_SECT_NONE is specified, the header is checked against
* this type and NULL is returned if the types do not match.
*/
static dof_sec_t *
{
if (i >= dof->dofh_secnum) {
return (NULL);
}
return (NULL);
}
return (NULL);
}
return (sec);
}
static dtrace_probedesc_t *
{
return (NULL);
}
return (NULL);
}
return (NULL);
}
return (NULL);
return (NULL);
}
return (NULL);
}
return (NULL);
}
return (NULL);
}
return (desc);
}
static dtrace_difo_t *
{
int i, l, n;
static const struct {
int section;
int bufoffs;
int lenoffs;
int entsize;
int align;
const char *msg;
} difo[] = {
sizeof (dif_instr_t), "multiple DIF sections" },
sizeof (uint64_t), "multiple integer tables" },
sizeof (char), "multiple string tables" },
sizeof (uint_t), "multiple variable tables" },
{ DOF_SECT_NONE, 0, 0, 0, NULL }
};
return (NULL);
}
return (NULL);
}
return (NULL);
}
for (l = 0; l < n; l++) {
void **bufp;
goto err; /* invalid section link */
goto err;
}
continue;
goto err;
}
goto err;
}
goto err;
}
goto err;
}
if (subsec->dofs_entsize != 0 &&
goto err;
}
if (subsec->dofs_entsize != 0)
break;
}
/*
* If we encounter a loadable DIFO sub-section that is not
* known to us, assume this is a broken program and fail.
*/
goto err;
}
}
/*
* We can't have a DIF object without DIF text.
*/
goto err;
}
/*
* Before we validate the DIF object, run through the variable table
* looking for the strings -- if any of their size are under, we'll set
* their size to be the system-wide default string size. Note that
* this should _not_ happen if the "strsize" option has been set --
* in this case, the compiler should have set the size to reflect the
* setting of the option.
*/
for (i = 0; i < dp->dtdo_varlen; i++) {
dtrace_diftype_t *t = &v->dtdv_type;
if (v->dtdv_id < DIF_VAR_OTHER_UBASE)
continue;
}
goto err;
return (dp);
err:
return (NULL);
}
static dtrace_predicate_t *
{
return (NULL);
return (dtrace_predicate_create(dp));
}
static dtrace_actdesc_t *
{
return (NULL);
}
return (NULL);
}
return (NULL);
}
return (NULL);
}
return (NULL);
}
return (NULL);
}
if ((DTRACEACT_ISPRINTFLIKE(kind) &&
(kind != DTRACEACT_PRINTA ||
(kind == DTRACEACT_DIFEXPR &&
uint64_t i;
/*
* The argument to these actions is an index into the
* DOF string table. For printf()-like actions, this
* is the format string. For print(), this is the
* CTF type of the expression result.
*/
goto err;
if (str[i] == '\0')
break;
}
goto err;
}
goto err;
}
} else {
if (kind == DTRACEACT_PRINTA) {
arg = 0;
} else {
}
}
} else {
}
continue;
goto err;
goto err;
}
return (first);
err:
}
return (NULL);
}
static dtrace_ecbdesc_t *
{
return (NULL);
}
return (NULL);
}
return (NULL);
goto err;
goto err;
goto err;
}
goto err;
goto err;
}
return (ep);
err:
return (NULL);
}
/*
* Apply the relocations from the specified 'sec' (a DOF_SECT_URELHDR) to the
* specified DOF. At present, this amounts to simply adding 'ubase' to the
* site of any user SETX relocations to account for load object base address.
* In the future, if we need other relocations, this function can be extended.
*/
static int
{
dof_relodesc_t *r;
uint_t i, n;
return (-1);
}
return (-1); /* dtrace_dof_error() has been called already */
return (-1);
}
for (i = 0; i < n; i++) {
switch (r->dofr_type) {
case DOF_RELO_NONE:
break;
case DOF_RELO_SETX:
return (-1);
}
return (-1);
}
break;
default:
return (-1);
}
}
return (0);
}
/*
* The dof_hdr_t passed to dtrace_dof_slurp() should be a partially validated
* header: it should be at the front of a memory region that is at least
* sizeof (dof_hdr_t) in size -- and then at least dof_hdr.dofh_loadsz in
* size. It need not be validated in any other way.
*/
static int
{
uint_t i;
/*
* Check the DOF header identification bytes. In addition to checking
* we can use them later without fear of regressing existing binaries.
*/
DOF_MAG_STRING, DOF_MAG_STRLEN) != 0) {
return (-1);
}
return (-1);
}
return (-1);
}
return (-1);
}
return (-1);
}
return (-1);
}
return (-1);
}
for (i = DOF_ID_PAD; i < DOF_ID_SIZE; i++) {
if (dof->dofh_ident[i] != 0) {
return (-1);
}
}
return (-1);
}
if (dof->dofh_secsize == 0) {
return (-1);
}
/*
* Check that the section headers don't exceed the amount of DOF
* data. Note that we cast the section size and number of sections
* to uint64_t's to prevent possible overflow in the multiplication.
*/
return (-1);
}
return (-1);
}
return (-1);
}
/*
* Take an initial pass through the section headers to be sure that
* the headers don't have stray offsets. If the 'noprobes' flag is
* set, do not permit sections relating to providers, probes, or args.
*/
for (i = 0; i < dof->dofh_secnum; i++) {
if (noprobes) {
case DOF_SECT_PROVIDER:
case DOF_SECT_PROBES:
case DOF_SECT_PRARGS:
case DOF_SECT_PROFFS:
"for enabling");
return (-1);
}
}
"flag unset");
return (-1);
}
continue; /* just ignore non-loadable sections */
return (-1);
}
return (-1);
}
return (-1);
}
return (-1);
}
}
/*
* Take a second pass through the sections and locate and perform any
* relocations that are present. We do this after the first pass to
* be sure that all sections have had their headers validated.
*/
for (i = 0; i < dof->dofh_secnum; i++) {
continue; /* skip sections that are not loadable */
case DOF_SECT_URELHDR:
return (-1);
break;
}
}
for (i = 0; i < dof->dofh_secnum; i++) {
continue;
return (-1);
}
}
return (0);
}
/*
* Process DOF for any options. This routine assumes that the DOF has been
* at least processed by dtrace_dof_slurp().
*/
static int
{
int i, rval;
for (i = 0; i < dof->dofh_secnum; i++) {
continue;
"option description");
return (EINVAL);
}
return (EINVAL);
}
if (entsize < sizeof (dof_optdesc_t)) {
return (EINVAL);
}
return (EINVAL);
}
return (EINVAL);
}
return (rval);
}
}
}
return (0);
}
/*
* DTrace Consumer State Functions
*/
int
{
void *base;
int i;
return (ENOMEM);
hashsize--;
/*
* Set all of our hash buckets to point to the single sink, and (if
* it hasn't already been set), set the sink's hash value to be the
* sink sentinel value. The sink is needed for dynamic variable
* lookups to know that they have iterated over an entire, valid hash
* chain.
*/
for (i = 0; i < hashsize; i++)
/*
* Determine number of active CPUs. Divide free list evenly among
* active CPUs.
*/
start = (dtrace_dynvar_t *)
for (i = 0; i < NCPU; i++) {
/*
* If we don't even have enough chunks to make it once through
* NCPUs, we're just going to allocate everything to the first
* CPU. And if we're on the last CPU, we're going to allocate
* whatever is left over. In either case, we set the limit to
* be the limit of the dynamic variable space.
*/
} else {
}
for (;;) {
break;
}
if (maxper == 0)
break;
}
return (0);
}
void
{
return;
}
static void
{
/*
* Logical XOR, where are you?
*/
if (vstate->dtvs_nglobals > 0) {
sizeof (dtrace_statvar_t *));
}
if (vstate->dtvs_ntlocals > 0) {
sizeof (dtrace_difv_t));
}
if (vstate->dtvs_nlocals > 0) {
sizeof (dtrace_statvar_t *));
}
}
static void
{
return;
}
static void
{
dtrace_sync();
now = dtrace_gethrtime();
return;
/*
* We must be sure that dts_alive never appears to be less than the
* value upon entry to dtrace_state_deadman(), and because we lack a
* dtrace_cas64(), we cannot store to it atomically. We thus instead
* store INT64_MAX to it, followed by a memory barrier, followed by
* the new value. This assures that dts_alive never appears to be
* less than its true value, regardless of the order in which the
* stores to the underlying storage are issued.
*/
}
{
char c[30];
VM_BESTFIT | VM_SLEEP);
return (NULL);
}
} else {
}
/*
* We allocate NCPU buffers. On the one hand, this can be quite
* a bit of memory per instance (nearly 36K on a Starcat). On the
* other hand, it saves an additional memory reference in the probe
* path.
*/
for (i = 0; i < DTRACEOPT_MAX; i++)
/*
* Set the default options.
*/
/*
* Depending on the user credentials, we set flag bits which alter probe
* visibility or the amount of destructiveness allowed. In the case of
* actual anonymous tracing, or the possession of all privileges, all of
* the normal checks are bypassed.
*/
} else {
/*
* Set up the credentials for this instantiation. We take a
* hold on the credential to prevent it from disappearing on
* us; this in turn prevents the zone_t referenced by this
* credential from disappearing. This means that we can
* examine the credential and the zone from probe context.
*/
/*
* CRA_PROC means "we have *some* privilege for dtrace" and
* unlocks the use of variables like pid, zonename, etc.
*/
}
/*
* dtrace_user allows use of syscall and profile providers.
* extend the scope to include additional visibility and
* destructive power.
*/
}
}
/*
* If we have all privs in whatever zone this is,
* we can do destructive things to processes which
* have altered credentials.
*/
}
}
/*
* Holding the dtrace_kernel privilege also implies that
* the user has the dtrace_user privilege from a visibility
* perspective. But without further privileges, some
* destructive actions are not available.
*/
/*
* Make all probes in all zones visible. However,
* this doesn't mean that all actions become available
* to all zones.
*/
/*
* Holding proc_owner means that destructive actions
* for *this* zone are allowed.
*/
/*
* Holding proc_zone means that destructive actions
*/
/*
* If we have all privs in whatever zone this is,
* we can do destructive things to processes which
* have altered credentials.
*/
}
}
/*
* Holding the dtrace_proc privilege gives control over fasttrap
* and pid providers. We need to grant wider destructive
* proc_zone.
*/
}
}
return (state);
}
static int
{
return (0);
if (which == DTRACEOPT_SPECSIZE)
if (which == DTRACEOPT_BUFSIZE) {
flags |= DTRACEBUF_RING;
flags |= DTRACEBUF_FILL;
}
/*
* The size must be 8-byte aligned. If the size is not 8-byte
* aligned, drop it down by the difference.
*/
/*
* Buffers always must be large enough to accommodate
* their prereserved space. We return E2BIG instead
* of ENOMEM in this case to allow for user-level
* software to differentiate the cases.
*/
return (E2BIG);
}
return (rval);
}
return (rval);
continue;
}
return (ENOMEM);
}
static int
{
int rval, i;
DTRACEOPT_BUFSIZE)) != 0)
return (rval);
DTRACEOPT_AGGSIZE)) != 0)
return (rval);
for (i = 0; i < state->dts_nspeculations; i++) {
return (rval);
}
return (0);
}
static void
{
state->dts_reserve = 0;
return;
/*
* If our buffer policy is a "fill" buffer policy, we need to set the
* prereserved space to be the space required by the END probes.
*/
continue;
}
}
static int
{
goto out;
}
/*
* Before we can perform any checks, we must prime all of the
* retained enablings that correspond to this state.
*/
goto out;
}
/*
* Now we want to do is try to allocate our speculations.
* We do not automatically resize the number of speculations; if
* this fails, we will fail the operation.
*/
goto out;
}
goto out;
}
for (i = 0; i < nspec; i++) {
goto err;
}
}
goto out;
}
goto out;
}
/*
* We want "grabanon" to be set in the grabbed state, so we'll
* copy that option value from the grabbing state into the
* grabbed state.
*/
/*
* If the anonymous state is active (as it almost certainly
* is if the anonymous enabling ultimately matched anything),
* we don't allow any further option processing -- but we
* don't return failure.
*/
goto out;
}
opt[DTRACEOPT_AGGSIZE] != 0) {
/*
* We're not going to create an aggregation buffer
* because we don't have any ECBs that contain
* aggregations -- set this option to 0.
*/
opt[DTRACEOPT_AGGSIZE] = 0;
} else {
/*
* If we have an aggregation buffer, we must also have
* a buffer to use as scratch.
*/
}
}
}
opt[DTRACEOPT_SPECSIZE] != 0) {
if (!state->dts_speculates) {
/*
* We're not going to create speculation buffers
* because we don't have any ECBs that actually
* speculate -- set the speculation size to 0.
*/
opt[DTRACEOPT_SPECSIZE] = 0;
}
}
/*
* The bare minimum size for any buffer that we're actually going to
* do anything to is sizeof (uint64_t).
*/
/*
* A buffer size has been explicitly set to 0 (or to a size
* that will be adjusted to 0) and we need the space -- we
* need to return failure. We return ENOSPC to differentiate
* it from failing to allocate a buffer due to failure to meet
* the reserve (for which we return E2BIG).
*/
goto out;
}
goto err;
do {
if (rval == 0)
break;
goto err;
} while (sz >>= 1);
if (rval != 0)
goto err;
if (opt[DTRACEOPT_CLEANRATE] == 0)
/*
* We don't have kernel privs but we have at least one call
* to getf(); we need to bump our zone's count, and (if
* this is the first enabling to have an unprivileged call
* to getf()) we need to hook into closef().
*/
if (dtrace_getf++ == 0) {
}
}
/*
* Now it's time to actually fire the BEGIN probe. We need to disable
* interrupts here both to record the CPU on which we fired the BEGIN
* probe (the data from this CPU will be processed first at user
* level) and to manually activate the buffer for this CPU.
*/
/*
* We may have had an exit action from a BEGIN probe; only change our
* state to ACTIVE if we're still in WARMUP.
*/
/*
* Regardless of whether or not now we're in ACTIVE or DRAINING, we
* want each CPU to transition its principal buffer out of the
* INACTIVE state. Doing this assures that no CPU will suddenly begin
* processing an ECB halfway down a probe's ECB chain; all CPUs will
* atomically transition from processing none of a state's ECBs to
* processing all of them.
*/
goto out;
err:
goto out;
}
for (i = 0; i < state->dts_nspeculations; i++) {
break;
}
state->dts_nspeculations = 0;
out:
return (rval);
}
static int
{
return (EINVAL);
/*
* We'll set the activity to DTRACE_ACTIVITY_DRAINING, and issue a sync
* to be sure that every CPU has seen it. See below for the details
* on why this is done.
*/
dtrace_sync();
/*
* By this point, it is impossible for any CPU to be still processing
* with DTRACE_ACTIVITY_ACTIVE. We can thus set our activity to
* DTRACE_ACTIVITY_COOLDOWN and know that we're not racing with any
* other CPU in dtrace_buffer_reserve(). This allows dtrace_probe()
* and callees to know that the activity is DTRACE_ACTIVITY_COOLDOWN
* iff we're in the END probe.
*/
dtrace_sync();
/*
* Finally, we can release the reserve and call the END probe. We
* disable interrupts across calling the END probe to allow us to
* return the CPU on which we actually called the END probe. This
* allows user-land to be sure that this CPU's principal buffer is
* processed last.
*/
state->dts_reserve = 0;
dtrace_sync();
/*
* We don't have kernel privs but we have at least one call
* to getf(); we need to lower our zone's count, and (if
* this is the last enabling to have an unprivileged call
* to getf()) we need to clear the closef() hook.
*/
ASSERT(dtrace_getf > 0);
if (--dtrace_getf == 0)
}
return (0);
}
static int
{
return (EBUSY);
if (option >= DTRACEOPT_MAX)
return (EINVAL);
return (EINVAL);
switch (option) {
case DTRACEOPT_DESTRUCTIVE:
return (EACCES);
break;
case DTRACEOPT_BUFSIZE:
case DTRACEOPT_DYNVARSIZE:
case DTRACEOPT_AGGSIZE:
case DTRACEOPT_SPECSIZE:
case DTRACEOPT_STRSIZE:
if (val < 0)
return (EINVAL);
/*
* If this is an otherwise negative value, set it to
* the highest multiple of 128m less than LONG_MAX.
* Technically, we're adjusting the size without
* regard to the buffer resizing policy, but in fact,
* this has no effect -- if we set the buffer size to
* ~LONG_MAX and the buffer policy is ultimately set to
* be "manual", the buffer allocation is guaranteed to
* fail, if only because the allocation requires two
* buffers. (We set the the size to the highest
* multiple of 128m because it ensures that the size
* will remain a multiple of a megabyte when
* repeatedly halved -- all the way down to 15m.)
*/
}
}
return (0);
}
static void
{
/*
* First, retract any retained enablings for this state.
*/
/*
* We have managed to come into dtrace_state_destroy() on a
* hot enabling -- almost certainly because of a disorderly
* shutdown of a consumer. (That is, a consumer that is
* exiting without having called dtrace_stop().) In this case,
* we're going to set our activity to be KILLED, and then
* issue a sync to be sure that everyone is out of probe
* context before we start blowing away ECBs.
*/
dtrace_sync();
}
/*
* Release the credential hold we took in dtrace_state_create().
*/
/*
* Now we can safely disable and destroy any enabled probes. Because
* any DTRACE_PRIV_KERNEL probes may actually be slowing our progress
* (especially if they're all enabled), we take two passes through the
* ECBs: in the first, we disable just DTRACE_PRIV_KERNEL probes, and
* in the second we disable whatever is left over.
*/
continue;
continue;
}
}
if (!match)
break;
}
/*
* Before we free the buffers, perform one more sync to assure that
* every CPU is out of probe context.
*/
dtrace_sync();
for (i = 0; i < nspec; i++)
#ifdef DEBUG
for (i = 0; i < state->dts_naggregations; i++)
#endif
}
for (i = 0; i < nspec; i++)
}
/*
* DTrace Anonymous Enabling Functions
*/
static dtrace_state_t *
dtrace_anon_grab(void)
{
return (NULL);
}
return (state);
}
static void
dtrace_anon_property(void)
{
int i, rv;
char c[32]; /* enough for "dof-data-" + digits */
for (i = 0; ; i++) {
(void) snprintf(c, sizeof (c), "dof-data-%d", i);
dtrace_err_verbose = 1;
dtrace_err_verbose = 0;
break;
}
/*
* We want to create anonymous state, so we need to transition
* the kernel debugger to indicate that DTrace is active. If
* this fails (e.g. because the debugger has modified text in
* some way), we won't continue with the processing.
*/
if (kdi_dtrace_set(KDI_DTSET_DTRACE_ACTIVATE) != 0) {
"enabling ignored.");
break;
}
/*
* If we haven't allocated an anonymous state, we'll do so now.
*/
/*
* This basically shouldn't happen: the only
* failure mode from dtrace_state_create() is a
* failure of ddi_soft_state_zalloc() that
* itself should never happen. Still, the
* interface allows for a failure mode, and
* we want to fail as gracefully as possible:
* we'll emit an error message and cease
* processing anonymous state in this case.
*/
"anonymous state");
break;
}
}
if (rv == 0)
dtrace_err_verbose = 0;
if (rv != 0) {
/*
* This is malformed DOF; chuck any anonymous state
* that we created.
*/
break;
}
}
int rval;
/*
* dtrace_enabling_retain() can only fail because we are
* trying to retain more enablings than are allowed -- but
* we only have one anonymous enabling, and we are guaranteed
* to be allowed at least one retained enabling; we assert
* that dtrace_enabling_retain() returns success.
*/
}
}
/*
* DTrace Helper Functions
*/
static void
{
return;
/*
* What would a tracing framework be without its own tracing
* framework? (Well, a hell of a lot simpler, for starters...)
*/
/*
* Iterate until we can allocate a slot in the trace buffer.
*/
do {
} else {
}
/*
* We have our slot; fill it in.
*/
next = 0;
}
for (i = 0; i < vstate->dtvs_nlocals; i++) {
continue;
ent->dtht_locals[i] =
}
}
static uint64_t
{
return (0);
return (0);
/*
* Now iterate over each helper. If its predicate evaluates to 'true',
* we'll call the corresponding actions. Note that the below calls
* to dtrace_dif_emulate() may set faults in machine state. This is
* okay: our caller (the outer dtrace_dif_emulate()) will simply plow
* the stored DIF offset with its own (which is the desired behavior).
* Also, note the calls to dtrace_dif_emulate() may allocate scratch
* from machine state; this is okay, too.
*/
if (trace)
goto next;
if (*flags & CPU_DTRACE_FAULT)
goto err;
}
for (i = 0; i < helper->dtha_nactions; i++) {
if (trace)
if (*flags & CPU_DTRACE_FAULT)
goto err;
}
next:
if (trace)
}
if (trace)
/*
* Restore the arg0 that we saved upon entry.
*/
return (rval);
err:
if (trace)
/*
* Restore the arg0 that we saved upon entry.
*/
return (NULL);
}
static void
{
int i;
for (i = 0; i < helper->dtha_nactions; i++) {
}
}
static int
{
int i;
return (EINVAL);
for (i = 0; i < DTRACE_NHELPER_ACTIONS; i++) {
if (h->dtha_generation == gen) {
} else {
}
} else {
last = h;
}
}
}
/*
* Interate until we've cleared out all helper providers with the
* given generation number.
*/
for (;;) {
/*
* Look for a helper provider with the right generation. We
* have to start back at the beginning of the list each time
* because we drop dtrace_lock. It's unlikely that we'll make
* more than two passes.
*/
for (i = 0; i < help->dthps_nprovs; i++) {
break;
}
/*
* If there were no matches, we're done.
*/
if (i == help->dthps_nprovs)
break;
/*
* Move the last helper provider into this slot.
*/
help->dthps_nprovs--;
/*
* If we have a meta provider, remove this helper provider.
*/
if (dtrace_meta_pid != NULL) {
p->p_pid);
}
}
return (0);
}
static int
{
int err = 0, i;
for (i = 0; i < helper->dtha_nactions; i++)
return (err == 0);
}
static int
{
return (EINVAL);
count++;
break;
}
/*
* If we already have dtrace_helper_actions_max helper actions for this
* helper action type, we'll refuse to add a new one.
*/
if (count >= dtrace_helper_actions_max)
return (ENOSPC);
}
goto err;
goto err;
nactions++;
}
}
if (!dtrace_helper_validate(helper))
goto err;
} else {
}
}
return (0);
err:
return (EINVAL);
}
static void
{
/*
* If the dtrace module is loaded but not attached, or if
* there aren't isn't a meta provider registered to deal with
* these provider descriptions, we need to postpone creating
* the actual providers until later.
*/
dtrace_deferred_pid != help) {
if (dtrace_deferred_pid != NULL)
}
/*
* If the dtrace module is loaded and we have a particular
* helper provider description, pass that off to the
* meta provider.
*/
} else {
/*
* Otherwise, just pass all the helper provider descriptions
* off to the meta provider.
*/
int i;
for (i = 0; i < help->dthps_nprovs; i++) {
p->p_pid);
}
}
}
static int
{
uint_t tmp_maxprovs, i;
/*
* If we already have dtrace_helper_providers_max helper providers,
* we're refuse to add a new one.
*/
return (ENOSPC);
/*
* Check to make sure this isn't a duplicate.
*/
for (i = 0; i < help->dthps_nprovs; i++) {
return (EALREADY);
}
/*
* Allocate a bigger table for helper providers if it's already full.
*/
if (help->dthps_maxprovs == 0)
else
sizeof (dtrace_helper_provider_t *), KM_SLEEP);
sizeof (dtrace_helper_provider_t *));
sizeof (dtrace_helper_provider_t *));
}
}
help->dthps_nprovs++;
return (0);
}
static void
{
} else {
}
}
static int
{
return (-1);
}
/*
* The section needs to be large enough to contain the DOF provider
* structure appropriate for the given version.
*/
sizeof (dof_provider_t))) {
return (-1);
}
return (-1);
return (-1);
return (-1);
}
if (prb_sec->dofs_entsize == 0 ||
return (-1);
}
return (-1);
}
return (-1);
}
return (-1);
}
return (-1);
}
/*
* Take a pass through the probes to check for errors.
*/
for (j = 0; j < nprobes; j++) {
return (-1);
}
return (-1);
}
return (-1);
}
/*
* The offset count must not wrap the index, and the offsets
* must also not overflow the section's data.
*/
probe->dofpr_offidx ||
return (-1);
}
/*
* If there's no is-enabled offset section, make sure
* there aren't any is-enabled offsets. Otherwise
* perform the same checks as for probe offsets
* (immediately above).
*/
if (probe->dofpr_enoffidx != 0 ||
probe->dofpr_nenoffs != 0) {
"offsets with null section");
return (-1);
}
} else if (probe->dofpr_enoffidx +
"offset");
return (-1);
}
"is-enabled offsets");
return (-1);
}
} else if (probe->dofpr_noffs == 0) {
return (-1);
}
probe->dofpr_argidx ||
return (-1);
}
for (k = 0; k < probe->dofpr_nargc; k++) {
"native argument type");
return (-1);
}
if (typesz > DTRACE_ARGTYPELEN) {
"argument type too long");
return (-1);
}
}
for (k = 0; k < probe->dofpr_xargc; k++) {
"native argument index");
return (-1);
}
"translated argument type");
return (-1);
}
if (typesz > DTRACE_ARGTYPELEN) {
"type too long");
return (-1);
}
}
}
return (0);
}
static int
{
return (rv);
}
/*
* Look for helper providers and validate their descriptions.
*/
for (i = 0; i < dof->dofh_secnum; i++) {
continue;
return (-1);
}
nprovs++;
}
}
/*
* Now we need to walk through the ECB descriptions in the enabling.
*/
for (i = 0; i < enab->dten_ndesc; i++) {
continue;
continue;
continue;
ep)) != 0) {
/*
* Adding this helper action failed -- we are now going
* to rip out the entire generation and return failure.
*/
return (-1);
}
nhelpers++;
}
destroy = 0;
}
}
if (destroy)
return (gen);
}
static dtrace_helpers_t *
{
p->p_dtrace_helpers = help;
return (help);
}
static void
dtrace_helpers_destroy(void)
{
int i;
ASSERT(dtrace_helpers > 0);
help = p->p_dtrace_helpers;
/*
* We're now going to lose the help from this process.
*/
p->p_dtrace_helpers = NULL;
dtrace_sync();
/*
* Destory the helper actions.
*/
for (i = 0; i < DTRACE_NHELPER_ACTIONS; i++) {
dtrace_helper_action_t *h, *next;
h = next;
}
}
/*
* Destroy the helper providers.
*/
if (help->dthps_maxprovs > 0) {
if (dtrace_meta_pid != NULL) {
for (i = 0; i < help->dthps_nprovs; i++) {
}
} else {
help == dtrace_deferred_pid);
/*
* Remove the helper from the deferred list.
*/
if (dtrace_deferred_pid == help) {
}
}
for (i = 0; i < help->dthps_nprovs; i++) {
}
sizeof (dtrace_helper_provider_t *));
}
sizeof (dtrace_helper_action_t *) * DTRACE_NHELPER_ACTIONS);
}
static void
{
ASSERT(dtrace_helpers > 0);
/*
* Duplicate the helper actions.
*/
for (i = 0; i < DTRACE_NHELPER_ACTIONS; i++) {
continue;
KM_SLEEP);
}
for (j = 0; j < new->dtha_nactions; j++) {
}
} else {
}
}
}
/*
* Duplicate the helper providers and register them with the
* DTrace framework.
*/
if (help->dthps_nprovs > 0) {
sizeof (dtrace_helper_provider_t *), KM_SLEEP);
for (i = 0; i < newhelp->dthps_nprovs; i++) {
}
hasprovs = 1;
}
if (hasprovs)
}
/*
* DTrace Hook Functions
*/
static void
{
/*
* We're going to call each providers per-module provide operation
* specifying only this module.
*/
/*
* If we have any retained enablings, we need to match against them.
* Enabling probes requires that cpu_lock be held, and we cannot hold
* cpu_lock here -- it is legal for cpu_lock to be held when loading a
* module. (In particular, this happens when loading scheduling
* classes.) So if we have any retained enablings, we need to dispatch
* our task queue to do the match for us.
*/
if (dtrace_retained == NULL) {
return;
}
(void) taskq_dispatch(dtrace_taskq,
/*
* And now, for a little heuristic sleaze: in general, we want to
* match modules as soon as they load. However, we cannot guarantee
* this, because it would lead us to the lock ordering violation
* outlined above. The common case, of course, is that cpu_lock is
* _not_ held -- so we delay here for a clock tick, hoping that that's
* long enough for the task queue to do its work. If it's not, it's
* not a serious problem -- it just means that the module that we
* just loaded may not be immediately instrumentable.
*/
delay(1);
}
static void
{
if (dtrace_bymod == NULL) {
/*
* The DTrace module is loaded (obviously) but not attached;
* we don't have any work to do.
*/
return;
}
/*
* This shouldn't _actually_ be possible -- we're
* unloading a module that has an enabled probe in it.
* (It's normally up to the provider to make sure that
* this can't happen.) However, because dtps_enable()
* doesn't have a failure mode, there can be an
* assert, but we're not going to disable the
* probe, either.
*/
if (dtrace_err_verbose) {
}
return;
}
}
} else {
}
}
/*
* We've removed all of the module's probes from the hash chains and
* from the probe array. Now issue a dtrace_sync() to be sure that
* everyone has cleared out from any probe array processing.
*/
dtrace_sync();
}
}
void
dtrace_suspend(void)
{
}
void
dtrace_resume(void)
{
}
static int
{
switch (what) {
case CPU_CONFIG: {
/*
* For now, we only allocate a new buffer for anonymous state.
*/
break;
break;
c = opt[DTRACEOPT_CPU];
break;
/*
* Regardless of what the actual policy is, we're going to
* temporarily set our resize policy to be manual. We're
* also going to temporarily set our CPU option to denote
* the newly configured CPU.
*/
(void) dtrace_state_buffers(state);
opt[DTRACEOPT_CPU] = c;
break;
}
case CPU_UNCONFIG:
/*
* We don't free the buffer in the CPU_UNCONFIG case. (The
* buffer will be freed when the consumer exits.)
*/
break;
default:
break;
}
return (0);
}
static void
{
}
static void
{
if (dtrace_toxranges >= dtrace_toxranges_max) {
if (osize == 0) {
ASSERT(dtrace_toxranges_max == 0);
dtrace_toxranges_max = 1;
} else {
dtrace_toxranges_max <<= 1;
}
if (dtrace_toxrange != NULL) {
}
}
}
static void
{
/*
* When we have unprivileged (that is, non-DTRACE_CRV_KERNEL) enablings
* that contain calls to getf(), this routine will be called on every
* closef() before either the underlying vnode is released or the
* file_t itself is freed. By the time we are here, it is essential
* that the file_t can no longer be accessed from a call to getf()
* in probe context -- that assures that a dtrace_sync() can be used
* to clear out any enablings referring to the old structures.
*/
dtrace_sync();
}
/*
* DTrace Driver Cookbook Functions
*/
/*ARGSUSED*/
static int
{
sizeof (dtrace_state_t), 0) != 0) {
return (DDI_FAILURE);
}
return (DDI_FAILURE);
}
dtrace_devi = devi;
1, INT_MAX, 0);
if (dtrace_retain_max < 1) {
"setting to 1", dtrace_retain_max);
dtrace_retain_max = 1;
}
/*
* Now discover our toxic ranges.
*/
/*
* Before we register ourselves as a provider to our own framework,
* we would like to assert that dtrace_provider is NULL -- but that's
* not true if we were loaded as a dependency of a DTrace provider.
* Once we've registered, we can assert that dtrace_provider is our
* pseudo provider.
*/
/*
* If there are already providers, we must ask them to provide their
* probes, and then match any anonymous enabling against them. Note
* that there should be no other retained enablings at this time:
* the only retained enablings at this time should be the anonymous
* enabling.
*/
/*
* We couldn't hold cpu_lock across the above call to
* dtrace_enabling_provide(), but we must hold it to actually
* enable the probes. We have to drop all of our locks, pick
* up cpu_lock, and regain our locks before matching the
* retained anonymous enabling.
*/
}
/*
* If we created any anonymous state, set it going now.
*/
}
return (DDI_SUCCESS);
}
/*ARGSUSED*/
static int
{
return (0);
/*
* If this wasn't an open with the "helper" minor, then it must be
* the "dtrace" minor.
*/
return (ENXIO);
/*
* If no DTRACE_PRIV_* bits are set in the credential, then the
* caller lacks sufficient permission to do anything with DTrace.
*/
if (priv == DTRACE_PRIV_NONE)
return (EACCES);
/*
* Ask all providers to provide all their probes.
*/
dtrace_opens++;
/*
* If the kernel debugger is active (that is, if the kernel debugger
* modified text in some way), we won't allow the open.
*/
if (kdi_dtrace_set(KDI_DTSET_DTRACE_ACTIVATE) != 0) {
dtrace_opens--;
return (EBUSY);
}
/*
* If DTrace helper tracing is enabled, we need to allocate the
* trace buffer and initialize the values.
*/
}
return (EAGAIN);
}
return (0);
}
/*ARGSUSED*/
static int
{
if (minor == DTRACEMNRN_HELPER)
return (0);
/*
* There is anonymous state. Destroy that first.
*/
}
if (dtrace_helptrace_disable) {
/*
* If we have been told to disable helper tracing, set the
* buffer to NULL before calling into dtrace_state_destroy();
* we take advantage of its dtrace_sync() to know that no
* CPU is in probe context with enabled helper tracing
* after it returns.
*/
}
ASSERT(dtrace_opens > 0);
/*
* Only relinquish control of the kernel debugger interface when there
* are no consumers and no anonymous enablings.
*/
}
return (0);
}
/*ARGSUSED*/
static int
{
int rval;
switch (cmd) {
case DTRACEHIOC_ADDDOF:
return (EFAULT);
}
/*FALLTHROUGH*/
case DTRACEHIOC_ADD: {
return (rval);
/*
* dtrace_helper_slurp() takes responsibility for the dof --
* it may free it now or it may save it and free it later.
*/
rval = 0;
} else {
}
return (rval);
}
case DTRACEHIOC_REMOVE: {
return (rval);
}
default:
break;
}
return (ENOTTY);
}
/*ARGSUSED*/
static int
{
int rval;
if (minor == DTRACEMNRN_HELPER)
}
switch (cmd) {
case DTRACEIOC_PROVIDER: {
return (EFAULT);
break;
}
return (ESRCH);
return (EFAULT);
return (0);
}
case DTRACEIOC_EPROBE: {
void *buf;
int nrecs;
return (EFAULT);
return (EINVAL);
}
return (EINVAL);
}
epdesc.dtepd_nrecs = 0;
continue;
}
/*
* Now that we have the size, we need to allocate a temporary
* buffer in which to store the complete description. We need
* the temporary buffer to be able to drop dtrace_lock()
* across the copyout(), below.
*/
size = sizeof (dtrace_eprobedesc_t) +
continue;
if (nrecs-- == 0)
break;
sizeof (dtrace_recdesc_t));
dest += sizeof (dtrace_recdesc_t);
}
return (EFAULT);
}
return (0);
}
case DTRACEIOC_AGGDESC: {
int nrecs;
void *buf;
return (EFAULT);
return (EINVAL);
}
aggdesc.dtagd_nrecs = 0;
/*
* If this action has a record size of zero, it
* denotes an argument to the aggregating action.
* Because the presence of this record doesn't (or
* shouldn't) affect the way the data is interpreted,
* we don't copy it out to save user-level the
* confusion of dealing with a zero-length record.
*/
continue;
}
break;
}
/*
* Now that we have the size, we need to allocate a temporary
* buffer in which to store the complete description. We need
* the temporary buffer to be able to drop dtrace_lock()
* across the copyout(), below.
*/
size = sizeof (dtrace_aggdesc_t) +
/*
* See the comment in the above loop for why we pass
* over zero-length records.
*/
continue;
}
if (nrecs-- == 0)
break;
dest += sizeof (dtrace_recdesc_t);
break;
}
return (EFAULT);
}
return (0);
}
case DTRACEIOC_ENABLE: {
int err = 0;
*rv = 0;
/*
* If a NULL argument has been passed, we take this as our
* cue to reevaluate our enablings.
*/
return (0);
}
return (rval);
return (EBUSY);
}
return (EINVAL);
}
return (rval);
}
} else {
}
return (err);
}
case DTRACEIOC_REPLICATE: {
int err;
return (EFAULT);
return (err);
}
case DTRACEIOC_PROBEMATCH:
case DTRACEIOC_PROBES: {
dtrace_id_t i;
int m = 0;
return (EFAULT);
/*
* Before we attempt to match this probe, we want to give
* all providers the opportunity to provide it.
*/
}
if (cmd == DTRACEIOC_PROBEMATCH) {
}
if (cmd == DTRACEIOC_PROBEMATCH) {
break;
}
if (m < 0) {
return (EINVAL);
}
} else {
break;
}
}
return (ESRCH);
}
return (EFAULT);
return (0);
}
case DTRACEIOC_PROBEARG: {
return (EFAULT);
return (EINVAL);
return (EINVAL);
return (EINVAL);
}
return (EINVAL);
}
/*
* There isn't any typed information for this probe.
* Set the argument number to DTRACE_ARGNONE.
*/
} else {
}
return (EFAULT);
return (0);
}
case DTRACEIOC_GO: {
if (rval != 0)
return (rval);
return (EFAULT);
return (0);
}
case DTRACEIOC_STOP: {
if (rval != 0)
return (rval);
return (EFAULT);
return (0);
}
case DTRACEIOC_DOFGET: {
return (EFAULT);
}
case DTRACEIOC_AGGSNAP:
case DTRACEIOC_BUFSNAP: {
return (EFAULT);
return (EINVAL);
if (cmd == DTRACEIOC_BUFSNAP) {
} else {
}
return (EBUSY);
}
/*
* If this buffer has already been consumed, we're
* going to indicate that there's nothing left here
* to consume.
*/
desc.dtbd_drops = 0;
desc.dtbd_errors = 0;
desc.dtbd_oldest = 0;
return (EFAULT);
return (0);
}
/*
* If this is a ring buffer that has wrapped, we want
* to copy the whole thing out.
*/
}
return (EFAULT);
}
return (EFAULT);
return (0);
}
return (ENOENT);
}
/*
* If the buffers did not actually switch, then the cross call
* did not take place -- presumably because the given CPU is
* not in the ready set. If this is the case, we'll return
* ENOENT.
*/
return (ENOENT);
}
/*
* We have our snapshot; now copy it out.
*/
buf->dtb_xamot_offset) != 0) {
return (EFAULT);
}
desc.dtbd_oldest = 0;
/*
* Finally, copy out the buffer description.
*/
return (EFAULT);
return (0);
}
case DTRACEIOC_CONF: {
return (EFAULT);
return (0);
}
case DTRACEIOC_STATUS: {
int i, j;
/*
* See the comment in dtrace_state_deadman() for the reason
* for setting dts_laststatus to INT64_MAX before setting
* it to the correct value.
*/
return (ENOENT);
}
for (i = 0; i < NCPU; i++) {
stat.dtst_filled++;
for (j = 0; j < state->dts_nspeculations; j++) {
}
}
return (EFAULT);
return (0);
}
case DTRACEIOC_FORMAT: {
char *str;
int len;
return (EFAULT);
if (fmt.dtfd_format == 0 ||
return (EINVAL);
}
/*
* Format strings are allocated contiguously and they are
* never freed; if a format index is less than the number
* of formats, we can assert that the format map is non-NULL
* and that the format for the specified index is non-NULL.
*/
return (EINVAL);
}
} else {
return (EINVAL);
}
}
return (0);
}
default:
break;
}
return (ENOTTY);
}
/*ARGSUSED*/
static int
{
switch (cmd) {
case DDI_DETACH:
break;
case DDI_SUSPEND:
return (DDI_SUCCESS);
default:
return (DDI_FAILURE);
}
ASSERT(dtrace_opens == 0);
if (dtrace_helpers > 0) {
return (DDI_FAILURE);
}
return (DDI_FAILURE);
}
/*
* If there were ECBs on this state, the provider should
* have not been allowed to detach; assert that there is
* none.
*/
/*
* If we're being detached with anonymous state, we need to
* indicate to the kernel debugger that DTrace is now inactive.
*/
}
ASSERT(dtrace_getf == 0);
dtrace_nprobes = 0;
dtrace_bymod = NULL;
if (dtrace_toxrange != NULL) {
dtrace_toxranges_max * sizeof (dtrace_toxrange_t));
dtrace_toxranges = 0;
dtrace_toxranges_max = 0;
}
dtrace_devi = NULL;
ASSERT(dtrace_vtime_references == 0);
ASSERT(dtrace_opens == 0);
/*
* We don't destroy the task queue until after we have dropped our
* locks (taskq_destroy() may block on running tasks). To prevent
* attempting to do work after we have effectively detached but before
* the task queue has been destroyed, all tasks dispatched via the
* task queue must check that DTrace is still attached before
* performing any operation.
*/
dtrace_taskq = NULL;
return (DDI_SUCCESS);
}
/*ARGSUSED*/
static int
{
int error;
switch (infocmd) {
case DDI_INFO_DEVT2DEVINFO:
*result = (void *)dtrace_devi;
error = DDI_SUCCESS;
break;
case DDI_INFO_DEVT2INSTANCE:
*result = (void *)0;
error = DDI_SUCCESS;
break;
default:
error = DDI_FAILURE;
}
return (error);
}
static struct cb_ops dtrace_cb_ops = {
dtrace_open, /* open */
dtrace_close, /* close */
nulldev, /* strategy */
nulldev, /* print */
nodev, /* dump */
nodev, /* read */
nodev, /* write */
dtrace_ioctl, /* ioctl */
nodev, /* devmap */
nodev, /* mmap */
nodev, /* segmap */
nochpoll, /* poll */
ddi_prop_op, /* cb_prop_op */
0, /* streamtab */
};
static struct dev_ops dtrace_ops = {
DEVO_REV, /* devo_rev */
0, /* refcnt */
dtrace_info, /* get_dev_info */
nulldev, /* identify */
nulldev, /* probe */
dtrace_attach, /* attach */
dtrace_detach, /* detach */
nodev, /* reset */
&dtrace_cb_ops, /* driver operations */
NULL, /* bus operations */
nodev, /* dev power */
ddi_quiesce_not_needed, /* quiesce */
};
&mod_driverops, /* module type (this is a pseudo driver) */
"Dynamic Tracing", /* name of module */
&dtrace_ops, /* driver ops */
};
static struct modlinkage modlinkage = {
(void *)&modldrv,
};
int
_init(void)
{
return (mod_install(&modlinkage));
}
int
{
}
int
_fini(void)
{
return (mod_remove(&modlinkage));
}