Use standard pattern for stdargs.h

We don't support older compilers. Most of the code in these files is
for pre-3.0 gcc, which is at least 15 years obsolete. Move to using
phk's sys/_stdargs.h for all these platforms.

Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D14323
This commit is contained in:
Warner Losh 2018-02-12 14:48:05 +00:00
parent 58a6aaf7ec
commit 33e959abab
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=329163
4 changed files with 62 additions and 384 deletions

View File

@ -1,144 +1,39 @@
/*
* JNPR: stdarg.h,v 1.3 2006/09/15 12:52:34 katta
/*-
* SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2017 Poul-Henning Kamp. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#ifndef _MACHINE_STDARG_H_
#define _MACHINE_STDARG_H_
#include <sys/cdefs.h>
#include <sys/_types.h>
#include <sys/_stdarg.h>
#if __GNUC__ >= 3
#ifndef _VA_LIST_DECLARED
#define _VA_LIST_DECLARED
typedef __va_list va_list;
#endif
#define va_start(v,l) __builtin_va_start((v),l)
#define va_end __builtin_va_end
#define va_arg __builtin_va_arg
#define va_copy __builtin_va_copy
#else /* __GNUC__ */
/* ---------------------------------------- */
/* VARARGS for MIPS/GNU CC */
/* ---------------------------------------- */
#include <machine/endian.h>
/* These macros implement varargs for GNU C--either traditional or ANSI. */
/* Define __gnuc_va_list. */
#ifndef __GNUC_VA_LIST
#define __GNUC_VA_LIST
typedef char * __gnuc_va_list;
typedef __gnuc_va_list va_list;
#endif /* ! __GNUC_VA_LIST */
/* If this is for internal libc use, don't define anything but
__gnuc_va_list. */
#ifndef _VA_MIPS_H_ENUM
#define _VA_MIPS_H_ENUM
enum {
__no_type_class = -1,
__void_type_class,
__integer_type_class,
__char_type_class,
__enumeral_type_class,
__boolean_type_class,
__pointer_type_class,
__reference_type_class,
__offset_type_class,
__real_type_class,
__complex_type_class,
__function_type_class,
__method_type_class,
__record_type_class,
__union_type_class,
__array_type_class,
__string_type_class,
__set_type_class,
__file_type_class,
__lang_type_class
};
#ifndef va_start
#error this file needs to be ported to your compiler
#endif
/* In GCC version 2, we want an ellipsis at the end of the declaration
of the argument list. GCC version 1 can't parse it. */
#if __GNUC__ > 1
#define __va_ellipsis ...
#else
#define __va_ellipsis
#endif
#define va_start(__AP, __LASTARG) \
(__AP = (__gnuc_va_list) __builtin_next_arg (__LASTARG))
#define va_end(__AP) ((void)0)
/* We cast to void * and then to TYPE * because this avoids
a warning about increasing the alignment requirement. */
/* The __mips64 cases are reversed from the 32 bit cases, because the standard
32 bit calling convention left-aligns all parameters smaller than a word,
whereas the __mips64 calling convention does not (and hence they are
right aligned). */
#ifdef __mips64
#define __va_rounded_size(__TYPE) (((sizeof (__TYPE) + 8 - 1) / 8) * 8)
#define __va_reg_size 8
#if defined(__MIPSEB__) || (BYTE_ORDER == BIG_ENDIAN)
#define va_arg(__AP, __type) \
((__type *) (void *) (__AP = (char *) \
((((__PTRDIFF_TYPE__)__AP + 8 - 1) & -8) \
+ __va_rounded_size (__type))))[-1]
#else /* ! __MIPSEB__ && !BYTE_ORDER == BIG_ENDIAN */
#define va_arg(__AP, __type) \
((__AP = (char *) ((((__PTRDIFF_TYPE__)__AP + 8 - 1) & -8) \
+ __va_rounded_size (__type))), \
*(__type *) (void *) (__AP - __va_rounded_size (__type)))
#endif /* ! __MIPSEB__ && !BYTE_ORDER == BIG_ENDIAN */
#else /* ! __mips64 */
#define __va_rounded_size(__TYPE) \
(((sizeof (__TYPE) + sizeof (int) - 1) / sizeof (int)) * sizeof (int))
#define __va_reg_size 4
#if defined(__MIPSEB__) || (BYTE_ORDER == BIG_ENDIAN)
/* For big-endian machines. */
#define va_arg(__AP, __type) \
((__AP = (char *) ((__alignof__ (__type) > 4 \
? ((__PTRDIFF_TYPE__)__AP + 8 - 1) & -8 \
: ((__PTRDIFF_TYPE__)__AP + 4 - 1) & -4) \
+ __va_rounded_size (__type))), \
*(__type *) (void *) (__AP - __va_rounded_size (__type)))
#else /* ! __MIPSEB__ && !BYTE_ORDER == BIG_ENDIAN */
/* For little-endian machines. */
#define va_arg(__AP, __type) \
((__type *) (void *) (__AP = (char *) ((__alignof__(__type) > 4 \
? ((__PTRDIFF_TYPE__)__AP + 8 - 1) & -8 \
: ((__PTRDIFF_TYPE__)__AP + 4 - 1) & -4) \
+ __va_rounded_size(__type))))[-1]
#endif /* ! __MIPSEB__ && !BYTE_ORDER == BIG_ENDIAN */
#endif /* ! __mips64 */
/* Copy __gnuc_va_list into another variable of this type. */
#define __va_copy(dest, src) (dest) = (src)
#define va_copy(dest, src) (dest) = (src)
#endif /* __GNUC__ */
#endif /* _MACHINE_STDARG_H_ */
#endif /* !_MACHINE_STDARG_H_ */

View File

@ -1,8 +1,7 @@
/*-
* SPDX-License-Identifier: BSD-3-Clause
* SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2002 David E. O'Brien. All rights reserved.
* Copyright (c) 2000 Tsubai Masanari. All rights reserved.
* Copyright (c) 2017 Poul-Henning Kamp. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -12,141 +11,29 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $NetBSD: stdarg.h,v 1.5 2000/02/27 17:50:21 tsubai Exp $
* $FreeBSD$
*/
#ifndef _MACHINE_STDARG_H_
#define _MACHINE_STDARG_H_
#include <sys/cdefs.h>
#include <sys/_types.h>
#include <sys/_stdarg.h>
#ifndef _VA_LIST_DECLARED
#define _VA_LIST_DECLARED
typedef __va_list va_list;
#ifndef va_start
#error this file needs to be ported to your compiler
#endif
#if defined(__GNUCLIKE_BUILTIN_STDARG)
#define va_start(ap, last) \
__builtin_va_start((ap), (last))
#define va_arg(ap, type) \
__builtin_va_arg((ap), type)
#if __ISO_C_VISIBLE >= 1999
#define va_copy(dest, src) \
__builtin_va_copy((dest), (src))
#define __va_copy(dest, src) \
va_copy((dest), (src))
#endif
#define va_end(ap) \
__builtin_va_end(ap)
#else /* !__GNUCLIKE_BUILTIN_STDARG */
#ifdef __lint__
#define va_start(ap, last) ((ap) = *(va_list *)0)
#define va_arg(ap, type) (*(type *)(void *)&(ap))
#else
#if defined(__GNUC_VA_LIST_COMPATIBILITY)
#define va_start(ap, last) \
(__builtin_next_arg(last), \
__builtin_memcpy((void *)&(ap), __builtin_saveregs (), \
sizeof(__gnuc_va_list)))
#else
#define va_start(ap, last) \
(__builtin_next_arg(last), \
(ap).__stack = __va_stack_args, \
(ap).__base = __va_reg_args, \
(ap).__gpr = __va_first_gpr, \
(ap).__fpr = __va_first_fpr)
#endif
#define __va_first_gpr (__builtin_args_info(0))
#define __va_first_fpr (__builtin_args_info(1) - 32 - 1)
#define __va_stack_args \
((char *)__builtin_saveregs() + \
(__va_first_gpr >= 8 ? __va_first_gpr - 8 : 0) * sizeof(int))
#define __va_reg_args \
((char *)__builtin_frame_address(0) + __builtin_args_info(4))
#define __INTEGER_TYPE_CLASS 1
#define __REAL_TYPE_CLASS 8
#define __RECORD_TYPE_CLASS 12
#define __va_longlong(type) \
(__builtin_classify_type(*(type *)0) == __INTEGER_TYPE_CLASS && \
sizeof(type) == 8)
#define __va_double(type) \
(__builtin_classify_type(*(type *)0) == __REAL_TYPE_CLASS)
#define __va_struct(type) \
(__builtin_classify_type(*(type *)0) >= __RECORD_TYPE_CLASS)
#define __va_size(type) \
((sizeof(type) + sizeof(int) - 1) / sizeof(int) * sizeof(int))
#define __va_savedgpr(ap, type) \
((ap).__base + (ap).__gpr * sizeof(int) - sizeof(type))
#define __va_savedfpr(ap, type) \
((ap).__base + 8 * sizeof(int) + (ap).__fpr * sizeof(double) - \
sizeof(type))
#define __va_stack(ap, type) \
((ap).__stack += __va_size(type) + \
(__va_longlong(type) ? (int)(ap).__stack & 4 : 0), \
(ap).__stack - sizeof(type))
#define __va_gpr(ap, type) \
((ap).__gpr += __va_size(type) / sizeof(int) + \
(__va_longlong(type) ? (ap).__gpr & 1 : 0), \
(ap).__gpr <= 8 ? __va_savedgpr(ap, type) : __va_stack(ap, type))
#define __va_fpr(ap, type) \
((ap).__fpr++, \
(ap).__fpr <= 8 ? __va_savedfpr(ap, type) : __va_stack(ap, type))
#define va_arg(ap, type) \
(*(type *)(__va_struct(type) ? (*(void **)__va_gpr(ap, void *)) : \
__va_double(type) ? __va_fpr(ap, type) : \
__va_gpr(ap, type)))
#endif /* __lint__ */
#define va_end(ap)
#if __ISO_C_VISIBLE >= 1999
#if !defined(_ANSI_SOURCE) && \
(!defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE) || \
defined(_ISOC99_SOURCE) || (__STDC_VERSION__ - 0) >= 199901L)
#define va_copy(dest, src) \
((dest) = (src))
#endif
#endif
#endif /* __GNUCLIKE_BUILTIN_STDARG */
#endif /* _MACHINE_STDARG_H_ */
#endif /* !_MACHINE_STDARG_H_ */

View File

@ -1,7 +1,7 @@
/*-
* Copyright (c) 2002 David E. O'Brien. All rights reserved.
* Copyright (c) 1991, 1993
* The Regents of the University of California. All rights reserved.
* SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2017 Poul-Henning Kamp. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -11,14 +11,11 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
@ -27,53 +24,16 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)stdarg.h 8.1 (Berkeley) 6/10/93
* $FreeBSD$
*/
#ifndef _MACHINE_STDARG_H_
#define _MACHINE_STDARG_H_
#include <sys/cdefs.h>
#include <sys/_types.h>
#include <sys/_stdarg.h>
#ifndef _VA_LIST_DECLARED
#define _VA_LIST_DECLARED
typedef __va_list va_list;
#ifndef va_start
#error this file needs to be ported to your compiler
#endif
#ifdef __GNUCLIKE_BUILTIN_STDARG
#define va_start(ap, last) \
__builtin_va_start((ap), (last))
#define va_arg(ap, type) \
__builtin_va_arg((ap), type)
#if __ISO_C_VISIBLE >= 1999
#define va_copy(dest, src) \
__builtin_va_copy((dest), (src))
#endif
#define va_end(ap) \
__builtin_va_end(ap)
#elif defined(lint)
/* Provide a fake implementation for lint's benefit */
#define __va_size(type) \
(((sizeof(type) + sizeof(long) - 1) / sizeof(long)) * sizeof(long))
#define va_start(ap, last) \
((ap) = (va_list)&(last) + __va_size(last))
#define va_copy(dst, src) \
((dst) = (src))
#define va_arg(ap, type) \
(*(type *)((ap) += __va_size(type), (ap) - __va_size(type)))
#define va_end(ap)
#else /* !__GNUCLIKE_BUILTIN_STDARG */
#error no support for your compiler
#endif /* __GNUCLIKE_BUILTIN_STDARG */
#endif /* !_MACHINE_STDARG_H_ */

View File

@ -1,18 +1,7 @@
/*-
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
* SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2002 David E. O'Brien. All rights reserved.
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
*
* This software was developed by the Computer Systems Engineering group
* at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
* contributed to Berkeley.
*
* All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Lawrence Berkeley Laboratory.
* Copyright (c) 2017 Poul-Henning Kamp. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -23,10 +12,10 @@
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
@ -35,69 +24,16 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)stdarg.h 8.2 (Berkeley) 9/27/93
* $NetBSD: stdarg.h,v 1.11 2000/07/23 21:36:56 mycroft Exp $
* $FreeBSD$
*/
#ifndef _MACHINE_STDARG_H_
#define _MACHINE_STDARG_H_
#include <sys/cdefs.h>
#include <sys/_types.h>
#include <sys/_stdarg.h>
#ifndef _VA_LIST_DECLARED
#define _VA_LIST_DECLARED
typedef __va_list va_list;
#ifndef va_start
#error this file needs to be ported to your compiler
#endif
#ifdef __GNUCLIKE_BUILTIN_STDARG
#define va_start(ap, last) \
__builtin_va_start((ap), (last))
#define va_arg(ap, type) \
__builtin_va_arg((ap), type)
#if __ISO_C_VISIBLE >= 1999
#define va_copy(dest, src) \
__builtin_va_copy((dest), (src))
#endif
#define va_end(ap) \
__builtin_va_end(ap)
#else /* ! __GNUCLIKE_BUILTIN_STDARG */
#if !defined(__GNUCLIKE_BUILTIN_NEXT_ARG) && !defined(lint)
#error no support for your compiler
#endif
#define va_start(ap, last) \
(__builtin_next_arg(last), (ap) = (va_list)__builtin_saveregs())
#define va_end(ap)
#define __va_arg8(ap, type) \
(*(type *)(void *)((ap) += 8, (ap) - 8))
#define __va_arg16(ap, type) \
(*(type *)(void *)((ap) = (va_list)(((unsigned long)(ap) + 31) & -16),\
(ap) - 16))
#define __va_int(ap, type) \
(*(type *)(void *)((ap) += 8, (ap) - sizeof(type)))
#define __REAL_TYPE_CLASS 8
#define __RECORD_TYPE_CLASS 12
#define va_arg(ap, type) \
(__builtin_classify_type(*(type *)0) == __REAL_TYPE_CLASS ? \
(__alignof__(type) == 16 ? __va_arg16(ap, type) : \
__va_arg8(ap, type)) : \
(__builtin_classify_type(*(type *)0) < __RECORD_TYPE_CLASS ? \
__va_int(ap, type) : \
(sizeof(type) <= 8 ? __va_arg8(ap, type) : \
(sizeof(type) <= 16 ? __va_arg16(ap, type) : \
*__va_arg8(ap, type *)))))
#endif /* __GNUCLIKE_BUILTIN_STDARG */
#endif /* !_MACHINE_STDARG_H_ */