From b2b2f7ccfaeda607d7829f0fa4afc107bee54a43 Mon Sep 17 00:00:00 2001 From: simonb Date: Fri, 17 Aug 2001 07:15:16 +0000 Subject: [PATCH] Fix va_arg() problem when adjusting argument pointer when a structure is passed which is larger than an int but has int alignment. As well as fixing the described problem, this is the same way it is handled in the Irix and Ultrix header files. Problem and suggested solution by Uros Prestor in port-mips mailling list. --- sys/arch/mips/include/stdarg.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/sys/arch/mips/include/stdarg.h b/sys/arch/mips/include/stdarg.h index b2b501244322..ffbe077d5b08 100644 --- a/sys/arch/mips/include/stdarg.h +++ b/sys/arch/mips/include/stdarg.h @@ -1,4 +1,4 @@ -/* $NetBSD: stdarg.h,v 1.19 2000/02/19 09:23:44 mycroft Exp $ */ +/* $NetBSD: stdarg.h,v 1.20 2001/08/17 07:15:16 simonb Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -41,6 +41,10 @@ #include #include +#if defined(_MIPS_BSD_API) && _MIPS_BSD_API != _MIPS_BSD_API_LP32 +#error stdargs.h does not work with 64 bit ABIs +#endif + typedef _BSD_VA_LIST_ va_list; #ifdef __lint__ @@ -53,15 +57,15 @@ typedef _BSD_VA_LIST_ va_list; #if BYTE_ORDER == LITTLE_ENDIAN #define va_arg(ap, T) \ (((T *)( \ - (ap) += (/*CONSTCOND*/ sizeof(T) <= sizeof(int) \ + (ap) += (/*CONSTCOND*/ __alignof__(T) <= sizeof(int) \ ? sizeof(int) : ((long)(ap) & 4) + sizeof(T)), \ - (ap) - (/*CONSTCOND*/ sizeof(T) <= sizeof(int) \ + (ap) - (/*CONSTCOND*/ __alignof__(T) <= sizeof(int) \ ? sizeof(int) : sizeof(T)) \ ))[0]) #else #define va_arg(ap, T) \ (((T *)( \ - (ap) += (/*CONSTCOND*/ sizeof(T) <= sizeof(int) \ + (ap) += (/*CONSTCOND*/ __alignof__(T) <= sizeof(int) \ ? sizeof(int) : ((long)(ap) & 4) + sizeof(T)) \ ))[-1]) #endif