ReactOS 0.4.15-dev-7659-ga55345b
util.c File Reference
#include "bl.h"
Include dependency graph for util.c:

Go to the source code of this file.

Functions

NTSTATUS BlUtlGetAcpiTable (_Out_ PVOID *TableAddress, _In_ ULONG Signature)
 
VOID BlUtlUpdateProgress (_In_ ULONG Percentage, _Out_opt_ PBOOLEAN Completed)
 
NTSTATUS BlUtlInitialize (VOID)
 
VOID BmUpdateProgressInfo (_In_ PVOID Unknown, _In_ PWCHAR ProgressInfo)
 
VOID BmUpdateProgress (_In_ PVOID Unknown, _In_ ULONG Percent, _Out_ PBOOLEAN Completed)
 
NTSTATUS BlUtlRegisterProgressRoutine (VOID)
 
PVOID BlTblFindEntry (_In_ PVOID *Table, _In_ ULONG Count, _Out_ PULONG EntryIndex, _In_ PBL_TBL_LOOKUP_ROUTINE Callback, _In_ PVOID Argument1, _In_ PVOID Argument2, _In_ PVOID Argument3, _In_ PVOID Argument4)
 
NTSTATUS BlTblSetEntry (_Inout_ PVOID **Table, _Inout_ PULONG Count, _In_ PVOID Entry, _Out_ PULONG EntryIndex, _In_ PBL_TBL_SET_ROUTINE Callback)
 
NTSTATUS BlTblMap (_In_ PVOID *Table, _In_ ULONG Count, _In_ PBL_TBL_MAP_ROUTINE MapCallback)
 
ULONG DefaultHashFunction (_In_ PBL_HASH_ENTRY Entry, _In_ ULONG TableSize)
 
BOOLEAN HtpCompareKeys (_In_ PBL_HASH_ENTRY Entry1, _In_ PBL_HASH_ENTRY Entry2)
 
NTSTATUS TblDoNotPurgeEntry (_In_ PVOID Entry)
 
NTSTATUS BlHtCreate (_In_ ULONG Size, _In_ PBL_HASH_TABLE_HASH_FUNCTION HashFunction, _In_ PBL_HASH_TABLE_COMPARE_FUNCTION CompareFunction, _Out_ PULONG Id)
 
NTSTATUS BlHtLookup (_In_ ULONG TableId, _In_ PBL_HASH_ENTRY Entry, _Out_opt_ PBL_HASH_VALUE *Value)
 
NTSTATUS BlHtStore (_In_ ULONG TableId, _In_ PBL_HASH_ENTRY Entry, _In_ PVOID Data, _In_ ULONG DataSize)
 
NTSTATUS BlHtDelete (_In_ ULONG TableId, _In_ PBL_HASH_ENTRY Entry)
 
ULONG BlUtlCheckSum (_In_ ULONG PartialSum, _In_ PUCHAR Buffer, _In_ ULONG Length, _In_ ULONG Flags)
 
BOOLEAN BlArchIsCpuIdFunctionSupported (_In_ ULONG Function)
 
ULONGLONG BlArchGetPerformanceCounter (VOID)
 
VOID BlArchCpuId (_In_ ULONG Function, _In_ ULONG SubFunction, _Out_ PCPU_INFO Result)
 
CPU_VENDORS BlArchGetCpuVendor (VOID)
 

Variables

PRSDT UtlRsdt
 
PXSDT UtlXsdt
 
PVOID UtlMcContext
 
PVOID UtlMcDisplayMessageRoutine
 
PVOID UtlMcUpdateMessageRoutine
 
PVOID UtlProgressRoutine
 
PVOID UtlProgressContext
 
PVOID UtlProgressInfoRoutine
 
ULONG UtlProgressGranularity
 
ULONG UtlCurrentPercentComplete
 
ULONG UtlNextUpdatePercentage
 
BOOLEAN UtlProgressNeedsInfoUpdate
 
PVOID UtlProgressInfo
 
ULONG HtTableSize
 
PBL_HASH_TABLEHtTableArray
 
ULONG HtTableEntries
 

Function Documentation

◆ BlArchCpuId()

VOID BlArchCpuId ( _In_ ULONG  Function,
_In_ ULONG  SubFunction,
_Out_ PCPU_INFO  Result 
)

Definition at line 924 of file util.c.

929{
930#if defined(_M_IX86) || defined(_M_X64)
931 /* Use the intrinsic */
932 __cpuidex((INT*)Result->AsUINT32, Function, SubFunction);
933#endif
934}
_In_ CDROM_SCAN_FOR_SPECIAL_INFO _In_ PCDROM_SCAN_FOR_SPECIAL_HANDLER Function
Definition: cdrom.h:1156
__INTRIN_INLINE void __cpuidex(int CPUInfo[4], int InfoType, int ECXValue)
Definition: intrin_x86.h:1649
int32_t INT
Definition: typedefs.h:58
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:409

Referenced by BlArchGetCpuVendor(), BlArchGetPerformanceCounter(), MmArchInitialize(), OslMain(), and OslpMain().

◆ BlArchGetCpuVendor()

CPU_VENDORS BlArchGetCpuVendor ( VOID  )

Definition at line 937 of file util.c.

940{
941 CPU_INFO CpuInfo;
942 INT Temp;
943
944 /* Get the CPU Vendor */
945 BlArchCpuId(0, 0, &CpuInfo);
946#if defined(_M_IX86) || defined(_M_X64)
947 Temp = CpuInfo.Ecx;
948 CpuInfo.Ecx = CpuInfo.Edx;
949 CpuInfo.Edx = Temp;
950
951 /* Check against supported values */
952 if (!strncmp((PCHAR)&CpuInfo.Ebx, "GenuineIntel", 12))
953 {
954 return CPU_INTEL;
955 }
956 if (!strncmp((PCHAR)&CpuInfo.Ebx, "AuthenticAMD", 12))
957 {
958 return CPU_AMD;
959 }
960 if (!strncmp((PCHAR)&CpuInfo.Ebx, "CentaurHauls", 12))
961 {
962 return CPU_VIA;
963 }
964#ifdef _M_IX86
965 if (!strncmp((PCHAR)&CpuInfo.Ebx, "CyrixInstead", 12))
966 {
967 return CPU_CYRIX;
968 }
969 if (!strncmp((PCHAR)&CpuInfo.Ebx, "GenuineTMx86", 12))
970 {
971 return CPU_TRANSMETA;
972 }
973 if (!strncmp((PCHAR)&CpuInfo.Ebx, "RiseRiseRise", 12))
974 {
975 return CPU_RISE;
976 }
977#endif // _M_IX86
978#else // defined(_M_IX86) || defined(_M_X64)
979 EfiPrintf(L"BlArchGetCpuVendor not implemented for this platform.\r\n");
980#endif
981 /* Other */
982 return CPU_UNKNOWN;
983}
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
Definition: utclib.c:534
VOID EfiPrintf(_In_ PWCHAR Format,...)
Definition: firmware.c:126
VOID BlArchCpuId(_In_ ULONG Function, _In_ ULONG SubFunction, _Out_ PCPU_INFO Result)
Definition: util.c:924
@ CPU_VIA
Definition: ketypes.h:107
@ CPU_INTEL
Definition: ketypes.h:106
@ CPU_UNKNOWN
Definition: ketypes.h:104
@ CPU_AMD
Definition: ketypes.h:105
@ CPU_RISE
Definition: ketypes.h:94
@ CPU_CYRIX
Definition: ketypes.h:90
@ CPU_TRANSMETA
Definition: ketypes.h:91
#define L(x)
Definition: ntvdm.h:50
char * PCHAR
Definition: typedefs.h:51
ULONG Ebx
Definition: ketypes.h:367
ULONG Ecx
Definition: ketypes.h:368
ULONG Edx
Definition: ketypes.h:369

Referenced by OslpMain().

◆ BlArchGetPerformanceCounter()

ULONGLONG BlArchGetPerformanceCounter ( VOID  )

Definition at line 902 of file util.c.

905{
906#if defined(_M_IX86) || defined(_M_X64)
907 CPU_INFO CpuInfo;
908
909 /* Serialize with CPUID, if it exists */
910 if (Archx86IsCpuidSupported())
911 {
912 BlArchCpuId(0, 0, &CpuInfo);
913 }
914
915 /* Read the TSC */
916 return __rdtsc();
917#else
918 EfiPrintf(L"BlArchGetPerformanceCounter not implemented for this platform.\r\n");
919 return 0;
920#endif
921}
PPC_QUAL unsigned long long __rdtsc(void)
Definition: intrin_ppc.h:688

Referenced by MmArchInitialize(), and OslPrepareTarget().

◆ BlArchIsCpuIdFunctionSupported()

BOOLEAN BlArchIsCpuIdFunctionSupported ( _In_ ULONG  Function)

Definition at line 856 of file util.c.

859{
860#if defined(_M_IX86) || defined(_M_X64)
862 INT CpuInfo[4];
863
864 /* Check if the CPU supports this instruction */
865 Supported = Archx86IsCpuidSupported();
866 if (!Supported)
867 {
868 return FALSE;
869 }
870
871 /* Check if it's the extended function */
872 if (Function >= 0x80000000)
873 {
874 /* Check if extended functions are supported */
875 __cpuid(CpuInfo, 0x80000000);
876 if ((CpuInfo[0] & 0xFFFFFF00) != 0x80000000)
877 {
878 /* Nope */
879 return FALSE;
880 }
881 }
882 else
883 {
884 /* It's a regular function, get the maximum one supported */
885 __cpuid(CpuInfo, 0);
886 }
887
888 /* Check if our function is within bounds */
889 if (Function <= CpuInfo[0])
890 {
891 return TRUE;
892 }
893#else
894 EfiPrintf(L"BlArchIsCpuIdFunctionSupported not implemented for this platform.\r\n");
895#endif
896
897 /* Nope */
898 return FALSE;
899}
unsigned char BOOLEAN
@ Supported
Definition: classpnp.h:733
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
PPC_QUAL void __cpuid(int CPUInfo[], const int InfoType)
Definition: intrin_ppc.h:682

Referenced by MmArchInitialize(), and OslMain().

◆ BlHtCreate()

NTSTATUS BlHtCreate ( _In_ ULONG  Size,
_In_ PBL_HASH_TABLE_HASH_FUNCTION  HashFunction,
_In_ PBL_HASH_TABLE_COMPARE_FUNCTION  CompareFunction,
_Out_ PULONG  Id 
)

Definition at line 504 of file util.c.

510{
513 ULONG i;
514
515 /* Assume failure */
516 HashTable = NULL;
517
518 /* Can't create a table with no ID */
519 if (!Id)
520 {
522 }
523
524 /* Check if we don't already have a hash table table */
525 if (!HtTableSize)
526 {
527 /* Allocate it and zero it out */
528 HtTableSize = 4;
530 if (!HtTableArray)
531 {
533 goto Quickie;
534 }
536 HtTableEntries = 0;
537 }
538
539 /* Allocate the hash table */
541 if (!HashTable)
542 {
544 goto Quickie;
545 }
546
547 /* Fill it out */
548 HashTable->HashFunction = HashFunction ? HashFunction : DefaultHashFunction;
549 HashTable->CompareFunction = CompareFunction ? CompareFunction : HtpCompareKeys;
550 HashTable->Size = Size ? Size : 13;
551
552 /* Allocate the hash links, one for each bucket */
553 HashTable->HashLinks = BlMmAllocateHeap(sizeof(LIST_ENTRY) * HashTable->Size);
554 if (!HashTable->HashLinks)
555 {
557 goto Quickie;
558 }
559
560 /* Initialize the hash links */
561 for (i = 0; i < HashTable->Size; i++)
562 {
563 InitializeListHead(&HashTable->HashLinks[i]);
564 }
565
566 /* Save us in the table of hash tables */
568 &Size,
569 HashTable,
570 Id,
572 if (NT_SUCCESS(Status))
573 {
574 /* One more -- we're done */
576 return Status;
577 }
578
579Quickie:
580 /* Check if we just allocated the table array now */
581 if (!(HtTableEntries) && (HtTableArray))
582 {
583 /* Free it */
586 HtTableSize = 0;
587 }
588
589 /* Check if we allocated a hash table*/
590 if (HashTable)
591 {
592 /* With links? */
593 if (HashTable->HashLinks)
594 {
595 /* Free them */
596 BlMmFreeHeap(HashTable->HashLinks);
597 }
598
599 /* Free the table*/
601 }
602
603 /* We're done */
604 return Status;
605}
DWORD Id
LONG NTSTATUS
Definition: precomp.h:26
PVOID BlMmAllocateHeap(_In_ SIZE_T Size)
Definition: heapalloc.c:569
NTSTATUS BlMmFreeHeap(_In_ PVOID Buffer)
Definition: heapalloc.c:663
ULONG HtTableEntries
Definition: util.c:439
ULONG DefaultHashFunction(_In_ PBL_HASH_ENTRY Entry, _In_ ULONG TableSize)
Definition: util.c:442
PBL_HASH_TABLE * HtTableArray
Definition: util.c:438
BOOLEAN HtpCompareKeys(_In_ PBL_HASH_ENTRY Entry1, _In_ PBL_HASH_ENTRY Entry2)
Definition: util.c:464
ULONG HtTableSize
Definition: util.c:437
NTSTATUS TblDoNotPurgeEntry(_In_ PVOID Entry)
Definition: util.c:495
NTSTATUS BlTblSetEntry(_Inout_ PVOID **Table, _Inout_ PULONG Count, _In_ PVOID Entry, _Out_ PULONG EntryIndex, _In_ PBL_TBL_SET_ROUTINE Callback)
Definition: util.c:321
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
Status
Definition: gdiplustypes.h:25
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
Definition: hash.c:67
Definition: typedefs.h:120
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533

Referenced by BcInitialize(), BlockIopInitialize(), and EfiVmOpenProtocol().

◆ BlHtDelete()

NTSTATUS BlHtDelete ( _In_ ULONG  TableId,
_In_ PBL_HASH_ENTRY  Entry 
)

Definition at line 722 of file util.c.

726{
730 PLIST_ENTRY HashLinkHead, HashLink;
731 PBL_HASH_NODE HashNode;
732
733 /* Check if the table ID is invalid, or we have no entry, or it's malformed */
734 if ((HtTableSize <= TableId) ||
735 !(Entry) ||
736 !(Entry->Size) ||
737 !(Entry->Value) ||
738 ((Entry->Flags & BL_HT_VALUE_IS_INLINE) && (Entry->Size != sizeof(ULONG))))
739 {
740 /* Fail */
742 }
743 else
744 {
745 /* Otherwise, get the hash table for this index */
746 HashTable = HtTableArray[TableId];
747
748 /* Get the hash bucket */
749 HashValue = HashTable->HashFunction(Entry, HashTable->Size);
750
751 /* Start iterating each entry in the bucket, assuming failure */
753 HashLinkHead = &HashTable->HashLinks[HashValue];
754 HashLink = HashLinkHead->Flink;
755 while (HashLink != HashLinkHead)
756 {
757 /* Get a node in this bucket, and compare the value */
758 HashNode = CONTAINING_RECORD(HashLink, BL_HASH_NODE, ListEntry);
759 if (HashTable->CompareFunction(&HashNode->Entry, Entry))
760 {
761 /* Remove it from the list and free it */
762 RemoveEntryList(&HashNode->ListEntry);
763 BlMmFreeHeap(HashNode);
764 return STATUS_SUCCESS;
765 }
766
767 /* Try the next node */
768 HashLink = HashLink->Flink;
769 }
770 }
771
772 /* Return back to the caller */
773 return Status;
774}
#define BL_HT_VALUE_IS_INLINE
Definition: bl.h:137
#define RemoveEntryList(Entry)
Definition: env_spec_w32.h:986
#define STATUS_SUCCESS
Definition: shellext.h:65
#define STATUS_NOT_FOUND
Definition: shellext.h:72
base of all file and directory entries
Definition: entries.h:83
LIST_ENTRY ListEntry
Definition: bl.h:1191
BL_HASH_ENTRY Entry
Definition: bl.h:1192
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
_In_ BOOLEAN _In_ ULONG _Out_ PULONG HashValue
Definition: rtlfuncs.h:2039

Referenced by BlockIoFirmwareOpen(), and EfiVmpFreeInterfaceEntry().

◆ BlHtLookup()

NTSTATUS BlHtLookup ( _In_ ULONG  TableId,
_In_ PBL_HASH_ENTRY  Entry,
_Out_opt_ PBL_HASH_VALUE Value 
)

Definition at line 608 of file util.c.

613{
617 PLIST_ENTRY HashLinkHead, HashLink;
618 PBL_HASH_NODE HashNode;
619
620 /* Check if the table ID is invalid, or we have no entry, or it's malformed */
621 if ((HtTableSize <= TableId) ||
622 !(Entry) ||
623 ((Entry->Flags & BL_HT_VALUE_IS_INLINE) && (Entry->Size != sizeof(ULONG))))
624 {
625 /* Fail */
627 }
628 else
629 {
630 /* Otherwise, get the hash table for this index */
631 HashTable = HtTableArray[TableId];
632
633 /* Get the hash bucket */
634 HashValue = HashTable->HashFunction(Entry, HashTable->Size);
635
636 /* Start iterating each entry in the bucket, assuming failure */
638 HashLinkHead = &HashTable->HashLinks[HashValue];
639 HashLink = HashLinkHead->Flink;
640 while (HashLink != HashLinkHead)
641 {
642 /* Get a node in this bucket, and compare the value */
643 HashNode = CONTAINING_RECORD(HashLink, BL_HASH_NODE, ListEntry);
644 if (HashTable->CompareFunction(&HashNode->Entry, Entry))
645 {
646 /* Does the caller want the value? */
647 if (Value)
648 {
649 /* Return it */
650 *Value = &HashNode->Value;
651 }
652
653 /* Return success and stop scanning */
655 break;
656 }
657
658 /* Try the next node */
659 HashLink = HashLink->Flink;
660 }
661 }
662
663 /* Return back to the caller */
664 return Status;
665}
BL_HASH_VALUE Value
Definition: bl.h:1193
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:413

◆ BlHtStore()

NTSTATUS BlHtStore ( _In_ ULONG  TableId,
_In_ PBL_HASH_ENTRY  Entry,
_In_ PVOID  Data,
_In_ ULONG  DataSize 
)

Definition at line 668 of file util.c.

674{
675 PBL_HASH_NODE HashNode;
677 PLIST_ENTRY HashLinkHead;
679
680 /* Check for invalid table ID, missing arguments, or malformed entry */
681 if ((HtTableSize <= TableId) ||
682 !(Entry) ||
683 !(Data) ||
684 !(Entry->Size) ||
685 !(Entry->Value) ||
686 !(DataSize) ||
687 ((Entry->Flags & BL_HT_VALUE_IS_INLINE) && (Entry->Size != sizeof(ULONG))))
688 {
689 /* Fail the call */
691 goto Quickie;
692 }
693
694 /* Get the hash table for this ID */
695 HashTable = HtTableArray[TableId];
696
697 /* Allocate a hash node */
698 HashNode = BlMmAllocateHeap(sizeof(*HashNode));
699 if (!HashNode)
700 {
702 goto Quickie;
703 }
704
705 /* Capture all the data*/
706 HashNode->Entry.Size = Entry->Size;
707 HashNode->Entry.Flags = Entry->Flags;
708 HashNode->Entry.Value = Entry->Value;
709 HashNode->Value.DataSize = DataSize;
710 HashNode->Value.Data = Data;
711
712 /* Insert it into the bucket list and return success */
713 HashLinkHead = &HashTable->HashLinks[HashTable->HashFunction(Entry, HashTable->Size)];
714 InsertTailList(HashLinkHead, &HashNode->ListEntry);
716
717Quickie:
718 return Status;
719}
#define InsertTailList(ListHead, Entry)
_In_ NDIS_STATUS _In_ ULONG _In_ USHORT _In_opt_ PVOID _In_ ULONG DataSize
Definition: ndis.h:4755
ULONG Flags
Definition: bl.h:1179
ULONG Size
Definition: bl.h:1178
PVOID Value
Definition: bl.h:1180
PVOID Data
Definition: bl.h:1186
ULONG DataSize
Definition: bl.h:1185

Referenced by BlockIoFirmwareOpen(), and EfiVmOpenProtocol().

◆ BlTblFindEntry()

PVOID BlTblFindEntry ( _In_ PVOID Table,
_In_ ULONG  Count,
_Out_ PULONG  EntryIndex,
_In_ PBL_TBL_LOOKUP_ROUTINE  Callback,
_In_ PVOID  Argument1,
_In_ PVOID  Argument2,
_In_ PVOID  Argument3,
_In_ PVOID  Argument4 
)

Definition at line 273 of file util.c.

283{
284 PVOID Entry = NULL;
285 ULONG Index;
287
288 /* Check for invalid parameters */
289 if (!(Table) || !(EntryIndex))
290 {
291 return Entry;
292 }
293
294 /* Loop each entry in the table */
295 for (Index = 0; Index < Count; Index++)
296 {
297 /* Check if this entry is filled out */
298 if (Table[Index])
299 {
300 /* Call the comparison function */
302 Argument1,
303 Argument2,
304 Argument3,
305 Argument4);
306 if (Result)
307 {
308 /* Entry found return it */
309 *EntryIndex = Index;
310 Entry = Table[Index];
311 break;
312 }
313 }
314 }
315
316 /* Return the entry that was (or wasn't) found */
317 return Entry;
318}
_In_ PVOID Argument2
Definition: classpnp.h:721
InternalIoctlParams Argument4
ASMGENDATA Table[]
Definition: genincdata.c:61
int Count
Definition: noreturn.cpp:7
_In_ WDFCOLLECTION _In_ ULONG Index
_In_ WDFINTERRUPT _In_ PFN_WDF_INTERRUPT_SYNCHRONIZE Callback
Definition: wdfinterrupt.h:458
_IRQL_requires_same_ _In_opt_ PVOID Argument1
Definition: cmtypes.h:696

Referenced by BlockIoOpen(), BlpDeviceOpen(), FileIoOpen(), and MmBapFindBlockInformation().

◆ BlTblMap()

NTSTATUS BlTblMap ( _In_ PVOID Table,
_In_ ULONG  Count,
_In_ PBL_TBL_MAP_ROUTINE  MapCallback 
)

Definition at line 399 of file util.c.

404{
405 NTSTATUS Status, LocalStatus;
406 PVOID Entry;
407 ULONG Index;
408
409 /* Bail out if there's no table */
410 if (!Table)
411 {
413 }
414
415 /* Assume success and loop each index */
417 for (Index = 0; Index < Count; Index++)
418 {
419 /* See if an entry exists at this index */
420 Entry = Table[Index];
421 if (Entry)
422 {
423 /* Call the map routine for this entry */
424 LocalStatus = MapCallback(Entry, Index);
425 if (!NT_SUCCESS(LocalStatus))
426 {
427 /* Propagate failure only */
428 Status = LocalStatus;
429 }
430 }
431 }
432
433 /* Return status to caller */
434 return Status;
435}

Referenced by BlockIoDeviceTableDestroy().

◆ BlTblSetEntry()

NTSTATUS BlTblSetEntry ( _Inout_ PVOID **  Table,
_Inout_ PULONG  Count,
_In_ PVOID  Entry,
_Out_ PULONG  EntryIndex,
_In_ PBL_TBL_SET_ROUTINE  Callback 
)

Definition at line 321 of file util.c.

328{
329 ULONG NewCount;
331 ULONG Index = 0;
332 PVOID* NewTable;
333
334 /* Make sure all the parameters were specified */
335 if (!(Table) || !(*Table) || !(Count) || !(Callback))
336 {
338 }
339
340 /* Read the current table */
341 NewTable = *Table;
342 NewCount = *Count;
343
344 /* Iterate over it */
345 while (Index < NewCount)
346 {
347 /* Look for a free index */
348 if (!NewTable[Index])
349 {
350 goto SetIndex;
351 }
352
353 /* No free index yet, keep going */
354 ++Index;
355 }
356
357 /* No free index was found, try to purge some entries */
358 Index = 0;
359 while (Index < NewCount)
360 {
361 /* Call each purge callback, trying to make space */
362 Status = Callback(NewTable[Index]);
363 if (NT_SUCCESS(Status))
364 {
365 /* We should have this slot available now */
366 goto SetIndex;
367 }
368
369 /* Keep trying to purge more */
370 ++Index;
371 }
372
373 /* Double the table */
374 NewTable = BlMmAllocateHeap(2 * sizeof(PVOID) * NewCount);
375 if (!NewTable)
376 {
377 return STATUS_NO_MEMORY;
378 }
379
380 /* Clear the new table, and copy the old entries */
381 RtlZeroMemory(&NewTable[NewCount], sizeof(PVOID) * NewCount);
382 RtlCopyMemory(NewTable, *Table, sizeof(PVOID) * NewCount);
383
384 /* Free the old table */
386
387 /* Return the new table and count */
388 *Count = 2 * NewCount;
389 *Table = NewTable;
390
391SetIndex:
392 /* Set the index and return */
393 NewTable[Index] = Entry;
394 *EntryIndex = Index;
395 return Status;
396}
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263

Referenced by BlHtCreate(), BlImgLoadBootApplication(), BlockIoFirmwareOpen(), BlpDeviceOpen(), BlpIoRegisterDestroyRoutine(), BlpMmCreateBlockAllocator(), EtfsMount(), and FileIoOpen().

◆ BlUtlCheckSum()

ULONG BlUtlCheckSum ( _In_ ULONG  PartialSum,
_In_ PUCHAR  Buffer,
_In_ ULONG  Length,
_In_ ULONG  Flags 
)

Definition at line 777 of file util.c.

783{
784 ULONG i;
785
787 {
788 EfiPrintf(L"Not supported\r\n");
789 return 0;
790 }
792 {
793 PartialSum = (unsigned __int16)PartialSum;
794 Length &= ~1;
795
796 for (i = 0; i < Length; i += 2)
797 {
798 PartialSum += *(unsigned __int16 *)&Buffer[i];
800 {
801 PartialSum = (unsigned __int16)((PartialSum >> 16) + PartialSum);
802 }
803 }
804
805 if (i != Length)
806 {
807 PartialSum += (unsigned __int8)Buffer[Length];
809 {
810 PartialSum = (unsigned __int16)((PartialSum >> 16) + PartialSum);
811 }
812 }
813
815 {
816 return ~PartialSum;
817 }
818
819 PartialSum = (unsigned __int16)PartialSum;
820 }
821 else
822 {
823 /* Invalid mode */
824 return 0;
825 }
826
828 {
829 return ~PartialSum;
830 }
831
832 return PartialSum;
833}
#define __int8
Definition: basetyps.h:25
#define __int16
Definition: basetyps.h:22
#define BL_UTL_CHECKSUM_USHORT_BUFFER
Definition: bl.h:191
#define BL_UTL_CHECKSUM_COMPLEMENT
Definition: bl.h:187
#define BL_UTL_CHECKSUM_UCHAR_BUFFER
Definition: bl.h:190
#define BL_UTL_CHECKSUM_NEGATE
Definition: bl.h:189
Definition: bufpool.h:45
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170

Referenced by ImgpLoadPEImage().

◆ BlUtlGetAcpiTable()

NTSTATUS BlUtlGetAcpiTable ( _Out_ PVOID TableAddress,
_In_ ULONG  Signature 
)

Definition at line 34 of file util.c.

38{
39 ULONG i, TableCount, HeaderLength;
41 PRSDT Rsdt;
42 PXSDT Xsdt;
45
46 Header = 0;
47
48 /* Make sure there's an output parameter */
49 if (!TableAddress)
50 {
52 }
53
54 /* Get the currently known RSDT and XSDT */
55 Rsdt = (PRSDT)UtlRsdt;
56 Xsdt = (PXSDT)UtlXsdt;
57
58 /* Is there an RSDT? */
59 if (!Rsdt)
60 {
61 /* No -- is there an XSDT? */
62 if (!Xsdt)
63 {
64 /* No. Look up the RSDT */
66 if (!NT_SUCCESS(Status))
67 {
68 EfiPrintf(L"no rsdp found\r\n");
69 return Status;
70 }
71
72 /* Map the header */
74 0,
75 sizeof(*Header),
77 if (!NT_SUCCESS(Status))
78 {
79 return Status;
80 }
81
82 /* Unmap the header */
84
85 /* Map the whole table */
87 0,
88 Header->Length,
90 if (!NT_SUCCESS(Status))
91 {
92 return Status;
93 }
94
95 /* Check if its an XSDT or an RSDT */
96 if (Header->Signature == XSDT_SIGNATURE)
97 {
98 /* It's an XSDT */
99 Xsdt = (PXSDT)Header;
100 UtlXsdt = Xsdt;
101 }
102 else
103 {
104 /* It's an RSDT */
105 Rsdt = (PRSDT)Header;
106 UtlRsdt = Rsdt;
107 }
108 }
109 }
110
111 /* OK, so do we have an XSDT after all? */
112 if (Xsdt)
113 {
114 /* Yes... how big is it? */
115 HeaderLength = Xsdt->Header.Length;
116 if (HeaderLength >= sizeof(*Header))
117 {
118 HeaderLength = sizeof(*Header);
119 }
120
121 /* Based on that, how many tables are there? */
122 TableCount = (Xsdt->Header.Length - HeaderLength) / sizeof(PHYSICAL_ADDRESS);
123 }
124 else
125 {
126 /* Nope, we have an RSDT. How big is it? */
127 HeaderLength = Rsdt->Header.Length;
128 if (HeaderLength >= sizeof(*Header))
129 {
130 HeaderLength = sizeof(*Header);
131 }
132
133 /* Based on that, how many tables are there? */
134 TableCount = (Rsdt->Header.Length - HeaderLength) / sizeof(ULONG);
135 }
136
137 /* Loop through the ACPI tables */
138 for (i = 0; i < TableCount; i++)
139 {
140 /* For an XSDT, read the 64-bit address directly */
141 if (Xsdt)
142 {
143 PhysicalAddress = Xsdt->Tables[i];
144 }
145 else
146 {
147 /* For RSDT, cast it */
149 }
150
151 /* Map the header */
153 0,
154 sizeof(*Header),
156 if (!NT_SUCCESS(Status))
157 {
158 return Status;
159 }
160
161 /* Is it the right one? */
162 if (Header->Signature == Signature)
163 {
164 /* Unmap the header */
166
167 /* Map the whole table */
168 return BlMmMapPhysicalAddressEx(TableAddress,
169 0,
170 Header->Length,
172 }
173 }
174
175 /* Requested table does not exist */
176 return STATUS_NOT_FOUND;
177}
NTSTATUS BlMmUnmapVirtualAddressEx(_In_ PVOID VirtualAddress, _In_ ULONGLONG Size)
Definition: mm.c:487
NTSTATUS BlMmMapPhysicalAddressEx(_In_ PVOID *VirtualAddress, _In_ ULONG Attributes, _In_ ULONGLONG Size, _In_ PHYSICAL_ADDRESS PhysicalAddress)
Definition: mm.c:192
NTSTATUS EfipGetRsdt(_Out_ PPHYSICAL_ADDRESS FoundRsdt)
Definition: firmware.c:1635
PRSDT UtlRsdt
Definition: util.c:15
PXSDT UtlXsdt
Definition: util.c:16
Definition: Header.h:9
static const WCHAR Signature[]
Definition: parser.c:141
RSDT * PRSDT
Definition: acpi.h:191
#define XSDT_SIGNATURE
Definition: acpi.h:39
XSDT * PXSDT
Definition: acpi.h:198
ULONG Length
Definition: acpi.h:97
Definition: acpi.h:187
ULONG Tables[ANYSIZE_ARRAY]
Definition: acpi.h:189
DESCRIPTION_HEADER Header
Definition: acpi.h:188
Definition: acpi.h:194
PHYSICAL_ADDRESS Tables[ANYSIZE_ARRAY]
Definition: acpi.h:196
DESCRIPTION_HEADER Header
Definition: acpi.h:195
LONGLONG QuadPart
Definition: typedefs.h:114
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS PhysicalAddress
Definition: iotypes.h:1098

Referenced by BlDisplayGetOemBitmap(), and BlDisplayInvalidateOemBitmap().

◆ BlUtlInitialize()

NTSTATUS BlUtlInitialize ( VOID  )

Definition at line 197 of file util.c.

200{
201 UtlRsdt = 0;
202 UtlXsdt = 0;
203
204 UtlMcContext = 0;
207
215 UtlProgressInfo = 0;
216
217 return STATUS_SUCCESS;
218}
ULONG UtlProgressGranularity
Definition: util.c:25
PVOID UtlMcContext
Definition: util.c:18
PVOID UtlProgressInfo
Definition: util.c:29
ULONG UtlNextUpdatePercentage
Definition: util.c:27
PVOID UtlProgressInfoRoutine
Definition: util.c:24
ULONG UtlCurrentPercentComplete
Definition: util.c:26
PVOID UtlMcUpdateMessageRoutine
Definition: util.c:20
PVOID UtlMcDisplayMessageRoutine
Definition: util.c:19
BOOLEAN UtlProgressNeedsInfoUpdate
Definition: util.c:28
PVOID UtlProgressRoutine
Definition: util.c:22
PVOID UtlProgressContext
Definition: util.c:23

Referenced by InitializeLibrary().

◆ BlUtlRegisterProgressRoutine()

NTSTATUS BlUtlRegisterProgressRoutine ( VOID  )

Definition at line 244 of file util.c.

247{
248 /* One shouldn't already exist */
250 {
251 return STATUS_UNSUCCESSFUL;
252 }
253
254 /* Set the routine, and no context */
257
258 /* Progress increases by one */
260
261 /* Set progress to zero for now */
264
265 /* Set the info routine if there is one */
267
268 /* All good */
269 return STATUS_SUCCESS;
270}
VOID BmUpdateProgress(_In_ PVOID Unknown, _In_ ULONG Percent, _Out_ PBOOLEAN Completed)
Definition: util.c:230
VOID BmUpdateProgressInfo(_In_ PVOID Unknown, _In_ PWCHAR ProgressInfo)
Definition: util.c:221
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132

Referenced by BmMain().

◆ BlUtlUpdateProgress()

VOID BlUtlUpdateProgress ( _In_ ULONG  Percentage,
_Out_opt_ PBOOLEAN  Completed 
)

Definition at line 181 of file util.c.

185{
187 {
188 EfiPrintf(L"Unimplemented\r\n");
189 }
190 else if (*Completed)
191 {
192 *Completed = TRUE;
193 }
194}

Referenced by BlImgLoadImageWithProgress2().

◆ BmUpdateProgress()

VOID BmUpdateProgress ( _In_ PVOID  Unknown,
_In_ ULONG  Percent,
_Out_ PBOOLEAN  Completed 
)

Definition at line 230 of file util.c.

235{
236 EfiPrintf(L"Progress: %d\r\n", Percent);
237 if (Completed)
238 {
239 *Completed = TRUE;
240 }
241}

Referenced by BlUtlRegisterProgressRoutine().

◆ BmUpdateProgressInfo()

VOID BmUpdateProgressInfo ( _In_ PVOID  Unknown,
_In_ PWCHAR  ProgressInfo 
)

Definition at line 221 of file util.c.

225{
226 EfiPrintf(L"Progress Info: %s\r\n", ProgressInfo);
227}

Referenced by BlUtlRegisterProgressRoutine().

◆ DefaultHashFunction()

ULONG DefaultHashFunction ( _In_ PBL_HASH_ENTRY  Entry,
_In_ ULONG  TableSize 
)

Definition at line 442 of file util.c.

446{
448 ULONG KeyHash, i;
449
450 /* Check if the value is a pointer, or embedded inline */
451 Value = (Entry->Flags & BL_HT_VALUE_IS_INLINE) ? Entry->Value : (PUCHAR)&Entry->Value;
452
453 /* Iterate over each byte, and sum it */
454 for (i = 0, KeyHash = 0; i < Entry->Size; i++)
455 {
456 KeyHash += Value[i++];
457 }
458
459 /* Modulo the number of buckets */
460 return KeyHash % TableSize;
461}
unsigned char * PUCHAR
Definition: typedefs.h:53
_Must_inspect_result_ typedef _Out_ PULONG TableSize
Definition: iotypes.h:4327

Referenced by BlHtCreate().

◆ HtpCompareKeys()

BOOLEAN HtpCompareKeys ( _In_ PBL_HASH_ENTRY  Entry1,
_In_ PBL_HASH_ENTRY  Entry2 
)

Definition at line 464 of file util.c.

468{
469 ULONG Flags;
470 BOOLEAN ValueMatch;
471
472 /* Check if the flags or sizes are not matching */
473 Flags = Entry1->Flags;
474 if ((Entry1->Size != Entry2->Size) || (Flags != Entry2->Flags))
475 {
476 ValueMatch = FALSE;
477 }
478 else if (Flags & BL_HT_VALUE_IS_INLINE)
479 {
480 /* Check if this is an in-line value, compare it */
481 ValueMatch = Entry1->Value == Entry2->Value;
482 }
483 else
484 {
485 /* This is a pointer value, compare it */
486 ValueMatch = (RtlCompareMemory(Entry1->Value, Entry2->Value, Entry1->Size) ==
487 Entry1->Size);
488 }
489
490 /* Return if it matched */
491 return ValueMatch;
492}
#define RtlCompareMemory(s1, s2, l)
Definition: env_spec_w32.h:465

Referenced by BlHtCreate().

◆ TblDoNotPurgeEntry()

NTSTATUS TblDoNotPurgeEntry ( _In_ PVOID  Entry)

Definition at line 495 of file util.c.

498{
499 /* Never purge this entry */
500 return STATUS_UNSUCCESSFUL;
501}

Referenced by BlHtCreate(), BlImgLoadBootApplication(), BlockIoFirmwareOpen(), BlpIoRegisterDestroyRoutine(), and EtfsMount().

Variable Documentation

◆ HtTableArray

PBL_HASH_TABLE* HtTableArray

Definition at line 438 of file util.c.

Referenced by BlHtCreate(), BlHtDelete(), BlHtLookup(), and BlHtStore().

◆ HtTableEntries

ULONG HtTableEntries

Definition at line 439 of file util.c.

Referenced by BlHtCreate().

◆ HtTableSize

ULONG HtTableSize

Definition at line 437 of file util.c.

Referenced by BlHtCreate(), BlHtDelete(), BlHtLookup(), and BlHtStore().

◆ UtlCurrentPercentComplete

ULONG UtlCurrentPercentComplete

Definition at line 26 of file util.c.

Referenced by BlUtlInitialize(), and BlUtlRegisterProgressRoutine().

◆ UtlMcContext

PVOID UtlMcContext

Definition at line 18 of file util.c.

Referenced by BlUtlInitialize().

◆ UtlMcDisplayMessageRoutine

PVOID UtlMcDisplayMessageRoutine

Definition at line 19 of file util.c.

Referenced by BlUtlInitialize().

◆ UtlMcUpdateMessageRoutine

PVOID UtlMcUpdateMessageRoutine

Definition at line 20 of file util.c.

Referenced by BlUtlInitialize().

◆ UtlNextUpdatePercentage

ULONG UtlNextUpdatePercentage

Definition at line 27 of file util.c.

Referenced by BlUtlInitialize(), and BlUtlRegisterProgressRoutine().

◆ UtlProgressContext

PVOID UtlProgressContext

Definition at line 23 of file util.c.

Referenced by BlUtlInitialize(), and BlUtlRegisterProgressRoutine().

◆ UtlProgressGranularity

ULONG UtlProgressGranularity

Definition at line 25 of file util.c.

Referenced by BlUtlInitialize(), and BlUtlRegisterProgressRoutine().

◆ UtlProgressInfo

PVOID UtlProgressInfo

Definition at line 29 of file util.c.

Referenced by BlUtlInitialize().

◆ UtlProgressInfoRoutine

PVOID UtlProgressInfoRoutine

Definition at line 24 of file util.c.

Referenced by BlUtlInitialize(), and BlUtlRegisterProgressRoutine().

◆ UtlProgressNeedsInfoUpdate

BOOLEAN UtlProgressNeedsInfoUpdate

Definition at line 28 of file util.c.

Referenced by BlUtlInitialize().

◆ UtlProgressRoutine

PVOID UtlProgressRoutine

Definition at line 22 of file util.c.

Referenced by BlUtlInitialize(), BlUtlRegisterProgressRoutine(), and BlUtlUpdateProgress().

◆ UtlRsdt

PRSDT UtlRsdt

Definition at line 15 of file util.c.

Referenced by BlUtlGetAcpiTable(), and BlUtlInitialize().

◆ UtlXsdt

PXSDT UtlXsdt

Definition at line 16 of file util.c.

Referenced by BlUtlGetAcpiTable(), and BlUtlInitialize().