Skip to content

Commit

Permalink
Ring3: Added helper function AllocateRing3Pages() and
Browse files Browse the repository at this point in the history
draft of Ring3LocateProtocol().
  • Loading branch information
Mikhail Krichanov committed Jan 26, 2024
1 parent c678a59 commit 7730f36
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 42 deletions.
9 changes: 8 additions & 1 deletion MdeModulePkg/Core/Dxe/DxeMain.h
Original file line number Diff line number Diff line change
Expand Up @@ -1167,6 +1167,13 @@ CoreAllocatePages (
IN OUT EFI_PHYSICAL_ADDRESS *Memory
);

EFI_STATUS
EFIAPI
AllocateRing3Pages (
IN UINTN NumberOfPages,
IN OUT VOID **Memory
);

/**
Frees previous allocated pages.
Expand Down Expand Up @@ -1353,7 +1360,7 @@ CoreLoadImage (
@retval EFI_SUCCESS The image has been unloaded.
@retval EFI_UNSUPPORTED The image has been started, and does not support
unload.
@retval EFI_INVALID_PARAMPETER ImageHandle is not a valid image handle.
@retval EFI_INVALID_PARAMETER ImageHandle is not a valid image handle.
**/
EFI_STATUS
Expand Down
3 changes: 2 additions & 1 deletion MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ EFI_BOOT_SERVICES mBootServices = {
(EFI_CALCULATE_CRC32)CoreEfiNotAvailableYetArg3, // CalculateCrc32
(EFI_COPY_MEM)CopyMem, // CopyMem
(EFI_SET_MEM)SetMem, // SetMem
(EFI_CREATE_EVENT_EX)CoreCreateEventEx // CreateEventEx
(EFI_CREATE_EVENT_EX)CoreCreateEventEx, // CreateEventEx
(EFI_ALLOCATE_RING3_PAGES)AllocateRing3Pages
};

EFI_DXE_SERVICES mDxeServices = {
Expand Down
23 changes: 22 additions & 1 deletion MdeModulePkg/Core/Dxe/Image/Image.c
Original file line number Diff line number Diff line change
Expand Up @@ -1565,6 +1565,27 @@ CoreLoadImage (
return Status;
}

EFI_STATUS
EFIAPI
AllocateRing3Pages (
IN UINTN NumberOfPages,
IN OUT VOID **Memory
)
{
if (Memory == NULL) {
return EFI_INVALID_PARAMETER;
}

*Memory = AllocatePages (NumberOfPages);
if (*Memory == NULL) {
return EFI_OUT_OF_RESOURCES;
}

SetUefiImageMemoryAttributes ((UINTN)*Memory, EFI_PAGES_TO_SIZE (NumberOfPages), EFI_MEMORY_USER);

return EFI_SUCCESS;
}

/**
Transfer control to a loaded image's entry point.
Expand Down Expand Up @@ -1972,7 +1993,7 @@ CoreExit (
@retval EFI_SUCCESS The image has been unloaded.
@retval EFI_UNSUPPORTED The image has been started, and does not support
unload.
@retval EFI_INVALID_PARAMPETER ImageHandle is not a valid image handle.
@retval EFI_INVALID_PARAMETER ImageHandle is not a valid image handle.
**/
EFI_STATUS
Expand Down
8 changes: 8 additions & 0 deletions MdePkg/Include/Uefi/UefiSpec.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,13 @@ EFI_STATUS
IN OUT EFI_PHYSICAL_ADDRESS *Memory
);

typedef
EFI_STATUS
(EFIAPI *EFI_ALLOCATE_RING3_PAGES)(
IN UINTN Pages,
IN OUT VOID **Memory
);

/**
Frees memory pages.
Expand Down Expand Up @@ -1960,6 +1967,7 @@ typedef struct {
EFI_COPY_MEM CopyMem;
EFI_SET_MEM SetMem;
EFI_CREATE_EVENT_EX CreateEventEx;
EFI_ALLOCATE_RING3_PAGES AllocateRing3Pages;
} EFI_BOOT_SERVICES;

///
Expand Down
Loading

0 comments on commit 7730f36

Please sign in to comment.