]> git.saurik.com Git - apple/xnu.git/blobdiff - bsd/sys/dtrace_impl.h
xnu-4903.231.4.tar.gz
[apple/xnu.git] / bsd / sys / dtrace_impl.h
index 71dc020f2985b08c34a58cbea9f8e86a9cc287d2..f463b49e35e8c8886e75f5cdab9993ab33c870ff 100644 (file)
@@ -22,6 +22,9 @@
 /*
  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
+ *
+ * Portions Copyright (c) 2012 by Delphix. All rights reserved.
+ * Portions Copyright (c) 2016 by Joyent, Inc.
  */
 
 #ifndef _SYS_DTRACE_IMPL_H
@@ -107,6 +110,8 @@ struct dtrace_probe {
        char *dtpr_mod;                         /* probe's module name */
        char *dtpr_func;                        /* probe's function name */
        char *dtpr_name;                        /* probe's name */
+       dtrace_probe_t *dtpr_nextprov;          /* next in provider hash */
+       dtrace_probe_t *dtpr_prevprov;          /* previous in provider hash */
        dtrace_probe_t *dtpr_nextmod;           /* next in module hash */
        dtrace_probe_t *dtpr_prevmod;           /* previous in module hash */
        dtrace_probe_t *dtpr_nextfunc;          /* next in function hash */
@@ -132,18 +137,21 @@ typedef struct dtrace_probekey {
 
 typedef struct dtrace_hashbucket {
        struct dtrace_hashbucket *dthb_next;    /* next on hash chain */
-       dtrace_probe_t *dthb_chain;             /* chain of probes */
+       void *dthb_chain;                       /* chain of elements */
        int dthb_len;                           /* number of probes here */
 } dtrace_hashbucket_t;
 
+typedef const char* dtrace_strkey_f(void*, uintptr_t);
+
 typedef struct dtrace_hash {
-       dtrace_hashbucket_t **dth_tab;          /* hash table */
-       int dth_size;                           /* size of hash table */
-       int dth_mask;                           /* mask to index into table */
-       int dth_nbuckets;                       /* total number of buckets */
-       uintptr_t dth_nextoffs;                 /* offset of next in probe */
-       uintptr_t dth_prevoffs;                 /* offset of prev in probe */
-       uintptr_t dth_stroffs;                  /* offset of str in probe */
+       dtrace_hashbucket_t **dth_tab;  /* hash table */
+       int dth_size;                   /* size of hash table */
+       int dth_mask;                   /* mask to index into table */
+       int dth_nbuckets;               /* total number of buckets */
+       uintptr_t dth_nextoffs;         /* offset of next in element */
+       uintptr_t dth_prevoffs;         /* offset of prev in element */
+       dtrace_strkey_f *dth_getstr;    /* func to retrieve str in element */
+       uintptr_t dth_stroffs;          /* offset of str in element */
 } dtrace_hash_t;
 
 /*
@@ -202,15 +210,18 @@ typedef struct dtrace_hash {
  * predicate is non-NULL, the DIF object is executed.  If the result is
  * non-zero, the action list is processed, with each action being executed
  * accordingly.  When the action list has been completely executed, processing
- * advances to the next ECB.  processing advances to the next ECB.  If the
- * result is non-zero; For each ECB, it first determines the The ECB
- * abstraction allows disjoint consumers to multiplex on single probes.
+ * advances to the next ECB. The ECB abstraction allows disjoint consumers
+ * to multiplex on single probes.
+ *
+ * Execution of the ECB results in consuming dte_size bytes in the buffer
+ * to record data.  During execution, dte_needed bytes must be available in
+ * the buffer.  This space is used for both recorded data and tuple data.
  */
 struct dtrace_ecb {
        dtrace_epid_t dte_epid;                 /* enabled probe ID */
        uint32_t dte_alignment;                 /* required alignment */
-       size_t dte_needed;                      /* bytes needed */
-       size_t dte_size;                        /* total size of payload */
+       size_t dte_needed;                      /* space needed for execution */
+       size_t dte_size;                        /* size of recorded payload */
        dtrace_predicate_t *dte_predicate;      /* predicate, if any */
        dtrace_action_t *dte_action;            /* actions, if any */
        dtrace_ecb_t *dte_next;                 /* next ECB on probe */
@@ -268,27 +279,30 @@ typedef struct dtrace_aggregation {
  * the EPID, the consumer can determine the data layout.  (The data buffer
  * layout is shown schematically below.)  By assuring that one can determine
  * data layout from the EPID, the metadata stream can be separated from the
- * data stream -- simplifying the data stream enormously.
- *
- *      base of data buffer --->  +------+--------------------+------+
- *                                | EPID | data               | EPID |
- *                                +------+--------+------+----+------+
- *                                | data          | EPID | data      |
- *                                +---------------+------+-----------+
- *                                | data, cont.                      |
- *                                +------+--------------------+------+
- *                                | EPID | data               |      |
- *                                +------+--------------------+      |
- *                                |                ||                |
- *                                |                ||                |
- *                                |                \/                |
- *                                :                                  :
- *                                .                                  .
- *                                .                                  .
- *                                .                                  .
- *                                :                                  :
- *                                |                                  |
- *     limit of data buffer --->  +----------------------------------+
+ * data stream -- simplifying the data stream enormously.  The ECB always
+ * proceeds the recorded data as part of the dtrace_rechdr_t structure that
+ * includes the EPID and a high-resolution timestamp used for output ordering
+ * consistency.
+ *
+ *      base of data buffer --->  +--------+--------------------+--------+
+ *                                | rechdr | data               | rechdr |
+ *                                +--------+------+--------+----+--------+
+ *                                | data          | rechdr | data        |
+ *                                +---------------+--------+-------------+
+ *                                | data, cont.                          |
+ *                                +--------+--------------------+--------+
+ *                                | rechdr | data               |        |
+ *                                +--------+--------------------+        |
+ *                                |                ||                    |
+ *                                |                ||                    |
+ *                                |                \/                    |
+ *                                :                                      :
+ *                                .                                      .
+ *                                .                                      .
+ *                                .                                      .
+ *                                :                                      :
+ *                                |                                      |
+ *     limit of data buffer --->  +--------------------------------------+
  *
  * When evaluating an ECB, dtrace_probe() determines if the ECB's needs of the
  * principal buffer (both scratch and payload) exceed the available space.  If
@@ -413,6 +427,8 @@ typedef struct dtrace_aggregation {
 
 typedef struct dtrace_buffer {
        uint64_t dtb_offset;                    /* current offset in buffer */
+       uint64_t dtb_cur_limit;                 /* current limit before signaling/dropping */
+       uint64_t dtb_limit;                     /* limit before signaling */
        uint64_t dtb_size;                      /* size of buffer */
        uint32_t dtb_flags;                     /* flags */
        uint32_t dtb_drops;                     /* number of drops */
@@ -426,6 +442,9 @@ typedef struct dtrace_buffer {
 #ifndef _LP64
        uint64_t dtb_pad1;
 #endif
+       uint64_t dtb_switched;                  /* time of last switch */
+       uint64_t dtb_interval;                  /* observed switch interval */
+       uint64_t dtb_pad2[4];                   /* pad to avoid false sharing */
 } dtrace_buffer_t;
 
 /*
@@ -917,6 +936,7 @@ typedef struct dtrace_mstate {
        int dtms_ipl;                           /* cached interrupt pri lev */
        int dtms_fltoffs;                       /* faulting DIFO offset */
        uintptr_t dtms_strtok;                  /* saved strtok() pointer */
+       uintptr_t dtms_strtok_limit;            /* upper bound of strtok ptr */
        uint32_t dtms_access;                   /* memory access rights */
        dtrace_difo_t *dtms_difo;               /* current dif object */
 } dtrace_mstate_t;
@@ -944,6 +964,7 @@ typedef struct dtrace_mstate {
  * directed acyclic graph.  The activity transition diagram is as follows:
  *
  *
+ *
  * +----------+                   +--------+                   +--------+
  * | INACTIVE |------------------>| WARMUP |------------------>| ACTIVE |
  * +----------+   dtrace_go(),    +--------+   dtrace_go(),    +--------+
@@ -1115,6 +1136,7 @@ typedef struct dtrace_helpers {
 #define        DTRACE_HELPTRACE_DONE   (-2)
 #define        DTRACE_HELPTRACE_ERR    (-3)
 
+
 typedef struct dtrace_helptrace {
        dtrace_helper_action_t  *dtht_helper;   /* helper action */
        int dtht_where;                         /* where in helper action */
@@ -1209,6 +1231,7 @@ struct dtrace_state {
        dtrace_cred_t dts_cred;                 /* credentials */
        size_t dts_nretained;                   /* number of retained enabs */
        uint64_t dts_arg_error_illval;
+       uint32_t dts_buf_over_limit;            /* number of bufs over dtb_limit */
 };
 
 struct dtrace_provider {
@@ -1292,6 +1315,28 @@ typedef struct dtrace_errhash {
 
 #endif /* DTRACE_ERRDEBUG */
 
+
+typedef struct dtrace_string dtrace_string_t;
+
+typedef struct dtrace_string {
+       dtrace_string_t *dtst_next;
+       dtrace_string_t *dtst_prev;
+       uint32_t dtst_refcount;
+       char dtst_str[];
+} dtrace_string_t;
+
+/**
+ * DTrace Matching pre-conditions
+ *
+ * Used when matching new probes to discard matching of enablings that
+ * doesn't match the condition tested by dmc_func
+ */
+typedef struct dtrace_match_cond {
+       int (*dmc_func)(dtrace_probedesc_t*, void*);
+       void *dmc_data;
+} dtrace_match_cond_t;
+
+
 /*
  * DTrace Toxic Ranges
  *
@@ -1313,7 +1358,7 @@ typedef struct dtrace_toxrange {
        uintptr_t       dtt_limit;              /* limit of toxic range */
 } dtrace_toxrange_t;
 
-extern uint64_t dtrace_getarg(int, int);
+extern uint64_t dtrace_getarg(int, int, dtrace_mstate_t*, dtrace_vstate_t*);
 extern int dtrace_getipl(void);
 extern uintptr_t dtrace_caller(int);
 extern uint32_t dtrace_cas32(uint32_t *, uint32_t, uint32_t);
@@ -1323,6 +1368,9 @@ extern void dtrace_copyinstr(user_addr_t, uintptr_t, size_t, volatile uint16_t *
 extern void dtrace_copyout(uintptr_t, user_addr_t, size_t, volatile uint16_t *);
 extern void dtrace_copyoutstr(uintptr_t, user_addr_t, size_t, volatile uint16_t *);
 extern void dtrace_getpcstack(pc_t *, int, int, uint32_t *);
+extern uint64_t dtrace_load64(uintptr_t);
+extern int dtrace_canload(uint64_t, size_t, dtrace_mstate_t*, dtrace_vstate_t*);
+
 extern uint64_t dtrace_getreg(struct regs *, uint_t);
 extern int dtrace_getstackdepth(int);
 extern void dtrace_getupcstack(uint64_t *, int);
@@ -1341,28 +1389,47 @@ extern int dtrace_attached(void);
 extern hrtime_t dtrace_gethrestime(void);
 extern void dtrace_isa_init(void);
 
+extern void dtrace_flush_caches(void);
+
 extern void dtrace_copy(uintptr_t, uintptr_t, size_t);
 extern void dtrace_copystr(uintptr_t, uintptr_t, size_t, volatile uint16_t *);
 
+/*
+ * DTrace state handling
+ */
+extern minor_t dtrace_state_reserve(void);
+extern dtrace_state_t* dtrace_state_allocate(minor_t minor);
+extern dtrace_state_t* dtrace_state_get(minor_t minor);
+extern void dtrace_state_free(minor_t minor);
+
 /*
  * DTrace restriction checks
  */
+extern void dtrace_restriction_policy_load(void);
 extern boolean_t dtrace_is_restricted(void);
+extern boolean_t dtrace_are_restrictions_relaxed(void);
+extern boolean_t dtrace_fbt_probes_restricted(void);
+extern boolean_t dtrace_sdt_probes_restricted(void);
 extern boolean_t dtrace_can_attach_to_proc(proc_t);
 
 /*
  * DTrace Assertions
  *
- * DTrace calls ASSERT from probe context.  To assure that a failed ASSERT
- * does not induce a markedly more catastrophic failure (e.g., one from which
- * a dump cannot be gleaned), DTrace must define its own ASSERT to be one that
- * may safely be called from probe context.  This header file must thus be
- * included by any DTrace component that calls ASSERT from probe context, and
- * _only_ by those components.  (The only exception to this is kernel
- * debugging infrastructure at user-level that doesn't depend on calling
- * ASSERT.)
+ * DTrace calls ASSERT and VERIFY from probe context.  To assure that a failed
+ * ASSERT or VERIFYdoes not induce a markedly more catastrophic failure (e.g.,
+ * one from which a dump cannot be gleaned), DTrace must define its own ASSERT
+ * and VERIFY macros to be ones that may safely be called from probe context.
+ * This header file must thus be included by any DTrace component that calls
+ * ASSERT and/or VERIFY from probe context, and _only_ by those components.
+ * (The only exception to this is kernel debugging infrastructure at user-level
+ * that doesn't depend on calling ASSERT.)
  */
 #undef ASSERT
+#undef VERIFY
+
+#define        VERIFY(EX)      ((void)((EX) || \
+                       dtrace_assfail(#EX, __FILE__, __LINE__)))
+
 #if DEBUG
 #define        ASSERT(EX)      ((void)((EX) || \
                        dtrace_assfail(#EX, __FILE__, __LINE__)))