19512fe85Sahl /*
29512fe85Sahl  * CDDL HEADER START
39512fe85Sahl  *
49512fe85Sahl  * The contents of this file are subject to the terms of the
59512fe85Sahl  * Common Development and Distribution License (the "License").
69512fe85Sahl  * You may not use this file except in compliance with the License.
79512fe85Sahl  *
89512fe85Sahl  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
99512fe85Sahl  * or http://www.opensolaris.org/os/licensing.
109512fe85Sahl  * See the License for the specific language governing permissions
119512fe85Sahl  * and limitations under the License.
129512fe85Sahl  *
139512fe85Sahl  * When distributing Covered Code, include this CDDL HEADER in each
149512fe85Sahl  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
159512fe85Sahl  * If applicable, add the following below this CDDL HEADER, with the
169512fe85Sahl  * fields enclosed by brackets "[]" replaced with your own identifying
179512fe85Sahl  * information: Portions Copyright [yyyy] [name of copyright owner]
189512fe85Sahl  *
199512fe85Sahl  * CDDL HEADER END
209512fe85Sahl  */
219512fe85Sahl 
229512fe85Sahl /*
239512fe85Sahl  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
249512fe85Sahl  * Use is subject to license terms.
259512fe85Sahl  */
269512fe85Sahl 
279512fe85Sahl /*
289512fe85Sahl  * ASSERTION:
299512fe85Sahl  *   Declare a dynamic type and then use it to copyin the first 3 environment
309512fe85Sahl  *   variable pointers from the current process.
319512fe85Sahl  *
329512fe85Sahl  * SECTION: Structs and Unions/Structs;
339512fe85Sahl  *	Actions and Subroutines/copyin();
34*05d32fd0SToomas Soome  *	Actions and Subroutines/copyinstr();
359512fe85Sahl  *	Variables/External Variables
369512fe85Sahl  *
379512fe85Sahl  * NOTES:
389512fe85Sahl  *  This test program declares a dynamic type and then uses it to copyin the
399512fe85Sahl  *  first three environment variable pointers from the current process.  We
409512fe85Sahl  *  then use the dynamic type to access the result of our copyin().  The
419512fe85Sahl  *  special "D" module type scope is also tested.
429512fe85Sahl  */
439512fe85Sahl 
449512fe85Sahl #pragma D option quiet
459512fe85Sahl 
469512fe85Sahl struct env_vars_32 {
479512fe85Sahl 	uint32_t e1;
489512fe85Sahl 	uint32_t e2;
499512fe85Sahl 	uint32_t e3;
509512fe85Sahl };
519512fe85Sahl 
52*05d32fd0SToomas Soome struct env_vars_flex_32 {
53*05d32fd0SToomas Soome 	uint32_t e1;
54*05d32fd0SToomas Soome 	uint32_t e2;
55*05d32fd0SToomas Soome 	uint32_t e3[];
56*05d32fd0SToomas Soome };
57*05d32fd0SToomas Soome 
589512fe85Sahl struct env_vars_64 {
599512fe85Sahl 	uint64_t e1;
609512fe85Sahl 	uint64_t e2;
619512fe85Sahl 	uint64_t e3;
629512fe85Sahl };
639512fe85Sahl 
64*05d32fd0SToomas Soome struct env_vars_flex_64 {
65*05d32fd0SToomas Soome 	uint64_t e1;
66*05d32fd0SToomas Soome 	uint64_t e2;
67*05d32fd0SToomas Soome 	uint64_t e3[];
68*05d32fd0SToomas Soome };
69*05d32fd0SToomas Soome 
709512fe85Sahl BEGIN
719512fe85Sahl /curpsinfo->pr_dmodel == PR_MODEL_ILP32/
729512fe85Sahl {
739512fe85Sahl 	e32 = (struct D`env_vars_32 *)
749512fe85Sahl 	    copyin(curpsinfo->pr_envp, sizeof (struct D`env_vars_32));
75*05d32fd0SToomas Soome 	e32f = (struct D`env_vars_flex_32 *)
76*05d32fd0SToomas Soome 	    copyin(curpsinfo->pr_envp, sizeof (struct D`env_vars_flex_32) +
77*05d32fd0SToomas Soome 	    sizeof (uint32_t) * 2);
789512fe85Sahl 
799512fe85Sahl 	printf("e1 = \"%s\"\n", stringof(copyinstr(e32->e1)));
809512fe85Sahl 	printf("e2 = \"%s\"\n", stringof(copyinstr(e32->e2)));
819512fe85Sahl 	printf("e3 = \"%s\"\n", stringof(copyinstr(e32->e3)));
82*05d32fd0SToomas Soome 	printf("\n");
83*05d32fd0SToomas Soome 	printf("e1 = \"%s\"\n", stringof(copyinstr(e32f->e1)));
84*05d32fd0SToomas Soome 	printf("e2 = \"%s\"\n", stringof(copyinstr(e32f->e2)));
85*05d32fd0SToomas Soome 	printf("e3[0] = \"%s\"\n", stringof(copyinstr(e32f->e3[0])));
86*05d32fd0SToomas Soome 	printf("e3[1] = \"%s\"\n", stringof(copyinstr(e32f->e3[1])));
879512fe85Sahl 
889512fe85Sahl 	exit(0);
899512fe85Sahl }
909512fe85Sahl 
919512fe85Sahl BEGIN
929512fe85Sahl /curpsinfo->pr_dmodel == PR_MODEL_LP64/
939512fe85Sahl {
949512fe85Sahl 	e64 = (struct D`env_vars_64 *)
959512fe85Sahl 	    copyin(curpsinfo->pr_envp, sizeof (struct D`env_vars_64));
96*05d32fd0SToomas Soome 	e64f = (struct D`env_vars_flex_64 *)
97*05d32fd0SToomas Soome 	    copyin(curpsinfo->pr_envp, sizeof (struct D`env_vars_flex_64) +
98*05d32fd0SToomas Soome 	    sizeof (uint64_t) * 2);
999512fe85Sahl 
1009512fe85Sahl 	printf("e1 = \"%s\"\n", stringof(copyinstr(e64->e1)));
1019512fe85Sahl 	printf("e2 = \"%s\"\n", stringof(copyinstr(e64->e2)));
1029512fe85Sahl 	printf("e3 = \"%s\"\n", stringof(copyinstr(e64->e3)));
103*05d32fd0SToomas Soome 	printf("\n");
104*05d32fd0SToomas Soome 	printf("e1 = \"%s\"\n", stringof(copyinstr(e64f->e1)));
105*05d32fd0SToomas Soome 	printf("e2 = \"%s\"\n", stringof(copyinstr(e64f->e2)));
106*05d32fd0SToomas Soome 	printf("e3[0] = \"%s\"\n", stringof(copyinstr(e64f->e3[0])));
107*05d32fd0SToomas Soome 	printf("e3[1] = \"%s\"\n", stringof(copyinstr(e64f->e3[1])));
1089512fe85Sahl 
1099512fe85Sahl 	exit(0);
1109512fe85Sahl }
111