Skip to content

Commit

Permalink
OcMainLib: Unload drivers most recent first
Browse files Browse the repository at this point in the history
  • Loading branch information
mikebeaton committed Dec 22, 2024
1 parent f30d412 commit 411de51
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 11 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ OpenCore Changelog
- Added support for booting from static IPv4 address to OpenCore-specific HttpBootDxe
- Added static IPv4 configuration options to OpenNetworkBoot
- Removed `--` prefix from OpenNetworkBoot arguments (modify driver arguments if using this driver)
- Updated `Unload` option to unload drivers in reverse of the order in which they were loaded

#### v1.0.3
- Fixed support for `AMD_CPU_EXT_FAMILY_1AH`, thx @Shaneee
Expand Down
2 changes: 1 addition & 1 deletion Docs/Configuration.md5
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4728e88d95bbba6d7add29638587fb98
c17c74a85252ceeb0d28b626e96e22bc
Binary file modified Docs/Configuration.pdf
Binary file not shown.
8 changes: 6 additions & 2 deletions Docs/Configuration.tex
Original file line number Diff line number Diff line change
Expand Up @@ -7781,13 +7781,17 @@ \subsection{Properties}\label{uefiprops}
unloaded even though they have active dependencies). However standard UEFI
network stack drivers should unload cleanly.

\emph{Note 1}: See \texttt{SysReport/Drivers/DriverImageNames.txt} for the
\emph{Note 1}: Drivers specified in this option will be unloaded in the reverse
of the order in which they were loaded, regardless of the order in which they
are specified here.

\emph{Note 2}: See \texttt{SysReport/Drivers/DriverImageNames.txt} for the
list of drivers which this option can attempt to unload.
The relevant name is the driver component name. Drivers are only listed if they
implement \texttt{DriverBindingProtocol} and \texttt{LoadedImageProtocol},
and have an available component name.

\emph{Note 2}: The NVRAM \texttt{Lang} and \texttt{PlatformLang} variables
\emph{Note 3}: The NVRAM \texttt{Lang} and \texttt{PlatformLang} variables
are ignored when determining the driver component names recognised by this
option, and listed in the \texttt{SysReport} file. This is in order to make
unloading images stable across changes in these variables.
Expand Down
Binary file modified Docs/Differences/Differences.pdf
Binary file not shown.
11 changes: 8 additions & 3 deletions Docs/Differences/Differences.tex
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
\documentclass[]{article}
%DIF LATEXDIFF DIFFERENCE FILE
%DIF DEL PreviousConfiguration.tex Sun Dec 22 14:07:33 2024
%DIF ADD ../Configuration.tex Sun Dec 22 14:07:33 2024
%DIF ADD ../Configuration.tex Sun Dec 22 14:14:49 2024

\usepackage{lmodern}
\usepackage{amssymb,amsmath}
Expand Down Expand Up @@ -7913,13 +7913,18 @@ \subsection{Properties}\label{uefiprops}
unloaded even though they have active dependencies). However standard UEFI
network stack drivers should unload cleanly.

\emph{Note 1}: See \texttt{SysReport/Drivers/DriverImageNames.txt} for the
\emph{Note 1}: \DIFaddbegin \DIFadd{Drivers specified in this option will be unloaded in the reverse
of the order in which they were loaded, regardless of the order in which they
are specified here.
}

\emph{\DIFadd{Note 2}}\DIFadd{: }\DIFaddend See \texttt{SysReport/Drivers/DriverImageNames.txt} for the
list of drivers which this option can attempt to unload.
The relevant name is the driver component name. Drivers are only listed if they
implement \texttt{DriverBindingProtocol} and \texttt{LoadedImageProtocol},
and have an available component name.

\emph{Note 2}: The NVRAM \texttt{Lang} and \texttt{PlatformLang} variables
\emph{Note \DIFdelbegin \DIFdel{2}\DIFdelend \DIFaddbegin \DIFadd{3}\DIFaddend }: The NVRAM \texttt{Lang} and \texttt{PlatformLang} variables
are ignored when determining the driver component names recognised by this
option, and listed in the \texttt{SysReport} file. This is in order to make
unloading images stable across changes in these variables.
Expand Down
Binary file modified Docs/Errata/Errata.pdf
Binary file not shown.
16 changes: 11 additions & 5 deletions Library/OcMainLib/OpenCoreUefiUnloadDrivers.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@ UnloadImageByName (
VOID
ProcessAllDrivers (
IN VOID *Context,
PROCESS_IMAGE ProcessImage
PROCESS_IMAGE ProcessImage,
BOOLEAN Ascending
)
{
EFI_STATUS Status;
Expand All @@ -234,14 +235,19 @@ ProcessAllDrivers (
return;
}

for (Index = 0; Index < HandleCount; Index++) {
for (
Ascending ? (Index = 0) : (Index = HandleCount - 1);
Index < HandleCount; ///< UINTN: (HandleCount >= HandleCount) && ((0 - 1) >= HandleCount)
Ascending ? Index++ : Index--
)
{
Status = gBS->HandleProtocol (
HandleBuffer[Index],
&gEfiLoadedImageProtocolGuid,
(VOID **)&LoadedImage
);
if (!EFI_ERROR (Status)) {
Name = GetStringNameFromHandle (HandleBuffer[Index], NULL); ///< Do not free this one.
Name = GetStringNameFromHandle (HandleBuffer[Index], NULL); ///< Do not free Name.
if (Name != NULL) {
ProcessImage (Context, Name, HandleBuffer[Index]);
}
Expand Down Expand Up @@ -303,7 +309,7 @@ OcUnloadDrivers (

UnloadContext.UnloadNameCount = Config->Uefi.Unload.Count;

ProcessAllDrivers (&UnloadContext, UnloadImageByName);
ProcessAllDrivers (&UnloadContext, UnloadImageByName, FALSE);

for (Index = 0; Index < Config->Uefi.Unload.Count; ++Index) {
if (!UnloadContext.UnloadInfo[Index].Unloaded) {
Expand Down Expand Up @@ -335,7 +341,7 @@ OcDriverInfoDump (
return EFI_OUT_OF_RESOURCES;
}

ProcessAllDrivers (&Context, ReportImageName);
ProcessAllDrivers (&Context, ReportImageName, TRUE);

//
// Save dumped driver info to file.
Expand Down

0 comments on commit 411de51

Please sign in to comment.