-
Notifications
You must be signed in to change notification settings - Fork 8
Create a UEFI variable at end of DXE indicating UEFI debugger is active #150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ | |
| #include <Library/BaseMemoryLib.h> | ||
| #include <Library/DebugAgentLib.h> | ||
| #include <Library/UefiBootServicesTableLib.h> | ||
| #include <Library/UefiRuntimeServicesTableLib.h> | ||
| #include <Library/UefiLib.h> | ||
| #include <Library/PeCoffGetEntryPointLib.h> | ||
| #include <Library/CpuExceptionHandlerLib.h> | ||
|
|
@@ -62,6 +63,7 @@ STATIC EFI_EVENT mTimerEvent; | |
| STATIC EFI_EVENT mCpuArchEvent; | ||
| STATIC EFI_EVENT mLoadedImageEvent; | ||
| STATIC EFI_EVENT mExitBootServicesEvent; | ||
| STATIC EFI_EVENT mEndOfDxeEvent; | ||
| STATIC BOOLEAN mDebuggerInitialized; | ||
| STATIC BOOLEAN mDisablePolling; | ||
| STATIC CHAR8 mDbgBreakOnModuleLoadString[64] = { 0 }; | ||
|
|
@@ -153,6 +155,40 @@ OnExitBootServices ( | |
| return; | ||
| } | ||
|
|
||
| /** | ||
| This routine handles the END_OF_DXE notification, and terminates | ||
| the debugger | ||
|
|
||
| @param Event Not used. | ||
| @param Context Not used. | ||
|
|
||
| **/ | ||
| VOID | ||
| EFIAPI | ||
| OnEndOfDxe ( | ||
| EFI_EVENT Event, | ||
| VOID *Context | ||
| ) | ||
| { | ||
| EFI_STATUS Status; | ||
| UINT8 Value; | ||
|
|
||
| Value = 1; | ||
| Status = gRT->SetVariable ( | ||
| L"UefiDebuggerActive", | ||
| &gDebuggerVariableGuid, | ||
| EFI_VARIABLE_BOOTSERVICE_ACCESS, | ||
| sizeof (Value), | ||
| &Value | ||
| ); | ||
|
|
||
| if (EFI_ERROR (Status)) { | ||
| DEBUG ((DEBUG_ERROR, "%a: Failed to set UefiDebuggerActive variable. %r\n", __FUNCTION__, Status)); | ||
| } | ||
|
|
||
| return; | ||
| } | ||
|
|
||
| /** | ||
| Cpu Arch Protocol notification. | ||
|
|
||
|
|
@@ -660,6 +696,23 @@ DxeDebugSetupCallbacks ( | |
| DEBUG ((DEBUG_ERROR, "%a: failed to create Exit Boot Services callback\n", __FUNCTION__)); | ||
| } | ||
|
|
||
| // | ||
| // Register for READY_TO_BOOT notification, to set a variable for OS loaders to check for debugger enablement. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You say RTB, but do EOD. I would have thought RTB would be the more natural place, right before we load a bootloader?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's somewhat arbitrary, and I have no strong preference. I can change to RTB. |
||
| // | ||
|
|
||
| Status = gBS->CreateEventEx ( | ||
| EVT_NOTIFY_SIGNAL, | ||
| TPL_CALLBACK, | ||
| OnEndOfDxe, | ||
| NULL, | ||
| &gEfiEndOfDxeEventGroupGuid, | ||
| &mEndOfDxeEvent | ||
| ); | ||
|
|
||
| if (EFI_ERROR (Status)) { | ||
| DEBUG ((DEBUG_ERROR, "%a: failed to create End of Dxe callback\n", __FUNCTION__)); | ||
| } | ||
|
|
||
| return EFI_SUCCESS; | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is might be a nit for the usecase:
Volatile variable that is Boot services access only, runs at end of dxe, before 3rd party code runs, and is un protected. Is it a problem that 3rd party code could change this value, and the boot loader wouldn't be aware of it anymore?
Is there a more standard way that presence of a debugger could be detected?