Skip to content

Commit

Permalink
SysCall: Added NumberOfCalls to USER_SPACE_DRIVER.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikhail Krichanov committed Jan 24, 2025
1 parent 72c747b commit 734748e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions MdeModulePkg/Core/Dxe/DxeMain.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ typedef struct {
VOID *UserSpaceDriver;
UINTN UserPageTable;
UINTN UserStackTop;
UINT8 NumberOfCalls;
LIST_ENTRY Link;
} USER_SPACE_DRIVER;

Expand Down
1 change: 1 addition & 0 deletions MdeModulePkg/Core/Dxe/Image/Image.c
Original file line number Diff line number Diff line change
Expand Up @@ -1743,6 +1743,7 @@ CoreStartImage (
UserDriver->UserSpaceDriver = (VOID *)Image->EntryPoint;
UserDriver->UserPageTable = Image->UserPageTable;
UserDriver->UserStackTop = Image->UserStackTop;
UserDriver->NumberOfCalls = 0;

InsertTailList (&gUserSpaceDriversHead, &UserDriver->Link);

Expand Down
1 change: 1 addition & 0 deletions MdeModulePkg/Core/Dxe/SysCall/BootServices.c
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,7 @@ CallBootService (
NewDriver->UserSpaceDriver = UserArgList[Index + 1];
NewDriver->UserPageTable = UserDriver->UserPageTable;
NewDriver->UserStackTop = UserDriver->UserStackTop;
NewDriver->NumberOfCalls = 0;

InsertTailList (&gUserSpaceDriversHead, &NewDriver->Link);
}
Expand Down
12 changes: 12 additions & 0 deletions MdeModulePkg/Core/Dxe/SysCall/SupportedProtocols.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include "DxeMain.h"
#include "SupportedProtocols.h"

#define MAX_CALL 1

LIST_ENTRY gUserSpaceDriversHead = INITIALIZE_LIST_HEAD_VARIABLE (gUserSpaceDriversHead);

EFI_STATUS
Expand All @@ -33,6 +35,10 @@ GoToRing3 (
EFI_PHYSICAL_ADDRESS Ring3Pages;
UINT32 PagesNumber;

if (UserDriver->NumberOfCalls > MAX_CALL) {
return EFI_OUT_OF_RESOURCES;
}

PagesNumber = (UINT32)EFI_SIZE_TO_PAGES (sizeof (RING3_CALL_DATA) + Number * sizeof (UINTN));

Status = CoreAllocatePages (
Expand Down Expand Up @@ -61,11 +67,15 @@ GoToRing3 (
// TODO: Allocate new stacks (only for EFI_FILE_PROTOCOL instances?),
// because UserDriver can be interrupted and interrupt handler may call the same UserDriver again.
//
++UserDriver->NumberOfCalls;

Status = CallRing3 (
Input,
UserDriver->UserStackTop
);

--UserDriver->NumberOfCalls;

CoreFreePages (Ring3Pages, PagesNumber);

return Status;
Expand Down Expand Up @@ -754,6 +764,7 @@ CoreFileOpen (
NewDriver->CoreWrapper = NewFile;
NewDriver->UserPageTable = UserDriver->UserPageTable;
NewDriver->UserStackTop = UserDriver->UserStackTop;
NewDriver->NumberOfCalls = 0;

AllowSupervisorAccessToUserMemory ();
NewDriver->UserSpaceDriver = *Ring3NewHandle;
Expand Down Expand Up @@ -855,6 +866,7 @@ CoreSimpleFileSystemOpenVolume (
NewDriver->CoreWrapper = File;
NewDriver->UserPageTable = UserDriver->UserPageTable;
NewDriver->UserStackTop = UserDriver->UserStackTop;
NewDriver->NumberOfCalls = 0;

AllowSupervisorAccessToUserMemory ();
NewDriver->UserSpaceDriver = *Ring3Root;
Expand Down

0 comments on commit 734748e

Please sign in to comment.