On 01/15/13 14:12, Космынин Олег Олегович wrote:
> Seems like gethostbyname error is the same as in GetHostByDns...
> 
> I spend about one week trying to understand what causes the bug with
> ASSERT message in GetHostByDns and come to a conclusion that pointer
> 'This' (EFI_UDP4_PROTOCOL pointer) coming to
> Udp4Main.c::Udp4Configure() (and other functions) and used in
> UDP4_INSTANCE_DATA_FROM_THIS() macro from Socket.c functions is
> corrupted causing macro to ASSERT.
> 
> I made simple experiment and compiled same sources on windows machine
> and produces GetHostByDns.efi file worked excellent.

I figured I'd look into where the EFIAPI calling convention could get
"lost". Consider the following (by no means the only) path:

- Udp4Configure() [MdeModulePkg/Universal/Network/Udp4Dxe/Udp4Main.c] is
declared with EFIAPI,
- its address is stored in mUdp4Protocol.Configure (same file) as part
of the struct's initialization,
- the type of that field is EFI_UDP4_CONFIGURE
[MdePkg/Include/Protocol/Udp4.h], which again carries EFIAPI:

typedef
EFI_STATUS
(EFIAPI *EFI_UDP4_CONFIGURE)(
  IN EFI_UDP4_PROTOCOL      *This,
  IN EFI_UDP4_CONFIG_DATA   *UdpConfigData OPTIONAL
  );


However,
- in function EslUdp4PortAllocate() [StdLib/EfiSocketLib/Udp4.c], which
seems to be part of the "[i]nterface between the socket layer and the
network specific code that supports SOCK_DGRAM sockets over UDPv4", we
can see the following assignment:

  pPort->pfnConfigure =
(PFN_NET_CONFIGURE)pPort->pProtocol.UDPv4->Configure;

(the explicit cast itself matches the type of the LHS),

- The type definition is in "StdLib/EfiSocketLib/Socket.h":

typedef
EFI_STATUS
(* PFN_NET_CONFIGURE) (
  IN VOID * pProtocol,
  IN VOID * pConfigData
  );

That is, the assignment casts away EFIAPI, which will cause a problem
when Udp4Configure() is called through pPort->pfnConfigure.


Kosmynin, can you please see if the attached patch fixes (or at least
moves around) the crash for you?

Thanks,
Laszlo
From fdfa5ff4c43bb3470d9a194c0e08444aec242d77 Mon Sep 17 00:00:00 2001
From: Laszlo Ersek <ler...@redhat.com>
Date: Tue, 15 Jan 2013 21:48:54 +0100
Subject: [PATCH] StdLib/EfiSocketLib: add EFIAPI calling conv to PFN_NET_* 
funcptr types

Contributed-under: TianoCore Contribution Agreement 1.0

Signed-off-by: Laszlo Ersek <ler...@redhat.com>
---
 StdLib/EfiSocketLib/Socket.h |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/StdLib/EfiSocketLib/Socket.h b/StdLib/EfiSocketLib/Socket.h
index 43a7084..0064411 100644
--- a/StdLib/EfiSocketLib/Socket.h
+++ b/StdLib/EfiSocketLib/Socket.h
@@ -362,7 +362,7 @@ typedef struct {
 **/
 typedef
 EFI_STATUS
-(* PFN_NET_CONFIGURE) (
+(EFIAPI *PFN_NET_CONFIGURE) (
   IN VOID * pProtocol,
   IN VOID * pConfigData
   );
@@ -378,7 +378,7 @@ EFI_STATUS
 **/
 typedef
 EFI_STATUS
-(* PFN_NET_IO_START) (
+(EFIAPI *PFN_NET_IO_START) (
   IN VOID * pProtocol,
   IN VOID * pToken
   );
@@ -394,7 +394,7 @@ EFI_STATUS
 **/
 typedef
 EFI_STATUS
-(* PFN_NET_POLL) (
+(EFIAPI *PFN_NET_POLL) (
   IN VOID * pProtocol
   );
 
-- 
1.7.1

------------------------------------------------------------------------------
Master SQL Server Development, Administration, T-SQL, SSAS, SSIS, SSRS
and more. Get SQL Server skills now (including 2012) with LearnDevNow -
200+ hours of step-by-step video tutorials by Microsoft MVPs and experts.
SALE $99.99 this month only - learn more at:
http://p.sf.net/sfu/learnmore_122512
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/edk2-devel

Reply via email to