xref: /onnv-gate/usr/src/uts/common/sys/va_impl.h (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
23*0Sstevel@tonic-gate /*	  All Rights Reserved	*/
24*0Sstevel@tonic-gate 
25*0Sstevel@tonic-gate 
26*0Sstevel@tonic-gate /*
27*0Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
28*0Sstevel@tonic-gate  * Use is subject to license terms.
29*0Sstevel@tonic-gate  */
30*0Sstevel@tonic-gate 
31*0Sstevel@tonic-gate #ifndef	_SYS_VA_IMPL_H
32*0Sstevel@tonic-gate #define	_SYS_VA_IMPL_H
33*0Sstevel@tonic-gate 
34*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
35*0Sstevel@tonic-gate 
36*0Sstevel@tonic-gate /*
37*0Sstevel@tonic-gate  * An application should not include this header directly.  Instead it
38*0Sstevel@tonic-gate  * should be included only through the inclusion of other Sun headers,
39*0Sstevel@tonic-gate  * specifically <stdarg.h> and <varargs.h>.
40*0Sstevel@tonic-gate  *
41*0Sstevel@tonic-gate  * This header serves two purposes.
42*0Sstevel@tonic-gate  *
43*0Sstevel@tonic-gate  * First, it provides a common set of definitions that implementations
44*0Sstevel@tonic-gate  * of the various standards for variable argument lists may use.  These
45*0Sstevel@tonic-gate  * various standards are implemented in <varargs.h>, <stdarg.h>,
46*0Sstevel@tonic-gate  * <iso/stdarg_iso.h>, <iso/stdarg_c99.h>, and <sys/varargs.h>.
47*0Sstevel@tonic-gate  *
48*0Sstevel@tonic-gate  * Second, it provides varying implementations of the common definitions,
49*0Sstevel@tonic-gate  * depending upon the compiler.
50*0Sstevel@tonic-gate  */
51*0Sstevel@tonic-gate 
52*0Sstevel@tonic-gate /*
53*0Sstevel@tonic-gate  * The common definitions exported by this header or compilers using
54*0Sstevel@tonic-gate  * this header are:
55*0Sstevel@tonic-gate  *
56*0Sstevel@tonic-gate  * the macro __va_start(list, name) starting the list iteration
57*0Sstevel@tonic-gate  * the macro __va_arg(list, type) getting the current arg and iterating
58*0Sstevel@tonic-gate  * the macro __va_copy(to, from) to bookmark the list iteration
59*0Sstevel@tonic-gate  * the macro __va_end(list) to end the iteration
60*0Sstevel@tonic-gate  *
61*0Sstevel@tonic-gate  * In addition, the following are exported via inclusion of <sys/va_list.h>:
62*0Sstevel@tonic-gate  *
63*0Sstevel@tonic-gate  * the identifier __builtin_va_alist for the variable list pseudo parameter
64*0Sstevel@tonic-gate  * the type __va_alist_type for the variable list pseudo parameter
65*0Sstevel@tonic-gate  * the type __va_list defining the type of the variable list iterator
66*0Sstevel@tonic-gate  */
67*0Sstevel@tonic-gate 
68*0Sstevel@tonic-gate /*
69*0Sstevel@tonic-gate  * This header uses feature macros (e.g. __BUILTIN_VA_ARG_INCR and
70*0Sstevel@tonic-gate  * __BUILTIN_VA_STRUCT), compiler macros (e.g. __GNUC__), and processor
71*0Sstevel@tonic-gate  * macros (e.g. __sparc) to determine the protocol appropriate to the
72*0Sstevel@tonic-gate  * current compilation.  It is intended that the compilation system
73*0Sstevel@tonic-gate  * define the feature, processor, and compiler macros, not the user of
74*0Sstevel@tonic-gate  * the system.
75*0Sstevel@tonic-gate  */
76*0Sstevel@tonic-gate 
77*0Sstevel@tonic-gate /*
78*0Sstevel@tonic-gate  * Many compilation systems depend upon the use of special functions
79*0Sstevel@tonic-gate  * built into the the compilation system to handle variable argument
80*0Sstevel@tonic-gate  * lists.  These built-in symbols may include one or more of the
81*0Sstevel@tonic-gate  * following:
82*0Sstevel@tonic-gate  *
83*0Sstevel@tonic-gate  *      __builtin_va_alist
84*0Sstevel@tonic-gate  *      __builtin_va_start
85*0Sstevel@tonic-gate  *      __builtin_va_arg_incr
86*0Sstevel@tonic-gate  *      __builtin_stdarg_start
87*0Sstevel@tonic-gate  *      __builtin_va_end
88*0Sstevel@tonic-gate  *      __builtin_va_arg
89*0Sstevel@tonic-gate  *      __builtin_va_copy
90*0Sstevel@tonic-gate  */
91*0Sstevel@tonic-gate 
92*0Sstevel@tonic-gate /*
93*0Sstevel@tonic-gate  * The following are defined in <sys/va_list.h>:
94*0Sstevel@tonic-gate  *
95*0Sstevel@tonic-gate  *      __va_alist_type
96*0Sstevel@tonic-gate  *      __va_void()
97*0Sstevel@tonic-gate  *      __va_ptr_base
98*0Sstevel@tonic-gate  *      ISA definitions via inclusion of <sys/isa_defs.h>
99*0Sstevel@tonic-gate  *
100*0Sstevel@tonic-gate  * Inclusion of this header also makes visible the symbols in <sys/va_list.h>.
101*0Sstevel@tonic-gate  * This header is included in <varargs.h>, <sys/varargs.h> and in <stdarg.h>
102*0Sstevel@tonic-gate  * via inclusion of <iso/stdarg_iso.h>.
103*0Sstevel@tonic-gate  */
104*0Sstevel@tonic-gate 
105*0Sstevel@tonic-gate #include <sys/va_list.h>
106*0Sstevel@tonic-gate 
107*0Sstevel@tonic-gate #ifdef	__cplusplus
108*0Sstevel@tonic-gate extern "C" {
109*0Sstevel@tonic-gate #endif
110*0Sstevel@tonic-gate 
111*0Sstevel@tonic-gate #if defined(__lint)	/* ---------------------------------------- protocol */
112*0Sstevel@tonic-gate 
113*0Sstevel@tonic-gate #define	__va_start(list, name)	((list) = (__va_list)&name)
114*0Sstevel@tonic-gate #define	__va_arg(list, type)	((type *)(list))[0]
115*0Sstevel@tonic-gate #define	__va_copy(to, from)	__va_void(((to) = (from)))
116*0Sstevel@tonic-gate /*ARGSUSED*/
__va_end(__va_list list)117*0Sstevel@tonic-gate static void __va_end(__va_list list) { __va_end(list); }
118*0Sstevel@tonic-gate 
119*0Sstevel@tonic-gate #elif defined(__BUILTIN_VA_STRUCT)	/* ------------------------ protocol */
120*0Sstevel@tonic-gate 
121*0Sstevel@tonic-gate /* ISA __va_list structures defined in <sys/va_list.h> */
122*0Sstevel@tonic-gate 
123*0Sstevel@tonic-gate #if defined(__STDC__)	/* source language is ISO C or C++ */
124*0Sstevel@tonic-gate 
125*0Sstevel@tonic-gate void __builtin_va_start(__va_list, ...);
126*0Sstevel@tonic-gate void *__builtin_va_arg_incr(__va_list, ...);
127*0Sstevel@tonic-gate 
128*0Sstevel@tonic-gate #else	/* source language is K&R C */
129*0Sstevel@tonic-gate 
130*0Sstevel@tonic-gate int __builtin_va_start();
131*0Sstevel@tonic-gate char *__builtin_va_arg_incr();
132*0Sstevel@tonic-gate 
133*0Sstevel@tonic-gate #endif	/* source language */
134*0Sstevel@tonic-gate 
135*0Sstevel@tonic-gate #define	__va_start(list, name)	__builtin_va_start(list, 0)
136*0Sstevel@tonic-gate #define	__va_arg(list, type)	\
137*0Sstevel@tonic-gate 	((type *)__builtin_va_arg_incr(list, (type *)0))[0]
138*0Sstevel@tonic-gate #define	__va_copy(to, from)	__va_void(((to)[0] = (from)[0]))
139*0Sstevel@tonic-gate #define	__va_end(list)		__va_void(0)
140*0Sstevel@tonic-gate 
141*0Sstevel@tonic-gate #elif defined(__BUILTIN_VA_ARG_INCR)	/* ------------------------ protocol */
142*0Sstevel@tonic-gate 
143*0Sstevel@tonic-gate #define	__va_start(list, name)	\
144*0Sstevel@tonic-gate 	__va_void(((list) = (__va_list)&__builtin_va_alist))
145*0Sstevel@tonic-gate #define	__va_arg(list, type)	\
146*0Sstevel@tonic-gate 	((type *)__builtin_va_arg_incr((type *)(list)))[0]
147*0Sstevel@tonic-gate #define	__va_copy(to, from)	__va_void(((to) = (from)))
148*0Sstevel@tonic-gate #define	__va_end(list)		__va_void(0)
149*0Sstevel@tonic-gate 
150*0Sstevel@tonic-gate #elif defined(__GNUC__)	&& ((__GNUC__ == 2 && __GNUC_MINOR >= 96) || \
151*0Sstevel@tonic-gate 	(__GNUC__ >= 3))		/* ------------------------ protocol */
152*0Sstevel@tonic-gate 
153*0Sstevel@tonic-gate #define	__va_start(list, name)	__builtin_stdarg_start(list, name)
154*0Sstevel@tonic-gate #define	__va_arg(list, type)	__builtin_va_arg(list, type)
155*0Sstevel@tonic-gate #define	__va_end(list)		__builtin_va_end(list)
156*0Sstevel@tonic-gate #define	__va_copy(to, from)	__builtin_va_copy(to, from)
157*0Sstevel@tonic-gate 
158*0Sstevel@tonic-gate #else					/* ----------------------- protocol */
159*0Sstevel@tonic-gate 
160*0Sstevel@tonic-gate /*
161*0Sstevel@tonic-gate  * Because we can not predict the compiler protocol for unknown compilers, we
162*0Sstevel@tonic-gate  * force an error in order to avoid unpredictable behavior. For versions of
163*0Sstevel@tonic-gate  * gcc 2.95 and earlier, variable argument lists are handled in gcc specific
164*0Sstevel@tonic-gate  * stdarg.h and varargs.h headers created via the gcc fixincl utility. In
165*0Sstevel@tonic-gate  * those cases, the gcc headers would override this header.
166*0Sstevel@tonic-gate  */
167*0Sstevel@tonic-gate 
168*0Sstevel@tonic-gate #error("Unrecognized compiler protocol for variable argument lists")
169*0Sstevel@tonic-gate 
170*0Sstevel@tonic-gate #endif  /* -------------------------------------------------------- protocol */
171*0Sstevel@tonic-gate 
172*0Sstevel@tonic-gate #ifdef	__cplusplus
173*0Sstevel@tonic-gate }
174*0Sstevel@tonic-gate #endif
175*0Sstevel@tonic-gate 
176*0Sstevel@tonic-gate #endif	/* _SYS_VA_IMPL_H */
177