OpenCore
1.0.4
OpenCore Bootloader
|
#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_VAR * | OcParsedVarsItemAt (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) |
Copyright (C) 2019-2024, vit9696, mikebeaton. All rights reserved.
SPDX-License-Identifier: BSD-3-Clause
Definition in file BootArguments.c.
#define SHIFT_TOKEN | ( | pos, | |
token, | |||
offset ) |
Definition at line 37 of file BootArguments.c.
typedef enum PARSE_VARS_STATE_ PARSE_VARS_STATE |
enum 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.
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.
[in,out] | LoadedImage | Loaded Image protocol instance. |
[in] | Arguments | Argument array. |
[in] | ArgumentCount | Number of arguments in the array. |
[in] | Replace | Whether to append to existing arguments or replace. |
TRUE | on success. |
Definition at line 224 of file BootArguments.c.
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.
[in,out] | Context | Picker context. NULL, if a privilege escalation is not required. |
[in,out] | CommandLine | Argument command line of BOOT_LINE_LENGTH bytes. |
[in] | Argument | Argument, e.g. -v, slide=0, debug=0x100, etc. |
[in] | ArgumentLength | Argument length, e.g. L_STR_LEN ("-v"). |
TRUE | on success. |
Definition at line 184 of file BootArguments.c.
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).
[in] | LoadedImage | UEFI loaded image protocol instance, optional. |
[in] | GetVariable | Preferred UEFI NVRAM reader, optional. |
[in] | Argument | Argument, e.g. -v, slide=, debug=, etc. |
[in] | ArgumentLength | Argument length, e.g. L_STR_LEN ("-v"). |
[in,out] | Value | Argument value allocated from pool. |
TRUE | if argument is present. |
Definition at line 298 of file BootArguments.c.
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.
[in] | CommandLine | Argument command line, e.g. for boot.efi. |
[in] | Argument | Argument, e.g. -v, slide=, debug=, etc. |
[in] | ArgumentLength | Argument length, e.g. L_STR_LEN ("-v"). |
[out] | ValueLength | Argument value length, optional. |
pointer | to argument value or NULL. |
Definition at line 97 of file BootArguments.c.
BOOLEAN EFIAPI OcHasLoadOptions | ( | IN UINT32 | LoadOptionsSize, |
IN CONST VOID * | LoadOptions ) |
Are load options present as a Unicode string?
[in] | LoadOptionsSize | Load options size. |
[in] | LoadOptions | Load options. |
TRUE | if valid. |
Definition at line 402 of file BootArguments.c.
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.
[in] | ParsedVars | Parsed variables. |
[in] | Name | Option name. |
[in] | StringFormat | Are option names and values Unicode or ASCII? |
TRUE | Option exists (with or without a value). |
FALSE | Option not found. |
Definition at line 737 of file BootArguments.c.
VOID OcParseBootArgs | ( | OUT OC_BOOT_ARGUMENTS * | Arguments, |
IN VOID * | BootArgs ) |
Parse macOS kernel into unified boot arguments structure.
[out] | Arguments | Unified boot arguments structure. |
[in] | BootArgs | Kernel boot arguments strucutre. |
Definition at line 43 of file BootArguments.c.
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.
[in] | ParsedVars | Parsed variables. |
[in] | Name | Option name. |
[in] | StrValue | Option 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. |
TRUE | Option exists. |
FALSE | Option not found. |
Definition at line 727 of file BootArguments.c.
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.
[in] | ParsedVars | Parsed variables. |
[in] | Name | Option name. |
[in] | Value | Option value if successful, not modified otherwise. |
[in] | StringFormat | Are option names and values Unicode or ASCII? |
EFI_SUCCESS | Success. |
EFI_NOT_FOUND | Option not found, or has no value. |
other | Error encountered when parsing option as guid. |
Definition at line 785 of file BootArguments.c.
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).
[in] | ParsedVars | Parsed variables. |
[in] | Name | Option name. |
[in] | Value | Option value if successful, not modified otherwise. |
[in] | StringFormat | Are option names and values Unicode or ASCII? |
EFI_SUCCESS | Success. |
EFI_NOT_FOUND | Option not found, or has no value. |
other | Error encountered when parsing option as int. |
Definition at line 749 of file BootArguments.c.
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.
[in] | ParsedVars | Parsed variables. |
[in] | Name | Option name. |
[in] | StrValue | Option 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] | StringFormat | Are option names and values Unicode or ASCII? |
TRUE | Option exists. |
FALSE | Option not found. |
Definition at line 669 of file BootArguments.c.
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.
[in] | ParsedVars | Parsed variables. |
[in] | Name | Option name. |
[in] | StrValue | Option 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. |
TRUE | Option exists. |
FALSE | Option not found. |
Definition at line 717 of file BootArguments.c.
OC_PARSED_VAR * OcParsedVarsItemAt | ( | IN CONST OC_FLEX_ARRAY * | ParsedVars, |
IN CONST UINTN | Index ) |
Return parsed variable at given index.
[in] | ParsedVars | Parsed variables. |
[in] | Index | Index of option to return. |
Parsed | option. |
Definition at line 657 of file BootArguments.c.
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.
[in] | LoadedImage | Loaded image handle. |
[out] | ParsedVars | Parsed load options if successful, NULL otherwise. Caller may free after use with OcFlexArrayFree if required. |
EFI_SUCCESS | Success. |
EFI_NOT_FOUND | Missing or empty load options. |
EFI_OUT_OF_RESOURCES | Out of memory. |
EFI_INVALID_PARAMETER | Invalid load options detected. |
Definition at line 416 of file BootArguments.c.
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.
[in] | StrVars | Raw var string. |
[out] | ParsedVars | Parsed variables if successful, NULL otherwise. Caller may free after use with OcFlexArrayFree. |
[in] | StringFormat | Are option names and values Unicode or ASCII? |
[in] | TokensOnly | If TRUE parse as a sequence of token values only, rather than as a sequence of name[=[value]] pairs. |
EFI_SUCCESS | Success. |
EFI_NOT_FOUND | Missing or empty load options. |
EFI_OUT_OF_RESOURCES | Out of memory. |
EFI_INVALID_PARAMETER | Invalid load options detected. |
Definition at line 449 of file BootArguments.c.
VOID OcRemoveArgumentFromCmd | ( | IN OUT CHAR8 * | CommandLine, |
IN CONST CHAR8 * | Argument ) |
Remove argument from command line if present.
[in,out] | CommandLine | Argument command line, e.g. for boot.efi. |
[in] | Argument | Argument, e.g. -v, slide=, debug=, etc. |
Definition at line 136 of file BootArguments.c.
BOOLEAN EFIAPI OcValidLoadOptions | ( | IN UINT32 | LoadOptionsSize, |
IN CONST VOID * | LoadOptions ) |
Are load options apparently valid (Unicode string or cleanly non-present)?
[in] | LoadOptionsSize | Load options size. |
[in] | LoadOptions | Load options. |
TRUE | if valid. |
Definition at line 384 of file BootArguments.c.