Skip to content

Commit

Permalink
Ring3: Fixed Ring3LocateHandleBuffer().
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikhail Krichanov committed Mar 11, 2024
1 parent 239b883 commit 2098b1d
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 45 deletions.
36 changes: 0 additions & 36 deletions MdeModulePkg/Core/Dxe/DxeRing3/Ring3.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,42 +131,6 @@ Ring3GetMemoryMap (
OUT UINT32 *DescriptorVersion
);

/**
Allocate pool of a particular type.
@param PoolType Type of pool to allocate
@param Size The amount of pool to allocate
@param Buffer The address to return a pointer to the allocated
pool
@retval EFI_INVALID_PARAMETER PoolType not valid or Buffer is NULL
@retval EFI_OUT_OF_RESOURCES Size exceeds max pool size or allocation failed.
@retval EFI_SUCCESS Pool successfully allocated.
**/
EFI_STATUS
EFIAPI
Ring3AllocatePool (
IN EFI_MEMORY_TYPE PoolType,
IN UINTN Size,
OUT VOID **Buffer
);

/**
Frees pool.
@param Buffer The allocated pool entry to free
@retval EFI_INVALID_PARAMETER Buffer is not a valid value.
@retval EFI_SUCCESS Pool successfully freed.
**/
EFI_STATUS
EFIAPI
Ring3FreePool (
IN VOID *Buffer
);

/**
Creates an event.
Expand Down
45 changes: 37 additions & 8 deletions MdeModulePkg/Core/Dxe/DxeRing3/Ring3UefiBootServices.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
#include <Library/MemoryPoolLib.h>

#include "Ring3.h"

Expand Down Expand Up @@ -579,14 +580,42 @@ Ring3LocateHandleBuffer (
OUT EFI_HANDLE **Buffer
)
{
return SysCall (
SysCallLocateHandleBuffer,
SearchType,
Protocol,
SearchKey,
NumberHandles,
Buffer
);
EFI_STATUS Status;
EFI_STATUS StatusBS;
VOID *Pool;
UINTN PoolSize;

StatusBS = SysCall (
SysCallLocateHandleBuffer,
SearchType,
Protocol,
SearchKey,
NumberHandles,
Buffer
);

if ((NumberHandles != NULL) && (Buffer != NULL) && (*Buffer != NULL)) {
PoolSize = *NumberHandles * sizeof (EFI_HANDLE *);

Status = CoreAllocatePool (EfiRing3MemoryType, PoolSize, &Pool);
if (EFI_ERROR (Status)) {
return Status;
}

CopyMem (Pool, *Buffer, PoolSize);

Status = Ring3FreePages (
(EFI_PHYSICAL_ADDRESS)*Buffer,
EFI_SIZE_TO_PAGES (PoolSize)
);
if (EFI_ERROR (Status)) {
return Status;
}

*Buffer = Pool;
}

return StatusBS;
}

EFI_STATUS
Expand Down
2 changes: 1 addition & 1 deletion MdeModulePkg/Core/Dxe/SysCall/BootServices.c
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ CallBootService (
*(UINTN *)UserRsp->Arguments[4] = Argument4;
}

if ((UINTN *)UserRsp->Arguments[5] != NULL) {
if ((EFI_HANDLE **)UserRsp->Arguments[5] != NULL) {
gCpu->GetMemoryAttributes (gCpu, (EFI_PHYSICAL_ADDRESS)UserRsp->Arguments[5], &Attributes);
ASSERT ((Attributes & EFI_MEMORY_USER) != 0);
gCpu->GetMemoryAttributes (gCpu, (EFI_PHYSICAL_ADDRESS)(UserRsp->Arguments[5] + sizeof (EFI_HANDLE *) - 1), &Attributes);
Expand Down

0 comments on commit 2098b1d

Please sign in to comment.