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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
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  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #!/usr/sbin/dtrace -Fs
28 
29 syscall::open:entry,
30 syscall::open64:entry
31 {
32 	/*
33 	 * The call to speculation() creates a new speculation.  If this fails,
34 	 * dtrace(8) will generate an error message indicating the reason for
35 	 * the failed speculation(), but subsequent speculative tracing will be
36 	 * silently discarded.
37 	 */
38 	self->spec = speculation();
39 	speculate(self->spec);
40 
41 	/*
42 	 * Because this printf() follows the speculate(), it is being
43 	 * speculatively traced; it will only appear in the data buffer if the
44 	 * speculation is subsequently commited.
45 	 */
46 	printf("%s", stringof(copyinstr(arg0)));
47 }
48 
49 fbt:::
50 /self->spec/
51 {
52 	/*
53 	 * A speculate() with no other actions speculates the default action:
54 	 * tracing the EPID.
55 	 */
56 	speculate(self->spec);
57 }
58 
59 syscall::open:return,
60 syscall::open64:return
61 /self->spec/
62 {
63 	/*
64 	 * To balance the output with the -F option, we want to be sure that
65 	 * every entry has a matching return.  Because we speculated the
66 	 * open entry above, we want to also speculate the open return.
67 	 * This is also a convenient time to trace the errno value.
68 	 */
69 	speculate(self->spec);
70 	trace(errno);
71 }
72 
73 syscall::open:return,
74 syscall::open64:return
75 /self->spec && errno != 0/
76 {
77 	/*
78 	 * If errno is non-zero, we want to commit the speculation.
79 	 */
80 	commit(self->spec);
81 	self->spec = 0;
82 }
83 
84 syscall::open:return,
85 syscall::open64:return
86 /self->spec && errno == 0/
87 {
88 	/*
89 	 * If errno is not set, we discard the speculation.
90 	 */
91 	discard(self->spec);
92 	self->spec = 0;
93 }
94