]> git.proxmox.com Git - mirror_edk2.git/blame - ShellPkg/Application/Shell/Shell.h
MdeModulePkg/UsbBusDxe: Fix memory leak
[mirror_edk2.git] / ShellPkg / Application / Shell / Shell.h
CommitLineData
a405b86d 1/** @file\r
2 function definitions for internal to shell functions.\r
3\r
c011b6c9 4 (C) Copyright 2014 Hewlett-Packard Development Company, L.P.<BR>\r
00534bc3 5 Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>\r
a405b86d 6 This program and the accompanying materials\r
7 are licensed and made available under the terms and conditions of the BSD License\r
8 which accompanies this distribution. The full text of the license may be found at\r
9 http://opensource.org/licenses/bsd-license.php\r
10\r
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
14**/\r
15\r
16#ifndef _SHELL_INTERNAL_HEADER_\r
17#define _SHELL_INTERNAL_HEADER_\r
18\r
19#include <Uefi.h>\r
20#include <ShellBase.h>\r
21\r
22#include <Guid/ShellVariableGuid.h>\r
0406a571 23#include <Guid/ShellAliasGuid.h>\r
a405b86d 24\r
25#include <Protocol/LoadedImage.h>\r
26#include <Protocol/SimpleTextOut.h>\r
27#include <Protocol/EfiShell.h>\r
28#include <Protocol/EfiShellInterface.h>\r
29#include <Protocol/EfiShellEnvironment2.h>\r
30#include <Protocol/EfiShellParameters.h>\r
31#include <Protocol/BlockIo.h>\r
32\r
33#include <Library/BaseLib.h>\r
34#include <Library/UefiApplicationEntryPoint.h>\r
35#include <Library/UefiLib.h>\r
36#include <Library/DebugLib.h>\r
37#include <Library/MemoryAllocationLib.h>\r
38#include <Library/ShellCommandLib.h>\r
39#include <Library/UefiRuntimeServicesTableLib.h>\r
40#include <Library/UefiBootServicesTableLib.h>\r
41#include <Library/DevicePathLib.h>\r
42#include <Library/BaseMemoryLib.h>\r
43#include <Library/PcdLib.h>\r
44#include <Library/ShellLib.h>\r
45#include <Library/SortLib.h>\r
46#include <Library/HiiLib.h>\r
47#include <Library/PrintLib.h>\r
48#include <Library/HandleParsingLib.h>\r
0406a571 49#include <Library/FileHandleLib.h>\r
a405b86d 50\r
51#include "ShellParametersProtocol.h"\r
52#include "ShellProtocol.h"\r
53#include "ShellEnvVar.h"\r
54#include "ConsoleLogger.h"\r
55#include "ShellManParser.h"\r
a49f6a2f 56#include "ConsoleWrappers.h"\r
0406a571 57#include "FileHandleWrappers.h"\r
a405b86d 58\r
59typedef struct {\r
60 LIST_ENTRY Link; ///< Standard linked list handler.\r
61 SHELL_FILE_HANDLE *SplitStdOut; ///< ConsoleOut for use in the split.\r
62 SHELL_FILE_HANDLE *SplitStdIn; ///< ConsoleIn for use in the split.\r
63} SPLIT_LIST;\r
64\r
65typedef struct {\r
66 UINT32 Startup:1; ///< Was "-startup" found on command line.\r
67 UINT32 NoStartup:1; ///< Was "-nostartup" found on command line.\r
68 UINT32 NoConsoleOut:1; ///< Was "-noconsoleout" found on command line.\r
69 UINT32 NoConsoleIn:1; ///< Was "-noconsolein" found on command line.\r
70 UINT32 NoInterrupt:1; ///< Was "-nointerrupt" found on command line.\r
71 UINT32 NoMap:1; ///< Was "-nomap" found on command line.\r
72 UINT32 NoVersion:1; ///< Was "-noversion" found on command line.\r
73 UINT32 Delay:1; ///< Was "-delay[:n] found on command line\r
ca79c798 74 UINT32 Exit:1; ///< Was "-_exit" found on command line\r
75 UINT32 Reserved:7; ///< Extra bits\r
a405b86d 76} SHELL_BITS;\r
77\r
78typedef union {\r
79 SHELL_BITS Bits;\r
80 UINT16 AllBits;\r
81} SHELL_BIT_UNION;\r
82\r
83typedef struct {\r
84 SHELL_BIT_UNION BitUnion;\r
85 UINTN Delay; ///< Seconds of delay default:5.\r
86 CHAR16 *FileName; ///< Filename to run upon successful initialization.\r
87 CHAR16 *FileOptions; ///< Options to pass to FileName.\r
88} SHELL_INIT_SETTINGS;\r
89\r
90typedef struct {\r
91 BUFFER_LIST CommandHistory;\r
92 UINTN VisibleRowNumber;\r
93 UINTN OriginalVisibleRowNumber;\r
94 BOOLEAN InsertMode; ///< Is the current typing mode insert (FALSE = overwrite).\r
95} SHELL_VIEWING_SETTINGS;\r
96\r
97typedef struct {\r
98 EFI_SHELL_PARAMETERS_PROTOCOL *NewShellParametersProtocol;\r
838b31a6 99 EFI_SHELL_PROTOCOL *NewEfiShellProtocol;\r
a405b86d 100 BOOLEAN PageBreakEnabled;\r
101 BOOLEAN RootShellInstance;\r
102 SHELL_INIT_SETTINGS ShellInitSettings;\r
103 BUFFER_LIST BufferToFreeList; ///< List of buffers that were returned to the user to free.\r
104 SHELL_VIEWING_SETTINGS ViewingSettings;\r
105 EFI_HII_HANDLE HiiHandle; ///< Handle from HiiLib.\r
106 UINTN LogScreenCount; ///< How many screens of log information to save.\r
107 EFI_EVENT UserBreakTimer; ///< Timer event for polling for CTRL-C.\r
108 EFI_DEVICE_PATH_PROTOCOL *ImageDevPath; ///< DevicePath for ourselves.\r
109 EFI_DEVICE_PATH_PROTOCOL *FileDevPath; ///< DevicePath for ourselves.\r
110 CONSOLE_LOGGER_PRIVATE_DATA *ConsoleInfo; ///< Pointer for ConsoleInformation.\r
111 EFI_SHELL_PARAMETERS_PROTOCOL *OldShellParameters; ///< old shell parameters to reinstall upon exiting.\r
112 SHELL_PROTOCOL_HANDLE_LIST OldShellList; ///< List of other instances to reinstall when closing.\r
113 SPLIT_LIST SplitList; ///< List of Splits in FILO stack.\r
402e4a9d
RN
114 VOID *CtrlCNotifyHandle1; ///< The NotifyHandle returned from SimpleTextInputEx.RegisterKeyNotify.\r
115 VOID *CtrlCNotifyHandle2; ///< The NotifyHandle returned from SimpleTextInputEx.RegisterKeyNotify.\r
116 VOID *CtrlCNotifyHandle3; ///< The NotifyHandle returned from SimpleTextInputEx.RegisterKeyNotify.\r
117 VOID *CtrlCNotifyHandle4; ///< The NotifyHandle returned from SimpleTextInputEx.RegisterKeyNotify.\r
118 VOID *CtrlSNotifyHandle1; ///< The NotifyHandle returned from SimpleTextInputEx.RegisterKeyNotify.\r
119 VOID *CtrlSNotifyHandle2; ///< The NotifyHandle returned from SimpleTextInputEx.RegisterKeyNotify.\r
120 VOID *CtrlSNotifyHandle3; ///< The NotifyHandle returned from SimpleTextInputEx.RegisterKeyNotify.\r
121 VOID *CtrlSNotifyHandle4; ///< The NotifyHandle returned from SimpleTextInputEx.RegisterKeyNotify.\r
a49f6a2f 122 BOOLEAN HaltOutput; ///< TRUE to start a CTRL-S halt.\r
a405b86d 123} SHELL_INFO;\r
124\r
125extern SHELL_INFO ShellInfoObject;\r
126\r
6bd64463
JC
127/**\r
128 Converts the command line to it's post-processed form. this replaces variables and alias' per UEFI Shell spec.\r
129\r
130 @param[in,out] CmdLine pointer to the command line to update\r
131\r
132 @retval EFI_SUCCESS The operation was successful\r
133 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.\r
d08a5464 134 @return some other error occurred\r
6bd64463
JC
135**/\r
136EFI_STATUS\r
137EFIAPI\r
138ProcessCommandLineToFinal(\r
139 IN OUT CHAR16 **CmdLine\r
140 );\r
141\r
142/**\r
51429264 143 Function to update the shell variable "lasterror".\r
6bd64463
JC
144\r
145 @param[in] ErrorCode the error code to put into lasterror\r
146**/\r
147EFI_STATUS\r
148EFIAPI\r
149SetLastError(\r
150 IN CONST SHELL_STATUS ErrorCode\r
151 );\r
152\r
a405b86d 153/**\r
154 Sets all the alias' that were registered with the ShellCommandLib library.\r
155\r
d08a5464 156 @retval EFI_SUCCESS all init commands were run successfully.\r
a405b86d 157**/\r
158EFI_STATUS\r
159EFIAPI\r
160SetBuiltInAlias(\r
161 VOID\r
162 );\r
163\r
164/**\r
165 This function will populate the 2 device path protocol parameters based on the\r
166 global gImageHandle. the DevPath will point to the device path for the handle that has\r
167 loaded image protocol installed on it. the FilePath will point to the device path\r
168 for the file that was loaded.\r
169\r
d08a5464
JP
170 @param[in, out] DevPath on a successful return the device path to the loaded image\r
171 @param[in, out] FilePath on a successful return the device path to the file\r
a405b86d 172\r
d08a5464 173 @retval EFI_SUCCESS the 2 device paths were successfully returned.\r
a405b86d 174 @return other a error from gBS->HandleProtocol\r
175\r
176 @sa HandleProtocol\r
177**/\r
178EFI_STATUS\r
179EFIAPI\r
180GetDevicePathsForImageAndFile (\r
181 IN OUT EFI_DEVICE_PATH_PROTOCOL **DevPath,\r
182 IN OUT EFI_DEVICE_PATH_PROTOCOL **FilePath\r
183 );\r
184\r
185/**\r
186 Process all Uefi Shell 2.0 command line options.\r
187\r
188 see Uefi Shell 2.0 section 3.2 for full details.\r
189\r
190 the command line should resemble the following:\r
191\r
192 shell.efi [ShellOpt-options] [options] [file-name [file-name-options]]\r
193\r
194 ShellOpt options Options which control the initialization behavior of the shell.\r
195 These options are read from the EFI global variable "ShellOpt"\r
196 and are processed before options or file-name.\r
197\r
198 options Options which control the initialization behavior of the shell.\r
199\r
200 file-name The name of a UEFI shell application or script to be executed\r
201 after initialization is complete. By default, if file-name is\r
202 specified, then -nostartup is implied. Scripts are not supported\r
203 by level 0.\r
204\r
205 file-nameoptions The command-line options that are passed to file-name when it\r
206 is invoked.\r
207\r
208 This will initialize the ShellInitSettings global variable.\r
209\r
210 @retval EFI_SUCCESS the variable is initialized.\r
211**/\r
212EFI_STATUS\r
213EFIAPI\r
214ProcessCommandLine(\r
215 VOID\r
216 );\r
217\r
218/**\r
219 Handles all interaction with the default startup script.\r
220\r
221 this will check that the correct command line parameters were passed, handle the delay, and then start running the script.\r
222\r
223 @param[in] ImagePath The path to the image for shell. The first place to look for the startup script.\r
224 @param[in] FilePath The path to the file for shell. The second place to look for the startup script.\r
225\r
226 @retval EFI_SUCCESS The variable is initialized.\r
227**/\r
228EFI_STATUS\r
229EFIAPI\r
230DoStartupScript(\r
a308e058
RN
231 IN EFI_DEVICE_PATH_PROTOCOL *ImagePath,\r
232 IN EFI_DEVICE_PATH_PROTOCOL *FilePath\r
a405b86d 233 );\r
234\r
235/**\r
236 Function to perform the shell prompt looping. It will do a single prompt,\r
237 dispatch the result, and then return. It is expected that the caller will\r
238 call this function in a loop many times.\r
239\r
240 @retval EFI_SUCCESS\r
241 @retval RETURN_ABORTED\r
242**/\r
243EFI_STATUS\r
244EFIAPI\r
245DoShellPrompt (\r
246 VOID\r
247 );\r
248\r
249/**\r
250 Add a buffer to the Buffer To Free List for safely returning buffers to other\r
251 places without risking letting them modify internal shell information.\r
252\r
253 @param Buffer Something to pass to FreePool when the shell is exiting.\r
254**/\r
255VOID*\r
256EFIAPI\r
257AddBufferToFreeList(\r
258 VOID *Buffer\r
259 );\r
260\r
261/**\r
262 Add a buffer to the Command History List.\r
263\r
264 @param Buffer[in] The line buffer to add.\r
265**/\r
266VOID\r
267EFIAPI\r
268AddLineToCommandHistory(\r
269 IN CONST CHAR16 *Buffer\r
270 );\r
271\r
272/**\r
273 Function will process and run a command line.\r
274\r
275 This will determine if the command line represents an internal shell command or dispatch an external application.\r
276\r
a308e058 277 @param[in] CmdLine the command line to parse\r
a405b86d 278\r
279 @retval EFI_SUCCESS the command was completed\r
280 @retval EFI_ABORTED the command's operation was aborted\r
281**/\r
282EFI_STATUS\r
283EFIAPI\r
284RunCommand(\r
a308e058 285 IN CONST CHAR16 *CmdLine\r
a405b86d 286 );\r
287\r
490ce43d
QS
288/**\r
289 Function will process and run a command line.\r
290\r
291 This will determine if the command line represents an internal shell \r
292 command or dispatch an external application.\r
293\r
294 @param[in] CmdLine The command line to parse.\r
295 @param[out] CommandStatus The status from the command line.\r
296\r
297 @retval EFI_SUCCESS The command was completed.\r
298 @retval EFI_ABORTED The command's operation was aborted.\r
299**/\r
300EFI_STATUS\r
301EFIAPI\r
302RunShellCommand(\r
303 IN CONST CHAR16 *CmdLine,\r
304 OUT EFI_STATUS *CommandStatus\r
305 );\r
306\r
a405b86d 307/**\r
d08a5464 308 Function determines if the CommandName COULD be a valid command. It does not determine whether\r
a405b86d 309 this is a valid command. It only checks for invalid characters.\r
310\r
311 @param[in] CommandName The name to check\r
312\r
313 @retval TRUE CommandName could be a command name\r
314 @retval FALSE CommandName could not be a valid command name\r
315**/\r
316BOOLEAN\r
317EFIAPI\r
318IsValidCommandName(\r
319 IN CONST CHAR16 *CommandName\r
320 );\r
321\r
322/**\r
323 Function to process a NSH script file via SHELL_FILE_HANDLE.\r
324\r
325 @param[in] Handle The handle to the already opened file.\r
326 @param[in] Name The name of the script file.\r
327\r
d08a5464 328 @retval EFI_SUCCESS the script completed successfully\r
a405b86d 329**/\r
330EFI_STATUS\r
331EFIAPI\r
332RunScriptFileHandle (\r
a308e058
RN
333 IN SHELL_FILE_HANDLE Handle,\r
334 IN CONST CHAR16 *Name\r
a405b86d 335 );\r
336\r
337/**\r
338 Function to process a NSH script file.\r
339\r
340 @param[in] ScriptPath Pointer to the script file name (including file system path).\r
e958b946
JC
341 @param[in] Handle the handle of the script file already opened.\r
342 @param[in] CmdLine the command line to run.\r
343 @param[in] ParamProtocol the shell parameters protocol pointer\r
a405b86d 344\r
d08a5464 345 @retval EFI_SUCCESS the script completed successfully\r
a405b86d 346**/\r
347EFI_STATUS\r
348EFIAPI\r
349RunScriptFile (\r
a308e058
RN
350 IN CONST CHAR16 *ScriptPath,\r
351 IN SHELL_FILE_HANDLE Handle OPTIONAL,\r
352 IN CONST CHAR16 *CmdLine,\r
353 IN EFI_SHELL_PARAMETERS_PROTOCOL *ParamProtocol\r
a405b86d 354 );\r
355\r
00534bc3 356/**\r
d08a5464 357 Return the pointer to the first occurrence of any character from a list of characters.\r
00534bc3
JC
358\r
359 @param[in] String the string to parse\r
360 @param[in] CharacterList the list of character to look for\r
361 @param[in] EscapeCharacter An escape character to skip\r
362\r
363 @return the location of the first character in the string\r
364 @retval CHAR_NULL no instance of any character in CharacterList was found in String\r
365**/\r
366CONST CHAR16*\r
367EFIAPI\r
368FindFirstCharacter(\r
369 IN CONST CHAR16 *String,\r
370 IN CONST CHAR16 *CharacterList,\r
371 IN CONST CHAR16 EscapeCharacter\r
372 );\r
a308e058 373\r
389824ff
QS
374/**\r
375 Cleans off leading and trailing spaces and tabs.\r
376\r
377 @param[in] String pointer to the string to trim them off.\r
378**/\r
379EFI_STATUS\r
380EFIAPI\r
381TrimSpaces(\r
382 IN CHAR16 **String\r
383 );\r
384\r
14810d6b
QS
385/**\r
386 \r
387 Create a new buffer list and stores the old one to OldBufferList \r
388\r
389 @param OldBufferList The temporary list head used to store the nodes in BufferToFreeList.\r
390**/\r
391VOID\r
392SaveBufferList (\r
393 OUT LIST_ENTRY *OldBufferList\r
394 );\r
395\r
396/**\r
397 Restore previous nodes into BufferToFreeList .\r
398\r
399 @param OldBufferList The temporary list head used to store the nodes in BufferToFreeList.\r
400**/\r
401VOID\r
402RestoreBufferList (\r
403 IN OUT LIST_ENTRY *OldBufferList\r
404 );\r
405\r
406\r
407\r
a405b86d 408#endif //_SHELL_INTERNAL_HEADER_\r
409\r