xref: /illumos-gate/usr/src/uts/common/sys/va_impl.h (revision ba3594ba)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
237c478bd9Sstevel@tonic-gate /*	  All Rights Reserved	*/
247c478bd9Sstevel@tonic-gate 
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate /*
27*ba3594baSGarrett D'Amore  * Copyright 2014 Garrett D'Amore <garrett@damore.org>
28*ba3594baSGarrett D'Amore  *
297c478bd9Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
307c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
317c478bd9Sstevel@tonic-gate  */
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #ifndef	_SYS_VA_IMPL_H
347c478bd9Sstevel@tonic-gate #define	_SYS_VA_IMPL_H
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate /*
377c478bd9Sstevel@tonic-gate  * An application should not include this header directly.  Instead it
387c478bd9Sstevel@tonic-gate  * should be included only through the inclusion of other Sun headers,
397c478bd9Sstevel@tonic-gate  * specifically <stdarg.h> and <varargs.h>.
407c478bd9Sstevel@tonic-gate  *
417c478bd9Sstevel@tonic-gate  * This header serves two purposes.
427c478bd9Sstevel@tonic-gate  *
437c478bd9Sstevel@tonic-gate  * First, it provides a common set of definitions that implementations
447c478bd9Sstevel@tonic-gate  * of the various standards for variable argument lists may use.  These
457c478bd9Sstevel@tonic-gate  * various standards are implemented in <varargs.h>, <stdarg.h>,
467c478bd9Sstevel@tonic-gate  * <iso/stdarg_iso.h>, <iso/stdarg_c99.h>, and <sys/varargs.h>.
477c478bd9Sstevel@tonic-gate  *
487c478bd9Sstevel@tonic-gate  * Second, it provides varying implementations of the common definitions,
497c478bd9Sstevel@tonic-gate  * depending upon the compiler.
507c478bd9Sstevel@tonic-gate  */
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate /*
537c478bd9Sstevel@tonic-gate  * The common definitions exported by this header or compilers using
547c478bd9Sstevel@tonic-gate  * this header are:
557c478bd9Sstevel@tonic-gate  *
567c478bd9Sstevel@tonic-gate  * the macro __va_start(list, name) starting the list iteration
577c478bd9Sstevel@tonic-gate  * the macro __va_arg(list, type) getting the current arg and iterating
587c478bd9Sstevel@tonic-gate  * the macro __va_copy(to, from) to bookmark the list iteration
597c478bd9Sstevel@tonic-gate  * the macro __va_end(list) to end the iteration
607c478bd9Sstevel@tonic-gate  *
617c478bd9Sstevel@tonic-gate  * In addition, the following are exported via inclusion of <sys/va_list.h>:
627c478bd9Sstevel@tonic-gate  *
637c478bd9Sstevel@tonic-gate  * the identifier __builtin_va_alist for the variable list pseudo parameter
647c478bd9Sstevel@tonic-gate  * the type __va_alist_type for the variable list pseudo parameter
657c478bd9Sstevel@tonic-gate  * the type __va_list defining the type of the variable list iterator
667c478bd9Sstevel@tonic-gate  */
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate /*
697c478bd9Sstevel@tonic-gate  * This header uses feature macros (e.g. __BUILTIN_VA_ARG_INCR and
707c478bd9Sstevel@tonic-gate  * __BUILTIN_VA_STRUCT), compiler macros (e.g. __GNUC__), and processor
717c478bd9Sstevel@tonic-gate  * macros (e.g. __sparc) to determine the protocol appropriate to the
727c478bd9Sstevel@tonic-gate  * current compilation.  It is intended that the compilation system
737c478bd9Sstevel@tonic-gate  * define the feature, processor, and compiler macros, not the user of
747c478bd9Sstevel@tonic-gate  * the system.
757c478bd9Sstevel@tonic-gate  */
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate /*
787c478bd9Sstevel@tonic-gate  * Many compilation systems depend upon the use of special functions
797c478bd9Sstevel@tonic-gate  * built into the the compilation system to handle variable argument
807c478bd9Sstevel@tonic-gate  * lists.  These built-in symbols may include one or more of the
817c478bd9Sstevel@tonic-gate  * following:
827c478bd9Sstevel@tonic-gate  *
837c478bd9Sstevel@tonic-gate  *      __builtin_va_alist
847c478bd9Sstevel@tonic-gate  *      __builtin_va_start
857c478bd9Sstevel@tonic-gate  *      __builtin_va_arg_incr
867c478bd9Sstevel@tonic-gate  *      __builtin_stdarg_start
877c478bd9Sstevel@tonic-gate  *      __builtin_va_end
887c478bd9Sstevel@tonic-gate  *      __builtin_va_arg
897c478bd9Sstevel@tonic-gate  *      __builtin_va_copy
907c478bd9Sstevel@tonic-gate  */
917c478bd9Sstevel@tonic-gate 
927c478bd9Sstevel@tonic-gate /*
937c478bd9Sstevel@tonic-gate  * The following are defined in <sys/va_list.h>:
947c478bd9Sstevel@tonic-gate  *
957c478bd9Sstevel@tonic-gate  *      __va_alist_type
967c478bd9Sstevel@tonic-gate  *      __va_void()
977c478bd9Sstevel@tonic-gate  *      __va_ptr_base
987c478bd9Sstevel@tonic-gate  *      ISA definitions via inclusion of <sys/isa_defs.h>
997c478bd9Sstevel@tonic-gate  *
1007c478bd9Sstevel@tonic-gate  * Inclusion of this header also makes visible the symbols in <sys/va_list.h>.
1017c478bd9Sstevel@tonic-gate  * This header is included in <varargs.h>, <sys/varargs.h> and in <stdarg.h>
1027c478bd9Sstevel@tonic-gate  * via inclusion of <iso/stdarg_iso.h>.
1037c478bd9Sstevel@tonic-gate  */
1047c478bd9Sstevel@tonic-gate 
1057c478bd9Sstevel@tonic-gate #include <sys/va_list.h>
1067c478bd9Sstevel@tonic-gate 
1077c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1087c478bd9Sstevel@tonic-gate extern "C" {
1097c478bd9Sstevel@tonic-gate #endif
1107c478bd9Sstevel@tonic-gate 
1117c478bd9Sstevel@tonic-gate #if defined(__lint)	/* ---------------------------------------- protocol */
1127c478bd9Sstevel@tonic-gate 
1137c478bd9Sstevel@tonic-gate #define	__va_start(list, name)	((list) = (__va_list)&name)
1147c478bd9Sstevel@tonic-gate #define	__va_arg(list, type)	((type *)(list))[0]
1157c478bd9Sstevel@tonic-gate #define	__va_copy(to, from)	__va_void(((to) = (from)))
1167c478bd9Sstevel@tonic-gate /*ARGSUSED*/
__va_end(__va_list list)1177c478bd9Sstevel@tonic-gate static void __va_end(__va_list list) { __va_end(list); }
1187c478bd9Sstevel@tonic-gate 
1197c478bd9Sstevel@tonic-gate #elif defined(__BUILTIN_VA_STRUCT)	/* ------------------------ protocol */
1207c478bd9Sstevel@tonic-gate 
1217c478bd9Sstevel@tonic-gate /* ISA __va_list structures defined in <sys/va_list.h> */
1227c478bd9Sstevel@tonic-gate 
1237c478bd9Sstevel@tonic-gate void __builtin_va_start(__va_list, ...);
1247c478bd9Sstevel@tonic-gate void *__builtin_va_arg_incr(__va_list, ...);
1257c478bd9Sstevel@tonic-gate 
1267c478bd9Sstevel@tonic-gate #define	__va_start(list, name)	__builtin_va_start(list, 0)
1277c478bd9Sstevel@tonic-gate #define	__va_arg(list, type)	\
1287c478bd9Sstevel@tonic-gate 	((type *)__builtin_va_arg_incr(list, (type *)0))[0]
1297c478bd9Sstevel@tonic-gate #define	__va_copy(to, from)	__va_void(((to)[0] = (from)[0]))
1307c478bd9Sstevel@tonic-gate #define	__va_end(list)		__va_void(0)
1317c478bd9Sstevel@tonic-gate 
1327c478bd9Sstevel@tonic-gate #elif defined(__BUILTIN_VA_ARG_INCR)	/* ------------------------ protocol */
1337c478bd9Sstevel@tonic-gate 
1347c478bd9Sstevel@tonic-gate #define	__va_start(list, name)	\
1357c478bd9Sstevel@tonic-gate 	__va_void(((list) = (__va_list)&__builtin_va_alist))
1367c478bd9Sstevel@tonic-gate #define	__va_arg(list, type)	\
1377c478bd9Sstevel@tonic-gate 	((type *)__builtin_va_arg_incr((type *)(list)))[0]
1387c478bd9Sstevel@tonic-gate #define	__va_copy(to, from)	__va_void(((to) = (from)))
1397c478bd9Sstevel@tonic-gate #define	__va_end(list)		__va_void(0)
1407c478bd9Sstevel@tonic-gate 
141135e56f2SRichard Lowe #elif defined(__GNUC__)	&& ((__GNUC__ == 2 && __GNUC_MINOR__ >= 96) || \
1427c478bd9Sstevel@tonic-gate 	(__GNUC__ >= 3))		/* ------------------------ protocol */
143135e56f2SRichard Lowe #if (__GNUC__ < 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ < 3))
1447c478bd9Sstevel@tonic-gate #define	__va_start(list, name)	__builtin_stdarg_start(list, name)
145135e56f2SRichard Lowe #else
146135e56f2SRichard Lowe #define	__va_start(list, name)	__builtin_va_start(list, name)
147135e56f2SRichard Lowe #endif
148135e56f2SRichard Lowe 
1497c478bd9Sstevel@tonic-gate #define	__va_arg(list, type)	__builtin_va_arg(list, type)
1507c478bd9Sstevel@tonic-gate #define	__va_end(list)		__builtin_va_end(list)
1517c478bd9Sstevel@tonic-gate #define	__va_copy(to, from)	__builtin_va_copy(to, from)
1527c478bd9Sstevel@tonic-gate 
1537c478bd9Sstevel@tonic-gate #else					/* ----------------------- protocol */
1547c478bd9Sstevel@tonic-gate 
1557c478bd9Sstevel@tonic-gate /*
1567c478bd9Sstevel@tonic-gate  * Because we can not predict the compiler protocol for unknown compilers, we
1577c478bd9Sstevel@tonic-gate  * force an error in order to avoid unpredictable behavior. For versions of
1587c478bd9Sstevel@tonic-gate  * gcc 2.95 and earlier, variable argument lists are handled in gcc specific
1597c478bd9Sstevel@tonic-gate  * stdarg.h and varargs.h headers created via the gcc fixincl utility. In
1607c478bd9Sstevel@tonic-gate  * those cases, the gcc headers would override this header.
1617c478bd9Sstevel@tonic-gate  */
1627c478bd9Sstevel@tonic-gate 
1637c478bd9Sstevel@tonic-gate #error("Unrecognized compiler protocol for variable argument lists")
1647c478bd9Sstevel@tonic-gate 
1657c478bd9Sstevel@tonic-gate #endif  /* -------------------------------------------------------- protocol */
1667c478bd9Sstevel@tonic-gate 
1677c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1687c478bd9Sstevel@tonic-gate }
1697c478bd9Sstevel@tonic-gate #endif
1707c478bd9Sstevel@tonic-gate 
1717c478bd9Sstevel@tonic-gate #endif	/* _SYS_VA_IMPL_H */
172