From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=209.132.183.28; helo=mx1.redhat.com; envelope-from=lersek@redhat.com; receiver=edk2-devel@lists.01.org Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 9517721A1099A for ; Tue, 12 Dec 2017 01:11:40 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9DBFC7F41D; Tue, 12 Dec 2017 09:16:18 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-120-105.rdu2.redhat.com [10.10.120.105]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5DE1D5D756; Tue, 12 Dec 2017 09:16:17 +0000 (UTC) To: Zenith432 , edk2-devel@lists.01.org Cc: michael.d.kinney@intel.com, liming.gao@intel.com References: <1667068483.2112668.1512898346914.ref@mail.yahoo.com> <1667068483.2112668.1512898346914@mail.yahoo.com> From: Laszlo Ersek Message-ID: Date: Tue, 12 Dec 2017 10:16:16 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 In-Reply-To: <1667068483.2112668.1512898346914@mail.yahoo.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Tue, 12 Dec 2017 09:16:18 +0000 (UTC) Subject: Re: [PATCH] MdePkg: correct and clarify documentation of VA_LIST in Base.h X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Dec 2017 09:11:40 -0000 Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Hi, On 12/10/17 10:32, Zenith432 wrote: > This is to resolve bug 457. > > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Zenith432 > --- > MdePkg/Include/Base.h | 24 ++++++++++++++++++++---- > 1 file changed, 20 insertions(+), 4 deletions(-) I'm commenting on this patch because Liming asked me to. I'm stating my opinion below; remember that I'm not an MdePkg maintainer. > diff --git a/MdePkg/Include/Base.h b/MdePkg/Include/Base.h > index 02140a5a..19f36872 100644 > --- a/MdePkg/Include/Base.h > +++ b/MdePkg/Include/Base.h > @@ -560,13 +560,14 @@ struct _LIST_ENTRY { > // VA_LIST - typedef for argument list. > // VA_START (VA_LIST Marker, argument before the ...) - Init Marker for use. > // VA_END (VA_LIST Marker) - Clear Marker > -// VA_ARG (VA_LIST Marker, var arg size) - Use Marker to get an argument from > -// the ... list. You must know the size and pass it in this macro. > +// VA_ARG (VA_LIST Marker, var arg type) - Use Marker to get an argument from > +// the ... list. You must know the type and pass it in this macro. > // VA_COPY (VA_LIST Dest, VA_LIST Start) - Initialize Dest as a copy of Start. (1) I suggest adding "Type must be compatible with the type of the actual next argument (as promoted according to the default argument promotions)". (This is not the full story either, but it would still remain short enough, and be an improvement.) > // > -// example: > +// Example: > // > // UINTN > +// EFIAPI > // ExampleVarArg ( > // IN UINTN NumberOfArgs, > // ... Correct. > @@ -582,7 +583,7 @@ struct _LIST_ENTRY { > // VA_START (Marker, NumberOfArgs); > // for (Index = 0, Result = 0; Index < NumberOfArgs; Index++) { > // // > -// // The ... list is a series of UINTN values, so average them up. > +// // The ... list is a series of UINTN values, so sum them up. > // // > // Result += VA_ARG (Marker, UINTN); > // } > @@ -591,6 +592,21 @@ struct _LIST_ENTRY { > // return Result (2) Maybe append a semicolon? (Not strictly the topic of this patch, but we're fixing up other typos anyway.) > // } > // > +// Notes: > +// > +// This set of macros is intended to support variadic functions that > +// use the EFIAPI calling convention. Variadic functions that use a > +// native calling convention should use stdarg.h. I disagree with this wording. "MdePkg/Include/Base.h" should be very careful about referencing dependent packages, even in comments. The only "stdarg.h" file in the tree (that is meant to be included by client code directly) is StdLib/Include/stdarg.h I'll comment on that lower down. > +// In particular: > +// -- VA_START may only be used in a variadic EFIAPI function. > +// -- va_start may only be used in a variadic native function. > +// -- VA_START, VA_END, VA_ARG and VA_COPY may only be used on a VA_LIST. > +// -- va_start, va_end, va_arg and va_copy may only be used on a va_list. > +// -- Both VA_LIST or va_list may be passed as arguments to functions > +// of either EFIAPI or native calling conventions. > +// -- VA_END, VA_ARG, VA_COPY, va_end, va_arg, and va_copy may be used > +// in functions of either calling conventions. > +// I would drop the language on the lower-case va_* macros and the native calling convention altogether. In Base.h we should give *practical* instructions for using variable argument lists with *these* macros (i.e. the macros from Base.h), such that they work with any edk2-supported toolchain. (3) So, as I wrote in the BZ, I would replace this Notes section with: Notes: - Functions that have a variable argument list and call VA_START() / VA_END() must be declared EFIAPI. - Functions that call VA_COPY() must be declared EFIAPI. - Functions that only use VA_LIST and VA_ARG() need not be EFIAPI. Now, if we want to consider any interactions with StdLib/Include/stdarg.h plus other standard C functions that take a variable argument list, then any such considerations should be added to "StdLib/Include/stdarg.h". (Unless I'm writing a UEFI_APPLICATION module with standard C functions from StdLib, I don't want to read anything related to va_*.) (4) Thus, I suggest that we additionally *replace* the following leading comment: // // Support for variable length argument lists using the ANSI standard. // // Since we are using the ANSI standard we used the standard naming and // did not follow the coding convention // with: // // Support for variable argument lists in freestanding edk2 modules. // // For modules that use the ISO C library interfaces for variable // argument lists, refer to "StdLib/Include/stdarg.h". // Just my two cents. Thanks Laszlo > > /** > Return the size of argument that has been aligned to sizeof (UINTN). >