xref: /illumos-gate/usr/src/cmd/dtrace/test/tst/common/types/tst.struct.d (revision b210e77709da8e42dfe621e10ccf4be504206058)
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 2006 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*
28  * ASSERTION:
29  *   Declare a dynamic type and then use it to copyin the first 3 environment
30  *   variable pointers from the current process.
31  *
32  * SECTION: Structs and Unions/Structs;
33  *	Actions and Subroutines/copyin();
34  * 	Actions and Subroutines/copyinstr();
35  *	Variables/External Variables
36  *
37  * NOTES:
38  *  This test program declares a dynamic type and then uses it to copyin the
39  *  first three environment variable pointers from the current process.  We
40  *  then use the dynamic type to access the result of our copyin().  The
41  *  special "D" module type scope is also tested.
42  */
43 
44 #pragma D option quiet
45 
46 struct env_vars_32 {
47 	uint32_t e1;
48 	uint32_t e2;
49 	uint32_t e3;
50 };
51 
52 struct env_vars_64 {
53 	uint64_t e1;
54 	uint64_t e2;
55 	uint64_t e3;
56 };
57 
58 BEGIN
59 /curpsinfo->pr_dmodel == PR_MODEL_ILP32/
60 {
61 	e32 = (struct D`env_vars_32 *)
62 	    copyin(curpsinfo->pr_envp, sizeof (struct D`env_vars_32));
63 
64 	printf("e1 = \"%s\"\n", stringof(copyinstr(e32->e1)));
65 	printf("e2 = \"%s\"\n", stringof(copyinstr(e32->e2)));
66 	printf("e3 = \"%s\"\n", stringof(copyinstr(e32->e3)));
67 
68 	exit(0);
69 }
70 
71 BEGIN
72 /curpsinfo->pr_dmodel == PR_MODEL_LP64/
73 {
74 	e64 = (struct D`env_vars_64 *)
75 	    copyin(curpsinfo->pr_envp, sizeof (struct D`env_vars_64));
76 
77 	printf("e1 = \"%s\"\n", stringof(copyinstr(e64->e1)));
78 	printf("e2 = \"%s\"\n", stringof(copyinstr(e64->e2)));
79 	printf("e3 = \"%s\"\n", stringof(copyinstr(e64->e3)));
80 
81 	exit(0);
82 }
83