OpenCore  1.0.4
OpenCore Bootloader
Loading...
Searching...
No Matches
BootArguments.c File Reference
#include <Guid/AppleVariable.h>
#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/OcBootManagementLib.h>
#include <Library/OcFlexArrayLib.h>
#include <Library/PrintLib.h>
#include <Library/UefiLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiRuntimeServicesTableLib.h>
#include "BootManagementInternal.h"

Go to the source code of this file.

Macros

#define SHIFT_TOKEN(pos, token, offset)
 

Typedefs

typedef enum PARSE_VARS_STATE_ PARSE_VARS_STATE
 

Enumerations

enum  PARSE_VARS_STATE_ {
  PARSE_VARS_WHITE_SPACE , PARSE_VARS_COMMENT , PARSE_VARS_NAME , PARSE_VARS_VALUE ,
  PARSE_VARS_QUOTED_VALUE , PARSE_VARS_SHELL_EXPANSION
}
 

Functions

VOID OcParseBootArgs (OUT OC_BOOT_ARGUMENTS *Arguments, IN VOID *BootArgs)
 
CONST CHAR8 * OcGetArgumentFromCmd (IN CONST CHAR8 *CommandLine, IN CONST CHAR8 *Argument, IN CONST UINTN ArgumentLength, OUT UINTN *ValueLength OPTIONAL)
 
VOID OcRemoveArgumentFromCmd (IN OUT CHAR8 *CommandLine, IN CONST CHAR8 *Argument)
 
BOOLEAN OcAppendArgumentToCmd (IN OUT OC_PICKER_CONTEXT *Context OPTIONAL, IN OUT CHAR8 *CommandLine, IN CONST CHAR8 *Argument, IN CONST UINTN ArgumentLength)
 
BOOLEAN OcAppendArgumentsToLoadedImage (IN OUT EFI_LOADED_IMAGE_PROTOCOL *LoadedImage, IN CONST CHAR8 **Arguments, IN UINT32 ArgumentCount, IN BOOLEAN Replace)
 
BOOLEAN OcCheckArgumentFromEnv (IN EFI_LOADED_IMAGE *LoadedImage OPTIONAL, IN EFI_GET_VARIABLE GetVariable OPTIONAL, IN CONST CHAR8 *Argument, IN CONST UINTN ArgumentLength, IN OUT CHAR8 **Value OPTIONAL)
 
BOOLEAN EFIAPI OcValidLoadOptions (IN UINT32 LoadOptionsSize, IN CONST VOID *LoadOptions)
 
BOOLEAN EFIAPI OcHasLoadOptions (IN UINT32 LoadOptionsSize, IN CONST VOID *LoadOptions)
 
EFI_STATUS OcParseLoadOptions (IN CONST EFI_LOADED_IMAGE_PROTOCOL *LoadedImage, OUT OC_FLEX_ARRAY **ParsedVars)
 
EFI_STATUS OcParseVars (IN VOID *StrVars, OUT OC_FLEX_ARRAY **ParsedVars, IN CONST OC_STRING_FORMAT StringFormat, IN CONST BOOLEAN TokensOnly)
 
OC_PARSED_VAROcParsedVarsItemAt (IN CONST OC_FLEX_ARRAY *ParsedVars, IN CONST UINTN Index)
 
BOOLEAN OcParsedVarsGetStr (IN CONST OC_FLEX_ARRAY *ParsedVars, IN CONST VOID *Name, OUT VOID **Value, IN CONST OC_STRING_FORMAT StringFormat)
 
BOOLEAN OcParsedVarsGetUnicodeStr (IN CONST OC_FLEX_ARRAY *ParsedVars, IN CONST CHAR16 *Name, OUT CHAR16 **Value)
 
BOOLEAN OcParsedVarsGetAsciiStr (IN CONST OC_FLEX_ARRAY *ParsedVars, IN CONST CHAR8 *Name, OUT CHAR8 **Value)
 
BOOLEAN OcHasParsedVar (IN CONST OC_FLEX_ARRAY *ParsedVars, IN CONST VOID *Name, IN CONST OC_STRING_FORMAT StringFormat)
 
EFI_STATUS OcParsedVarsGetInt (IN CONST OC_FLEX_ARRAY *ParsedVars, IN CONST VOID *Name, OUT UINTN *Value, IN CONST OC_STRING_FORMAT StringFormat)
 
EFI_STATUS OcParsedVarsGetGuid (IN CONST OC_FLEX_ARRAY *ParsedVars, IN CONST VOID *Name, OUT EFI_GUID *Value, IN CONST OC_STRING_FORMAT StringFormat)
 

Detailed Description

Copyright (C) 2019-2024, vit9696, mikebeaton. All rights reserved.
SPDX-License-Identifier: BSD-3-Clause

Definition in file BootArguments.c.

Macro Definition Documentation

◆ SHIFT_TOKEN

#define SHIFT_TOKEN ( pos,
token,
offset )
Value:
do {\
CopyMem ((UINT8 *)(token) + (offset), (token), (UINT8 *)(pos) - (UINT8 *)(token)); \
(token) = (UINT8 *)(token) + (offset); \
} while (0)

Definition at line 37 of file BootArguments.c.

Typedef Documentation

◆ PARSE_VARS_STATE

Enumeration Type Documentation

◆ PARSE_VARS_STATE_

Enumerator
PARSE_VARS_WHITE_SPACE 
PARSE_VARS_COMMENT 
PARSE_VARS_NAME 
PARSE_VARS_VALUE 
PARSE_VARS_QUOTED_VALUE 
PARSE_VARS_SHELL_EXPANSION 

Definition at line 23 of file BootArguments.c.

Function Documentation

◆ OcAppendArgumentsToLoadedImage()

BOOLEAN OcAppendArgumentsToLoadedImage ( IN OUT EFI_LOADED_IMAGE_PROTOCOL * LoadedImage,
IN CONST CHAR8 ** Arguments,
IN UINT32 ArgumentCount,
IN BOOLEAN Replace )

Append 1 or more arguments to Loaded Image protocol.

Parameters
[in,out]LoadedImageLoaded Image protocol instance.
[in]ArgumentsArgument array.
[in]ArgumentCountNumber of arguments in the array.
[in]ReplaceWhether to append to existing arguments or replace.
Return values
TRUEon success.

Definition at line 224 of file BootArguments.c.

◆ OcAppendArgumentToCmd()

BOOLEAN OcAppendArgumentToCmd ( IN OUT OC_PICKER_CONTEXT *Context OPTIONAL,
IN OUT CHAR8 * CommandLine,
IN CONST CHAR8 * Argument,
IN CONST UINTN ArgumentLength )

Append argument to command line without deduplication.

Parameters
[in,out]ContextPicker context. NULL, if a privilege escalation is not required.
[in,out]CommandLineArgument command line of BOOT_LINE_LENGTH bytes.
[in]ArgumentArgument, e.g. -v, slide=0, debug=0x100, etc.
[in]ArgumentLengthArgument length, e.g. L_STR_LEN ("-v").
Return values
TRUEon success.

Definition at line 184 of file BootArguments.c.

◆ OcCheckArgumentFromEnv()

BOOLEAN OcCheckArgumentFromEnv ( IN EFI_LOADED_IMAGE *LoadedImage OPTIONAL,
IN EFI_GET_VARIABLE GetVariable OPTIONAL,
IN CONST CHAR8 * Argument,
IN CONST UINTN ArgumentLength,
IN OUT CHAR8 **Value OPTIONAL )

Check if boot argument is currently passed (via image options or NVRAM).

Parameters
[in]LoadedImageUEFI loaded image protocol instance, optional.
[in]GetVariablePreferred UEFI NVRAM reader, optional.
[in]ArgumentArgument, e.g. -v, slide=, debug=, etc.
[in]ArgumentLengthArgument length, e.g. L_STR_LEN ("-v").
[in,out]ValueArgument value allocated from pool.
Return values
TRUEif argument is present.

Definition at line 298 of file BootArguments.c.

◆ OcGetArgumentFromCmd()

CONST CHAR8 * OcGetArgumentFromCmd ( IN CONST CHAR8 * CommandLine,
IN CONST CHAR8 * Argument,
IN CONST UINTN ArgumentLength,
OUT UINTN *ValueLength OPTIONAL )

Get argument value from command line.

Parameters
[in]CommandLineArgument command line, e.g. for boot.efi.
[in]ArgumentArgument, e.g. -v, slide=, debug=, etc.
[in]ArgumentLengthArgument length, e.g. L_STR_LEN ("-v").
[out]ValueLengthArgument value length, optional.
Return values
pointerto argument value or NULL.

Definition at line 97 of file BootArguments.c.

◆ OcHasLoadOptions()

BOOLEAN EFIAPI OcHasLoadOptions ( IN UINT32 LoadOptionsSize,
IN CONST VOID * LoadOptions )

Are load options present as a Unicode string?

Parameters
[in]LoadOptionsSizeLoad options size.
[in]LoadOptionsLoad options.
Return values
TRUEif valid.

Definition at line 402 of file BootArguments.c.

◆ OcHasParsedVar()

BOOLEAN OcHasParsedVar ( IN CONST OC_FLEX_ARRAY * ParsedVars,
IN CONST VOID * Name,
IN CONST OC_STRING_FORMAT StringFormat )

Get presence or absence of parsed shell var or load option.

Parameters
[in]ParsedVarsParsed variables.
[in]NameOption name.
[in]StringFormatAre option names and values Unicode or ASCII?
Return values
TRUEOption exists (with or without a value).
FALSEOption not found.

Definition at line 737 of file BootArguments.c.

◆ OcParseBootArgs()

VOID OcParseBootArgs ( OUT OC_BOOT_ARGUMENTS * Arguments,
IN VOID * BootArgs )

Parse macOS kernel into unified boot arguments structure.

Parameters
[out]ArgumentsUnified boot arguments structure.
[in]BootArgsKernel boot arguments strucutre.

Definition at line 43 of file BootArguments.c.

◆ OcParsedVarsGetAsciiStr()

BOOLEAN OcParsedVarsGetAsciiStr ( IN CONST OC_FLEX_ARRAY * ParsedVars,
IN CONST CHAR8 * Name,
OUT CHAR8 ** StrValue )

Get ASCII string value of parsed var or load option. Return value points directly into original raw option memory, so may need to be copied if it is to be retained, and must not be freed directly.

Parameters
[in]ParsedVarsParsed variables.
[in]NameOption name.
[in]StrValueOption value if successful, not modified otherwise; note that NULL is returned if option exists with no value. Caller must not attempt to free this memory.
Return values
TRUEOption exists.
FALSEOption not found.

Definition at line 727 of file BootArguments.c.

◆ OcParsedVarsGetGuid()

EFI_STATUS OcParsedVarsGetGuid ( IN CONST OC_FLEX_ARRAY * ParsedVars,
IN CONST VOID * Name,
OUT EFI_GUID * Value,
IN CONST OC_STRING_FORMAT StringFormat )

Get guid value of parsed shell var or load option.

Parameters
[in]ParsedVarsParsed variables.
[in]NameOption name.
[in]ValueOption value if successful, not modified otherwise.
[in]StringFormatAre option names and values Unicode or ASCII?
Return values
EFI_SUCCESSSuccess.
EFI_NOT_FOUNDOption not found, or has no value.
otherError encountered when parsing option as guid.

Definition at line 785 of file BootArguments.c.

◆ OcParsedVarsGetInt()

EFI_STATUS OcParsedVarsGetInt ( IN CONST OC_FLEX_ARRAY * ParsedVars,
IN CONST VOID * Name,
OUT UINTN * Value,
IN CONST OC_STRING_FORMAT StringFormat )

Get integer value of parsed shell var or load option (parses hex and decimal representations).

Parameters
[in]ParsedVarsParsed variables.
[in]NameOption name.
[in]ValueOption value if successful, not modified otherwise.
[in]StringFormatAre option names and values Unicode or ASCII?
Return values
EFI_SUCCESSSuccess.
EFI_NOT_FOUNDOption not found, or has no value.
otherError encountered when parsing option as int.

Definition at line 749 of file BootArguments.c.

◆ OcParsedVarsGetStr()

BOOLEAN OcParsedVarsGetStr ( IN CONST OC_FLEX_ARRAY * ParsedVars,
IN CONST VOID * Name,
OUT VOID ** StrValue,
IN CONST OC_STRING_FORMAT StringFormat )

Get string value of parsed var or load option. Returned value is in same format as raw options. Return value points directly into original raw option memory, so may need to be copied if it is to be retained, and must not be freed directly.

Parameters
[in]ParsedVarsParsed variables.
[in]NameOption name.
[in]StrValueOption value if successful, not modified otherwise; note that NULL is returned if option exists with no value. Caller must not attempt to free this memory.
[in]StringFormatAre option names and values Unicode or ASCII?
Return values
TRUEOption exists.
FALSEOption not found.

Definition at line 669 of file BootArguments.c.

◆ OcParsedVarsGetUnicodeStr()

BOOLEAN OcParsedVarsGetUnicodeStr ( IN CONST OC_FLEX_ARRAY * ParsedVars,
IN CONST CHAR16 * Name,
OUT CHAR16 ** StrValue )

Get string value of parsed var or load option. Return value points directly into original raw option memory, so may need to be copied if it is to be retained, and must not be freed directly.

Parameters
[in]ParsedVarsParsed variables.
[in]NameOption name.
[in]StrValueOption value if successful, not modified otherwise; note that NULL is returned if option exists with no value. Caller must not attempt to free this memory.
Return values
TRUEOption exists.
FALSEOption not found.

Definition at line 717 of file BootArguments.c.

◆ OcParsedVarsItemAt()

OC_PARSED_VAR * OcParsedVarsItemAt ( IN CONST OC_FLEX_ARRAY * ParsedVars,
IN CONST UINTN Index )

Return parsed variable at given index.

Parameters
[in]ParsedVarsParsed variables.
[in]IndexIndex of option to return.
Return values
Parsedoption.

Definition at line 657 of file BootArguments.c.

◆ OcParseLoadOptions()

EFI_STATUS OcParseLoadOptions ( IN CONST EFI_LOADED_IMAGE_PROTOCOL * LoadedImage,
OUT OC_FLEX_ARRAY ** ParsedVars )

Parse loaded image protocol load options, resultant options are in the same format as is returned by OcParsedVars and may be examined using the same utility methods.

Assumes CHAR_NULL terminated Unicode string of space separated options, each of form {name} or {name}={value}. Double quotes can be used round {value} to include spaces, and '\' can be used within quoted or unquoted values to escape any character (including space and '"').

Note: Var names and values are left as pointers to within the original raw LoadOptions string, which may be modified during processing.

Parameters
[in]LoadedImageLoaded image handle.
[out]ParsedVarsParsed load options if successful, NULL otherwise. Caller may free after use with OcFlexArrayFree if required.
Return values
EFI_SUCCESSSuccess.
EFI_NOT_FOUNDMissing or empty load options.
EFI_OUT_OF_RESOURCESOut of memory.
EFI_INVALID_PARAMETERInvalid load options detected.

Definition at line 416 of file BootArguments.c.

◆ OcParseVars()

EFI_STATUS OcParseVars ( IN VOID * StrVars,
OUT OC_FLEX_ARRAY ** ParsedVars,
IN CONST OC_STRING_FORMAT StringFormat,
IN CONST BOOLEAN TokensOnly )

Parse Unix-style var file or string. Parses a couple of useful ASCII GRUB config files (multi-line, name=var, with optional comments) and defines a standard format for Unicode UEFI LoadOptions.

Assumes CHAR_NULL terminated Unicode string of space separated options, each of form {name} or {name}={value}. Double quotes can be used round {value} to include spaces, and backslash can be used within quoted or unquoted values to escape any character (including space and double quote). Comments (if any) run from hash symbol to end of same line.

Note: Var names and values are left as pointers to within the raw string, which may be modified during processing.

Parameters
[in]StrVarsRaw var string.
[out]ParsedVarsParsed variables if successful, NULL otherwise. Caller may free after use with OcFlexArrayFree.
[in]StringFormatAre option names and values Unicode or ASCII?
[in]TokensOnlyIf TRUE parse as a sequence of token values only, rather than as a sequence of name[=[value]] pairs.
Return values
EFI_SUCCESSSuccess.
EFI_NOT_FOUNDMissing or empty load options.
EFI_OUT_OF_RESOURCESOut of memory.
EFI_INVALID_PARAMETERInvalid load options detected.

Definition at line 449 of file BootArguments.c.

◆ OcRemoveArgumentFromCmd()

VOID OcRemoveArgumentFromCmd ( IN OUT CHAR8 * CommandLine,
IN CONST CHAR8 * Argument )

Remove argument from command line if present.

Parameters
[in,out]CommandLineArgument command line, e.g. for boot.efi.
[in]ArgumentArgument, e.g. -v, slide=, debug=, etc.

Definition at line 136 of file BootArguments.c.

◆ OcValidLoadOptions()

BOOLEAN EFIAPI OcValidLoadOptions ( IN UINT32 LoadOptionsSize,
IN CONST VOID * LoadOptions )

Are load options apparently valid (Unicode string or cleanly non-present)?

Parameters
[in]LoadOptionsSizeLoad options size.
[in]LoadOptionsLoad options.
Return values
TRUEif valid.

Definition at line 384 of file BootArguments.c.