Re: [edk2] UnicodeVSPrint returns nonsense string length

Subject: Re: [edk2] UnicodeVSPrint returns nonsense string length

From: duck wilson <duck.54321@gmail.com>

To: edk2-devel@lists.sourceforge.net

Date: 2012-10-24 04:24:16

Thanks MUCH Jordan! Adding EFIAPI to the function declararion solved the problem
as in,

UINTN
EFIAPI
fooprint (
IN CONST CHAR16 *Format,
...
)

I inherited a mixture of working EDK production code and some working, and some not,
EDK2 code. This problem arose in some code ported from EDK to EDK2 that I inherited
in midstream development. Was a headache to track down since it involved pointers that
eventually got whacked. The fact the EDK production code works fine added to the debug
confusion. BTW, I am using GCC 4.7 with the build tools patch for GCC47. Looks like a
filter script is in order to sniff the source code for more instances of this issue.

On Tue, Oct 23, 2012 at 11:44 AM, Jordan Justen <jljusten@gmail.com> wrote:
On Tue, Oct 23, 2012 at 5:43 AM, duck wilson <duck.54321@gmail.com> wrote:
> UnicodeVSPrint is not returning the correct (expected) string length. The
> simple program below demonstrates
> the problem. The build environment is UDK2010.SR1.UP1. This demo was built
> as a module in MdeModulePkg.
> When the demo program is run the output is:
>
> fooprint:Count: 6
> Count = 6
> fooprint:Count: 127
> Count = 127
> fooprint:Count: 127
> Count = 127
>
> Any recommendations? I am not seeing any problem with the code so I have no
> idea what is going on.
> (This has led to a mind-bend debug exercise in live code due to pointer
> arithmetic not being as intended...pfew!)

Are you using GCC44~GCC46? If so, you might be seeing a mismatch in
parameter calling conventions. Can you try adding EFIAPI to fooprint?

The VA_* macros assume EFIAPI...

-Jordan

>
> TIA!
>
> -------- Vprint.c --------
>
> #include <Uefi.h>
> #include <Library/UefiLib.h>
> #include <Library/UefiApplicationEntryPoint.h>
> #include <Library/PrintLib.h>
>
> CHAR16 Buffer[128];
> CHAR16 String1[] = L"a string";
> CHAR16 String2[] = L"a longer string";
> CHAR16 String3[] = L"an even longer string";
>
> UINTN
> fooprint (
> IN CONST CHAR16 *Format,
> ...
> )
> {
> UINTN Count;
> VA_LIST Marker;
>
> VA_START (Marker, Format);
> Count = UnicodeVSPrint (Buffer, sizeof Buffer, Format, Marker);
> VA_END (Marker);
> Print (L"fooprint:Count: %d\n", Count);
> return Count;
> }
>
> EFI_STATUS
> EFIAPI
> UefiMain (
> IN EFI_HANDLE ImageHandle,
> IN EFI_SYSTEM_TABLE *SystemTable
> )
> {
> UINTN Count;
>
> Count = fooprint (L"%s", String1);
> Print (L"Count = %d\n", Count);
> Count = fooprint (L"%s", String2);
> Print (L"Count = %d\n", Count);
> Count = fooprint (L"%s", String3);
> Print (L"Count = %d\n", Count);
>
> return EFI_SUCCESS;
> }
>
> -------- Vprint.inf --------
>
> [Defines]
> INF_VERSION = 0x00010005
> BASE_NAME = Vprint
> FILE_GUID = f9bfca86-a0b5-41f8-ba8a-1f2e9428ec06
> MODULE_TYPE = UEFI_APPLICATION
> VERSION_STRING = 1.0
> ENTRY_POINT = UefiMain
>
>
> [Sources]
> Vprint.c
>
> [Packages]
> MdePkg/MdePkg.dec
> MdeModulePkg/MdeModulePkg.dec
>
> [LibraryClasses]
> UefiApplicationEntryPoint
> UefiLib
> PrintLib
>
>
> ------------------------------------------------------------------------------
> Everyone hates slow websites. So do we.
> Make your web apps faster with AppDynamics
> Download AppDynamics Lite for free today:
> http://p.sf.net/sfu/appdyn_sfd2d_oct
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/edk2-devel
>

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_sfd2d_oct
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/edk2-devel