Skip to content

Commit

Permalink
firmware remove agressive smbios caching
Browse files Browse the repository at this point in the history
  • Loading branch information
jxy-s committed Jan 10, 2025
1 parent c754900 commit 2dd6f63
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions phlib/firmware.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,27 +129,29 @@ NTSTATUS PhEnumSMBIOS(
_In_opt_ PVOID Context
)
{
static PH_INITONCE initOnce = PH_INITONCE_INIT;
static NTSTATUS status;
static ULONG length;
static PSYSTEM_FIRMWARE_TABLE_INFORMATION info;
static volatile ULONG cachedLength = sizeof(PSYSTEM_FIRMWARE_TABLE_INFORMATION) + 64;
NTSTATUS status;
ULONG length;
PSYSTEM_FIRMWARE_TABLE_INFORMATION info;

if (PhBeginInitOnce(&initOnce))
{
SYSTEM_FIRMWARE_TABLE_INFORMATION initInfo;
length = (ULONG)ReadAcquire((volatile LONG*)&cachedLength);

initInfo.ProviderSignature = 'RSMB';
initInfo.TableID = 0;
initInfo.Action = SystemFirmwareTableGet;
initInfo.TableBufferLength = 0;
info = PhAllocateZero(length);

NtQuerySystemInformation(
SystemFirmwareTableInformation,
&initInfo,
sizeof(SYSTEM_FIRMWARE_TABLE_INFORMATION),
&length
);
info->ProviderSignature = 'RSMB';
info->TableID = 0;
info->Action = SystemFirmwareTableGet;
info->TableBufferLength = length - sizeof(PSYSTEM_FIRMWARE_TABLE_INFORMATION);

status = NtQuerySystemInformation(
SystemFirmwareTableInformation,
info,
length,
&length
);
if (status == STATUS_BUFFER_TOO_SMALL)
{
PhFree(info);
info = PhAllocateZero(length);

info->ProviderSignature = 'RSMB';
Expand All @@ -163,8 +165,8 @@ NTSTATUS PhEnumSMBIOS(
length,
&length
);

PhEndInitOnce(&initOnce);
if (NT_SUCCESS(status))
WriteRelease((volatile LONG*)&cachedLength, (LONG)length);
}

if (NT_SUCCESS(status))
Expand Down

0 comments on commit 2dd6f63

Please sign in to comment.