8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22
23 /*
24 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
25 * Use is subject to license terms.
26 */
27
28 #pragma ident "%Z%%M% %I% %E% SMI"
29
30 #include <dt_impl.h>
31 #include <stddef.h>
32 #include <errno.h>
33 #include <assert.h>
34 #include <time.h>
35
36 static const struct {
37 int dtslt_option;
38 size_t dtslt_offs;
39 } _dtrace_sleeptab[] = {
40 { DTRACEOPT_STATUSRATE, offsetof(dtrace_hdl_t, dt_laststatus) },
41 { DTRACEOPT_AGGRATE, offsetof(dtrace_hdl_t, dt_lastagg) },
42 { DTRACEOPT_SWITCHRATE, offsetof(dtrace_hdl_t, dt_lastswitch) },
43 { DTRACEOPT_MAX, 0 }
44 };
45
46 void
47 dtrace_sleep(dtrace_hdl_t *dtp)
48 {
147 return (DTRACE_STATUS_EXITED);
148 }
149
150 if (dtp->dt_status[gen].dtst_filled == 0)
151 return (DTRACE_STATUS_OKAY);
152
153 if (dtp->dt_options[DTRACEOPT_BUFPOLICY] != DTRACEOPT_BUFPOLICY_FILL)
154 return (DTRACE_STATUS_OKAY);
155
156 if (!dtp->dt_stopped) {
157 if (dtrace_stop(dtp) == -1)
158 return (-1);
159 }
160
161 return (DTRACE_STATUS_FILLED);
162 }
163
164 int
165 dtrace_go(dtrace_hdl_t *dtp)
166 {
167 void *dof;
168 int err;
169
170 if (dtp->dt_active)
171 return (dt_set_errno(dtp, EINVAL));
172
173 /*
174 * If a dtrace:::ERROR program and callback are registered, enable the
175 * program before we start tracing. If this fails for a vector open
176 * with ENOTTY, we permit dtrace_go() to succeed so that vector clients
177 * such as mdb's dtrace module can execute the rest of dtrace_go() even
178 * though they do not provide support for the DTRACEIOC_ENABLE ioctl.
179 */
180 if (dtp->dt_errprog != NULL &&
181 dtrace_program_exec(dtp, dtp->dt_errprog, NULL) == -1 && (
182 dtp->dt_errno != ENOTTY || dtp->dt_vector == NULL))
183 return (-1); /* dt_errno has been set for us */
184
185 if ((dof = dtrace_getopt_dof(dtp)) == NULL)
186 return (-1); /* dt_errno has been set for us */
187
188 err = dt_ioctl(dtp, DTRACEIOC_ENABLE, dof);
189 dtrace_dof_destroy(dtp, dof);
190
191 if (err == -1 && (errno != ENOTTY || dtp->dt_vector == NULL))
192 return (dt_set_errno(dtp, errno));
193
194 if (dt_ioctl(dtp, DTRACEIOC_GO, &dtp->dt_beganon) == -1) {
195 if (errno == EACCES)
196 return (dt_set_errno(dtp, EDT_DESTRUCTIVE));
197
198 if (errno == EALREADY)
199 return (dt_set_errno(dtp, EDT_ISANON));
200
201 if (errno == ENOENT)
202 return (dt_set_errno(dtp, EDT_NOANON));
203
204 if (errno == E2BIG)
205 return (dt_set_errno(dtp, EDT_ENDTOOBIG));
206
207 if (errno == ENOSPC)
208 return (dt_set_errno(dtp, EDT_BUFTOOSMALL));
209
210 return (dt_set_errno(dtp, errno));
211 }
212
213 dtp->dt_active = 1;
|
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22
23 /*
24 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
25 * Use is subject to license terms.
26 */
27
28 /*
29 * Copyright (c) 2011, Joyent, Inc. All rights reserved.
30 */
31
32 #include <dt_impl.h>
33 #include <stddef.h>
34 #include <errno.h>
35 #include <assert.h>
36 #include <time.h>
37
38 static const struct {
39 int dtslt_option;
40 size_t dtslt_offs;
41 } _dtrace_sleeptab[] = {
42 { DTRACEOPT_STATUSRATE, offsetof(dtrace_hdl_t, dt_laststatus) },
43 { DTRACEOPT_AGGRATE, offsetof(dtrace_hdl_t, dt_lastagg) },
44 { DTRACEOPT_SWITCHRATE, offsetof(dtrace_hdl_t, dt_lastswitch) },
45 { DTRACEOPT_MAX, 0 }
46 };
47
48 void
49 dtrace_sleep(dtrace_hdl_t *dtp)
50 {
149 return (DTRACE_STATUS_EXITED);
150 }
151
152 if (dtp->dt_status[gen].dtst_filled == 0)
153 return (DTRACE_STATUS_OKAY);
154
155 if (dtp->dt_options[DTRACEOPT_BUFPOLICY] != DTRACEOPT_BUFPOLICY_FILL)
156 return (DTRACE_STATUS_OKAY);
157
158 if (!dtp->dt_stopped) {
159 if (dtrace_stop(dtp) == -1)
160 return (-1);
161 }
162
163 return (DTRACE_STATUS_FILLED);
164 }
165
166 int
167 dtrace_go(dtrace_hdl_t *dtp)
168 {
169 if (dtp->dt_active)
170 return (dt_set_errno(dtp, EINVAL));
171
172 /*
173 * If a dtrace:::ERROR program and callback are registered, enable the
174 * program before we start tracing. If this fails for a vector open
175 * with ENOTTY, we permit dtrace_go() to succeed so that vector clients
176 * such as mdb's dtrace module can execute the rest of dtrace_go() even
177 * though they do not provide support for the DTRACEIOC_ENABLE ioctl.
178 */
179 if (dtp->dt_errprog != NULL &&
180 dtrace_program_exec(dtp, dtp->dt_errprog, NULL) == -1 && (
181 dtp->dt_errno != ENOTTY || dtp->dt_vector == NULL))
182 return (-1); /* dt_errno has been set for us */
183
184 if (dt_ioctl(dtp, DTRACEIOC_GO, &dtp->dt_beganon) == -1) {
185 if (errno == EACCES)
186 return (dt_set_errno(dtp, EDT_DESTRUCTIVE));
187
188 if (errno == EALREADY)
189 return (dt_set_errno(dtp, EDT_ISANON));
190
191 if (errno == ENOENT)
192 return (dt_set_errno(dtp, EDT_NOANON));
193
194 if (errno == E2BIG)
195 return (dt_set_errno(dtp, EDT_ENDTOOBIG));
196
197 if (errno == ENOSPC)
198 return (dt_set_errno(dtp, EDT_BUFTOOSMALL));
199
200 return (dt_set_errno(dtp, errno));
201 }
202
203 dtp->dt_active = 1;
|