OpenCore  1.0.4
OpenCore Bootloader
Loading...
Searching...
No Matches
OcMiscLib.h File Reference
#include <Uefi.h>
#include <Library/OcStringLib.h>
#include <Protocol/ApplePlatformInfoDatabase.h>

Go to the source code of this file.

Macros

#define OC_CHAR_BIT   8
 
#define SECONDS_TO_MICROSECONDS(x)
 
#define MS_TO_MICROSECONDS(x)
 
#define SECONDS_TO_NANOSECONDS(x)
 
#define MS_TO_NANOSECONDS(x)
 
#define _ASSERT_EQUALS(Expression, ExpectedValue)
 
#define ASSERT_EQUALS(Expression, ExpectedValue)
 

Functions

BOOLEAN FindPattern (IN CONST UINT8 *Pattern, IN CONST UINT8 *PatternMask OPTIONAL, IN CONST UINT32 PatternSize, IN CONST UINT8 *Data, IN UINT32 DataSize, IN OUT UINT32 *DataOff)
 
UINT32 ApplyPatch (IN CONST UINT8 *Pattern, IN CONST UINT8 *PatternMask OPTIONAL, IN CONST UINT32 PatternSize, IN CONST UINT8 *Replace, IN CONST UINT8 *ReplaceMask OPTIONAL, IN UINT8 *Data, IN UINT32 DataSize, IN UINT32 Count, IN UINT32 Skip)
 
EFI_STATUS GetArguments (OUT UINTN *Argc, OUT CHAR16 ***Argv)
 
EFI_STATUS OcUninstallAllProtocolInstances (EFI_GUID *Protocol)
 
EFI_STATUS OcHandleProtocolFallback (IN EFI_HANDLE Handle, IN EFI_GUID *Protocol, OUT VOID **Interface)
 
UINTN OcCountProtocolInstances (IN EFI_GUID *Protocol)
 
VOID * OcGetProtocol (IN EFI_GUID *Protocol, IN UINTN ErrorLevel, IN CONST CHAR8 *CallerName OPTIONAL, IN CONST CHAR8 *ProtocolName OPTIONAL)
 
EFI_STATUS OcLoadAndRunImage (IN EFI_DEVICE_PATH_PROTOCOL *DevicePath OPTIONAL, IN VOID *Buffer OPTIONAL, IN UINTN BufferSize, OUT EFI_HANDLE *ImageHandle OPTIONAL, IN CHAR16 *OptionalData OPTIONAL)
 
EFI_STATUS OcReadApplePlatformFirstData (IN APPLE_PLATFORM_INFO_DATABASE_PROTOCOL *PlatformInfo, IN EFI_GUID *DataGuid, IN OUT UINT32 *Size, OUT VOID *Data)
 
EFI_STATUS OcReadApplePlatformFirstDataAlloc (IN APPLE_PLATFORM_INFO_DATABASE_PROTOCOL *PlatformInfo, IN EFI_GUID *DataGuid, OUT UINT32 *Size, OUT VOID **Data)
 
EFI_STATUS OcReadApplePlatformData (IN APPLE_PLATFORM_INFO_DATABASE_PROTOCOL *PlatformInfo, IN EFI_GUID *DataGuid, IN EFI_GUID *HobGuid, IN OUT UINT32 *Size, OUT VOID *Data)
 
VOID OcConsoleFlush (VOID)
 

Detailed Description

Copyright (C) 2016 - 2018, The HermitCrabs Lab. All rights reserved.

All rights reserved.

This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at http://opensource.org/licenses/bsd-license.php

THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.

Definition in file OcMiscLib.h.

Macro Definition Documentation

◆ _ASSERT_EQUALS

#define _ASSERT_EQUALS ( Expression,
ExpectedValue )
Value:
DEBUG_ERROR, \
"ASSERT %a(%d): %a (expected: %d, actual: %d)\n", \
__FILE__, \
__LINE__, \
#Expression, \
(INTN)(ExpectedValue), \
(INTN)(Expression))
VOID EFIAPI DebugPrint(IN UINTN ErrorLevel, IN CONST CHAR8 *Format,...)

Internal worker macro that calls DebugPrint().

This macro calls DebugPrint(), passing in the filename, line number, an expression that failed the comparison with expected value, the expected value and the actual value.

Parameters
ExpressionInteger expression that evaluated to value different from Value (should be convertible to INTN)
ExpectedValueExpected value of the expression (should be convertible to INTN)

Definition at line 234 of file OcMiscLib.h.

◆ ASSERT_EQUALS

#define ASSERT_EQUALS ( Expression,
ExpectedValue )
Value:
do { \
if (DebugAssertEnabled ()) { \
if ((Expression) != (ExpectedValue)) { \
_ASSERT_EQUALS (Expression, ExpectedValue); \
ASSERT(FALSE); \
ANALYZER_UNREACHABLE (); \
} \
} \
} while (FALSE)
BOOLEAN EFIAPI DebugAssertEnabled(VOID)

Macro that calls DebugAssert() if the value of an expression differs from the expected value.

If MDEPKG_NDEBUG is not defined and the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set, then this macro evaluates the integer expression specified by Expression. If the value of Expression differs from ExpectedValue, then DebugPrint() is called passing in the source filename, source line number, Expression, its value and ExpectedValue; then ASSERT(FALSE) is called to cause a breakpoint, deadloop or no-op depending on PcdDebugProperyMask.

Parameters
ExpressionInteger expression (should be convertible to INTN).
ExpectedValueExpected value (should be convertible to INTN).

Definition at line 259 of file OcMiscLib.h.

◆ MS_TO_MICROSECONDS

#define MS_TO_MICROSECONDS ( x)
Value:
((x) * 1000)
UINT16 x
Definition BmfFile.h:83

Definition at line 31 of file OcMiscLib.h.

◆ MS_TO_NANOSECONDS

#define MS_TO_NANOSECONDS ( x)
Value:
((x) * 1000000)

Definition at line 37 of file OcMiscLib.h.

◆ OC_CHAR_BIT

#define OC_CHAR_BIT   8

The size, in Bits, of one Byte.

Definition at line 25 of file OcMiscLib.h.

◆ SECONDS_TO_MICROSECONDS

#define SECONDS_TO_MICROSECONDS ( x)
Value:
((x) * 1000000)

Conversions to microseconds for use in e.g. gBS->Stall.

Definition at line 30 of file OcMiscLib.h.

◆ SECONDS_TO_NANOSECONDS

#define SECONDS_TO_NANOSECONDS ( x)
Value:
((x) * 1000000000)

Conversions to nanoseconds for use in e.g. PciIo->PollMem.

Definition at line 36 of file OcMiscLib.h.

Function Documentation

◆ ApplyPatch()

UINT32 ApplyPatch ( IN CONST UINT8 * Pattern,
IN CONST UINT8 *PatternMask OPTIONAL,
IN CONST UINT32 PatternSize,
IN CONST UINT8 * Replace,
IN CONST UINT8 *ReplaceMask OPTIONAL,
IN UINT8 * Data,
IN UINT32 DataSize,
IN UINT32 Count,
IN UINT32 Skip )

Definition at line 106 of file DataPatcher.c.

◆ FindPattern()

BOOLEAN FindPattern ( IN CONST UINT8 * Pattern,
IN CONST UINT8 *PatternMask OPTIONAL,
IN CONST UINT32 PatternSize,
IN CONST UINT8 * Data,
IN UINT32 DataSize,
IN OUT UINT32 * DataOff )

Definition at line 82 of file DataPatcher.c.

◆ GetArguments()

EFI_STATUS GetArguments ( OUT UINTN * Argc,
OUT CHAR16 *** Argv )

Obtain application arguments.

Parameters
[out]ArgcArgument count.
[out]ArgvArgument list.
Return values
EFI_SUCCESSon success.

Definition at line 25 of file ProtocolSupport.c.

◆ OcConsoleFlush()

VOID OcConsoleFlush ( VOID )

Performs ConIn keyboard input flush.

Definition at line 13 of file ConsoleUtils.c.

◆ OcCountProtocolInstances()

UINTN OcCountProtocolInstances ( IN EFI_GUID * Protocol)

Count instances found under a specific protocol.

Parameters
[in]ProtocolProtocol to search for.
Returns
Number of instances found.

Definition at line 149 of file ProtocolSupport.c.

◆ OcGetProtocol()

VOID * OcGetProtocol ( IN EFI_GUID * Protocol,
IN UINTN ErrorLevel,
IN CONST CHAR8 *CallerName OPTIONAL,
IN CONST CHAR8 *ProtocolName OPTIONAL )

Obtain protocol. If not obtained returns NULL, and optionally adds log message "[CallerName] cannot get protocol [ProtocolName] - %r".

Parameters
[in]ProtocolProtocol to search for.
[in]ErrorLevelThe error level of the debug log message to print if protocol not found. Send zero to generate no log message (caller becomes reponsible).
[in]CallerNameThe caller name for the error message; should always be provided if ErrorLevel is non-zero; will work, but with less useful log output, if ommitted in that case.
[in]ProtocolNameThe protocol name for the error message; optional, protocol GUID will be used as protocol name in error message when required, otherwise.
Returns
Protocol instance, or NULL if not found.

Definition at line 179 of file ProtocolSupport.c.

◆ OcHandleProtocolFallback()

EFI_STATUS OcHandleProtocolFallback ( IN EFI_HANDLE Handle,
IN EFI_GUID * Protocol,
OUT VOID ** Interface )

Handle protocol on handle and fallback to any protocol when missing.

Parameters
[in]HandleHandle to search for protocol.
[in]ProtocolProtocol to search for.
[out]InterfaceProtocol interface if found.
Return values
EFI_SUCCESSon success.

Definition at line 124 of file ProtocolSupport.c.

◆ OcLoadAndRunImage()

EFI_STATUS OcLoadAndRunImage ( IN EFI_DEVICE_PATH_PROTOCOL *DevicePath OPTIONAL,
IN VOID *Buffer OPTIONAL,
IN UINTN BufferSize,
OUT EFI_HANDLE *ImageHandle OPTIONAL,
IN CHAR16 *OptionalData OPTIONAL )

Run and execute image file from buffer.

Parameters
[in]DevicePathImage device path, optional.
[in]BufferBuffer with image data, optional when DP is given.
[in]BufferSizeImage data size in the buffer.
[out]ImageHandleLoaded image handle for drivers, optional.
[out]OptionalDataData that is passed to the loaded image, optional.

Definition at line 25 of file ImageRunner.c.

◆ OcReadApplePlatformData()

EFI_STATUS OcReadApplePlatformData ( IN APPLE_PLATFORM_INFO_DATABASE_PROTOCOL * PlatformInfo,
IN EFI_GUID * DataGuid,
IN EFI_GUID * HobGuid,
IN OUT UINT32 * Size,
OUT VOID * Data )

Read data from Apple Platform Info protocol.

Parameters
[in]PlatformInfoApple Platform Info protocol.
[in]DataGuidResource GUID identifier.
[in]HobGuidHob GUID identifier.
[in,out]SizeMaximum size allowed, updated to actual size on success.
[out]DataData read from Apple Platform Info protocol.
Return values
EFI_SUCCESSon success.

Definition at line 155 of file PlatformInfo.c.

◆ OcReadApplePlatformFirstData()

EFI_STATUS OcReadApplePlatformFirstData ( IN APPLE_PLATFORM_INFO_DATABASE_PROTOCOL * PlatformInfo,
IN EFI_GUID * DataGuid,
IN OUT UINT32 * Size,
OUT VOID * Data )

Read first data from Apple Platform Info protocol.

Parameters
[in]PlatformInfoApple Platform Info protocol.
[in]DataGuidResource GUID identifier.
[in,out]SizeMaximum size allowed, updated to actual size on success.
[out]DataData read from Apple Platform Info protocol.
Return values
EFI_SUCCESSon success.

Definition at line 26 of file PlatformInfo.c.

◆ OcReadApplePlatformFirstDataAlloc()

EFI_STATUS OcReadApplePlatformFirstDataAlloc ( IN APPLE_PLATFORM_INFO_DATABASE_PROTOCOL * PlatformInfo,
IN EFI_GUID * DataGuid,
OUT UINT32 * Size,
OUT VOID ** Data )

Read first data from Apple Platform Info protocol allocating memory from pool.

Parameters
[in]PlatformInfoApple Platform Info protocol.
[in]DataGuidResource GUID identifier.
[out]SizeSize of the entry.
[out]DataData read from Apple Platform Info protocol allocated from pool.
Return values
EFI_SUCCESSon success.

Definition at line 91 of file PlatformInfo.c.

◆ OcUninstallAllProtocolInstances()

EFI_STATUS OcUninstallAllProtocolInstances ( EFI_GUID * Protocol)

Uninstall all protocols with the specified GUID.

Parameters
[in]ProtocolThe published unique identifier of the protocol. It is the caller's responsibility to pass in a valid GUID.
Return values
EFI_SUCCESSon success.

Definition at line 70 of file ProtocolSupport.c.