]> CyberLeo.Net >> Repos - FreeBSD/releng/7.2.git/blob - sys/cddl/contrib/opensolaris/uts/common/sys/fasttrap_impl.h
Create releng/7.2 from stable/7 in preparation for 7.2-RELEASE.
[FreeBSD/releng/7.2.git] / sys / cddl / contrib / opensolaris / uts / common / sys / fasttrap_impl.h
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21
22 /*
23  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26
27 #ifndef _FASTTRAP_IMPL_H
28 #define _FASTTRAP_IMPL_H
29
30 #pragma ident   "%Z%%M% %I%     %E% SMI"
31
32 #include <sys/types.h>
33 #include <sys/dtrace.h>
34 #include <sys/proc.h>
35 #include <sys/fasttrap.h>
36 #include <sys/fasttrap_isa.h>
37
38 #ifdef  __cplusplus
39 extern "C" {
40 #endif
41
42 /*
43  * Fasttrap Providers, Probes and Tracepoints
44  *
45  * Each Solaris process can have multiple providers -- the pid provider as
46  * well as any number of user-level statically defined tracing (USDT)
47  * providers. Those providers are each represented by a fasttrap_provider_t.
48  * All providers for a given process have a pointer to a shared
49  * fasttrap_proc_t. The fasttrap_proc_t has two states: active or defunct.
50  * When the count of live providers goes to zero it becomes defunct; providers
51  * drop their count when they are removed individually or en masse when a
52  * process exits or performs an exec.
53  *
54  * Each probe is represented by a fasttrap_probe_t which has a pointer to
55  * its associated provider as well as a list of fasttrap_id_tp_t structures
56  * which are tuples combining a fasttrap_id_t and a fasttrap_tracepoint_t.
57  * A fasttrap_tracepoint_t represents the actual point of instrumentation
58  * and it contains two lists of fasttrap_id_t structures (to be fired pre-
59  * and post-instruction emulation) that identify the probes attached to the
60  * tracepoint. Tracepoints also have a pointer to the fasttrap_proc_t for the
61  * process they trace which is used when looking up a tracepoint both at
62  * probe fire time and when enabling and disabling probes.
63  *
64  * It's important to note that probes are preallocated with the necessary
65  * number of tracepoints, but that tracepoints can be shared by probes and
66  * swapped between probes. If a probe's preallocated tracepoint is enabled
67  * (and, therefore, the associated probe is enabled), and that probe is
68  * then disabled, ownership of that tracepoint may be exchanged for an
69  * unused tracepoint belonging to another probe that was attached to the
70  * enabled tracepoint.
71  */
72
73 typedef struct fasttrap_proc {
74         pid_t ftpc_pid;                         /* process ID for this proc */
75         uint64_t ftpc_acount;                   /* count of active providers */
76         uint64_t ftpc_rcount;                   /* provider reference count */
77 #if defined(sun)
78         kmutex_t ftpc_mtx;                      /* proc lock */
79 #else
80         struct mtx ftpc_mtx;                    /* proc lock */
81 #endif
82         struct fasttrap_proc *ftpc_next;        /* next proc in hash chain */
83 } fasttrap_proc_t;
84
85 typedef struct fasttrap_provider {
86         pid_t ftp_pid;                          /* process ID for this prov */
87         char ftp_name[DTRACE_PROVNAMELEN];      /* prov name (w/o the pid) */
88         dtrace_provider_id_t ftp_provid;        /* DTrace provider handle */
89         uint_t ftp_marked;                      /* mark for possible removal */
90         uint_t ftp_retired;                     /* mark when retired */
91 #if defined(sun)
92         kmutex_t ftp_mtx;                       /* provider lock */
93         kmutex_t ftp_cmtx;                      /* lock on creating probes */
94 #else
95         struct mtx ftp_mtx;                     /* provider lock */
96         struct mtx ftp_cmtx;                    /* lock on creating probes */
97 #endif
98         uint64_t ftp_rcount;                    /* enabled probes ref count */
99         uint64_t ftp_ccount;                    /* consumers creating probes */
100         uint64_t ftp_mcount;                    /* meta provider count */
101         fasttrap_proc_t *ftp_proc;              /* shared proc for all provs */
102         struct fasttrap_provider *ftp_next;     /* next prov in hash chain */
103 } fasttrap_provider_t;
104
105 typedef struct fasttrap_id fasttrap_id_t;
106 typedef struct fasttrap_probe fasttrap_probe_t;
107 typedef struct fasttrap_tracepoint fasttrap_tracepoint_t;
108
109 struct fasttrap_id {
110         fasttrap_probe_t *fti_probe;            /* referrring probe */
111         fasttrap_id_t *fti_next;                /* enabled probe list on tp */
112         fasttrap_probe_type_t fti_ptype;        /* probe type */
113 };
114
115 typedef struct fasttrap_id_tp {
116         fasttrap_id_t fit_id;
117         fasttrap_tracepoint_t *fit_tp;
118 } fasttrap_id_tp_t;
119
120 struct fasttrap_probe {
121         dtrace_id_t ftp_id;                     /* DTrace probe identifier */
122         pid_t ftp_pid;                          /* pid for this probe */
123         fasttrap_provider_t *ftp_prov;          /* this probe's provider */
124         uintptr_t ftp_faddr;                    /* associated function's addr */
125         size_t ftp_fsize;                       /* associated function's size */
126         uint64_t ftp_gen;                       /* modification generation */
127         uint64_t ftp_ntps;                      /* number of tracepoints */
128         uint8_t *ftp_argmap;                    /* native to translated args */
129         uint8_t ftp_nargs;                      /* translated argument count */
130         uint8_t ftp_enabled;                    /* is this probe enabled */
131         char *ftp_xtypes;                       /* translated types index */
132         char *ftp_ntypes;                       /* native types index */
133         fasttrap_id_tp_t ftp_tps[1];            /* flexible array */
134 };
135
136 #define FASTTRAP_ID_INDEX(id)   \
137 ((fasttrap_id_tp_t *)(((char *)(id) - offsetof(fasttrap_id_tp_t, fit_id))) - \
138 &(id)->fti_probe->ftp_tps[0])
139
140 struct fasttrap_tracepoint {
141         fasttrap_proc_t *ftt_proc;              /* associated process struct */
142         uintptr_t ftt_pc;                       /* address of tracepoint */
143         pid_t ftt_pid;                          /* pid of tracepoint */
144         fasttrap_machtp_t ftt_mtp;              /* ISA-specific portion */
145         fasttrap_id_t *ftt_ids;                 /* NULL-terminated list */
146         fasttrap_id_t *ftt_retids;              /* NULL-terminated list */
147         fasttrap_tracepoint_t *ftt_next;        /* link in global hash */
148 };
149
150 typedef struct fasttrap_bucket {
151 #if defined(sun)
152         kmutex_t ftb_mtx;                       /* bucket lock */
153 #else
154         struct mtx ftb_mtx;                     /* bucket lock */
155 #endif
156         void *ftb_data;                         /* data payload */
157
158         uint8_t ftb_pad[64 - sizeof (struct mtx) - sizeof (void *)];
159 } fasttrap_bucket_t;
160
161 typedef struct fasttrap_hash {
162         ulong_t fth_nent;                       /* power-of-2 num. of entries */
163         ulong_t fth_mask;                       /* fth_nent - 1 */
164         fasttrap_bucket_t *fth_table;           /* array of buckets */
165 } fasttrap_hash_t;
166
167 /*
168  * If at some future point these assembly functions become observable by
169  * DTrace, then these defines should become separate functions so that the
170  * fasttrap provider doesn't trigger probes during internal operations.
171  */
172 #define fasttrap_copyout        copyout
173 #define fasttrap_fuword32       fuword32
174 #define fasttrap_suword32       suword32
175
176 #define fasttrap_fulword        fulword
177 #define fasttrap_sulword        sulword
178
179 extern void fasttrap_sigtrap(proc_t *, kthread_t *, uintptr_t);
180
181 extern dtrace_id_t              fasttrap_probe_id;
182 extern fasttrap_hash_t          fasttrap_tpoints;
183
184 #define FASTTRAP_TPOINTS_INDEX(pid, pc) \
185         (((pc) / sizeof (fasttrap_instr_t) + (pid)) & fasttrap_tpoints.fth_mask)
186
187 /*
188  * Must be implemented by fasttrap_isa.c
189  */
190 extern int fasttrap_tracepoint_init(proc_t *, fasttrap_tracepoint_t *,
191     uintptr_t, fasttrap_probe_type_t);
192 extern int fasttrap_tracepoint_install(proc_t *, fasttrap_tracepoint_t *);
193 extern int fasttrap_tracepoint_remove(proc_t *, fasttrap_tracepoint_t *);
194
195 extern int fasttrap_pid_probe(struct regs *);
196 extern int fasttrap_return_probe(struct regs *);
197
198 extern uint64_t fasttrap_pid_getarg(void *, dtrace_id_t, void *, int, int);
199 extern uint64_t fasttrap_usdt_getarg(void *, dtrace_id_t, void *, int, int);
200
201 #ifdef  __cplusplus
202 }
203 #endif
204
205 #endif  /* _FASTTRAP_IMPL_H */