From 044a40c89857aca2d31dce0a09787bc07e02f842 Mon Sep 17 00:00:00 2001 From: Mikhail Krichanov Date: Mon, 25 Mar 2024 14:37:06 +0300 Subject: [PATCH] Ring3: Fixed bug in IA32 SetPosition() and Open(). --- MdeModulePkg/Core/Dxe/DxeRing3/DxeRing3.c | 33 +++++++++++++++++++ .../Core/Dxe/SysCall/SupportedProtocols.c | 32 ++++++++++++++++++ 2 files changed, 65 insertions(+) diff --git a/MdeModulePkg/Core/Dxe/DxeRing3/DxeRing3.c b/MdeModulePkg/Core/Dxe/DxeRing3/DxeRing3.c index e0800f446f..da40513a94 100644 --- a/MdeModulePkg/Core/Dxe/DxeRing3/DxeRing3.c +++ b/MdeModulePkg/Core/Dxe/DxeRing3/DxeRing3.c @@ -143,6 +143,29 @@ EFI_STATUS IN UINTN Argument5 ); +typedef +EFI_STATUS +(EFIAPI *FUNCTION_6)( + IN UINTN Argument1, + IN UINTN Argument2, + IN UINTN Argument3, + IN UINTN Argument4, + IN UINTN Argument5, + IN UINTN Argument6 + ); + +typedef +EFI_STATUS +(EFIAPI *FUNCTION_7)( + IN UINTN Argument1, + IN UINTN Argument2, + IN UINTN Argument3, + IN UINTN Argument4, + IN UINTN Argument5, + IN UINTN Argument6, + IN UINTN Argument7 + ); + VOID EFIAPI Ring3Call ( @@ -156,6 +179,8 @@ Ring3Call ( FUNCTION_3 Function3; FUNCTION_4 Function4; FUNCTION_5 Function5; + FUNCTION_6 Function6; + FUNCTION_7 Function7; switch (Data->NumberOfArguments) { case 0: @@ -182,6 +207,14 @@ Ring3Call ( Function5 = (FUNCTION_5)Data->EntryPoint; Status = Function5 (Data->Arguments[0], Data->Arguments[1], Data->Arguments[2], Data->Arguments[3], Data->Arguments[4]); break; + case 6: + Function6 = (FUNCTION_6)Data->EntryPoint; + Status = Function6 (Data->Arguments[0], Data->Arguments[1], Data->Arguments[2], Data->Arguments[3], Data->Arguments[4], Data->Arguments[5]); + break; + case 7: + Function7 = (FUNCTION_7)Data->EntryPoint; + Status = Function7 (Data->Arguments[0], Data->Arguments[1], Data->Arguments[2], Data->Arguments[3], Data->Arguments[4], Data->Arguments[5], Data->Arguments[6]); + break; default: Status = EFI_UNSUPPORTED; break; diff --git a/MdeModulePkg/Core/Dxe/SysCall/SupportedProtocols.c b/MdeModulePkg/Core/Dxe/SysCall/SupportedProtocols.c index ac908a3005..a7acb4ceb8 100644 --- a/MdeModulePkg/Core/Dxe/SysCall/SupportedProtocols.c +++ b/MdeModulePkg/Core/Dxe/SysCall/SupportedProtocols.c @@ -322,12 +322,27 @@ CoreFileSetPosition ( File = (RING3_EFI_FILE_PROTOCOL *)This; +#if defined (MDE_CPU_X64) return GoToRing3 ( 2, (VOID *)mRing3FileProtocol.SetPosition, File->Ring3File, Position ); +#endif + +#if defined (MDE_CPU_IA32) + // + // UINT64 Position is passed as 2 double words on stack. + // + return GoToRing3 ( + 3, + (VOID *)mRing3FileProtocol.SetPosition, + File->Ring3File, + Position + ); +#endif + } STATIC @@ -582,6 +597,7 @@ CoreFileOpen ( return Status; } +#if defined (MDE_CPU_X64) Status = GoToRing3 ( 5, (VOID *)mRing3FileProtocol.Open, @@ -591,6 +607,22 @@ CoreFileOpen ( OpenMode, Attributes ); +#endif + +#if defined (MDE_CPU_IA32) + // + // UINT64 OpenMode and Attributes are each passed as 2 double words on stack. + // + Status = GoToRing3 ( + 7, + (VOID *)mRing3FileProtocol.Open, + File->Ring3File, + Ring3NewHandle, + Ring3FileName, + OpenMode, + Attributes + ); +#endif if (EFI_ERROR (Status)) { *NewHandle = NULL; CoreFreePages (Ring3Pages, PagesNumber);