]> git.proxmox.com Git - mirror_edk2.git/blame - ShellPkg/Application/Shell/Shell.h
Add check before use to make code run more safer.
[mirror_edk2.git] / ShellPkg / Application / Shell / Shell.h
CommitLineData
a405b86d 1/** @file\r
2 function definitions for internal to shell functions.\r
3\r
733f138d 4 Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>\r
a405b86d 5 This program and the accompanying materials\r
6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php\r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#ifndef _SHELL_INTERNAL_HEADER_\r
16#define _SHELL_INTERNAL_HEADER_\r
17\r
18#include <Uefi.h>\r
19#include <ShellBase.h>\r
20\r
21#include <Guid/ShellVariableGuid.h>\r
22\r
23#include <Protocol/LoadedImage.h>\r
24#include <Protocol/SimpleTextOut.h>\r
25#include <Protocol/EfiShell.h>\r
26#include <Protocol/EfiShellInterface.h>\r
27#include <Protocol/EfiShellEnvironment2.h>\r
28#include <Protocol/EfiShellParameters.h>\r
29#include <Protocol/BlockIo.h>\r
30\r
31#include <Library/BaseLib.h>\r
32#include <Library/UefiApplicationEntryPoint.h>\r
33#include <Library/UefiLib.h>\r
34#include <Library/DebugLib.h>\r
35#include <Library/MemoryAllocationLib.h>\r
36#include <Library/ShellCommandLib.h>\r
37#include <Library/UefiRuntimeServicesTableLib.h>\r
38#include <Library/UefiBootServicesTableLib.h>\r
39#include <Library/DevicePathLib.h>\r
40#include <Library/BaseMemoryLib.h>\r
41#include <Library/PcdLib.h>\r
42#include <Library/ShellLib.h>\r
43#include <Library/SortLib.h>\r
44#include <Library/HiiLib.h>\r
45#include <Library/PrintLib.h>\r
46#include <Library/HandleParsingLib.h>\r
ab94587a 47#include <Library/PathLib.h>\r
a405b86d 48\r
49#include "ShellParametersProtocol.h"\r
50#include "ShellProtocol.h"\r
51#include "ShellEnvVar.h"\r
52#include "ConsoleLogger.h"\r
53#include "ShellManParser.h"\r
a49f6a2f 54#include "ConsoleWrappers.h"\r
a405b86d 55\r
56typedef struct {\r
57 LIST_ENTRY Link; ///< Standard linked list handler.\r
58 SHELL_FILE_HANDLE *SplitStdOut; ///< ConsoleOut for use in the split.\r
59 SHELL_FILE_HANDLE *SplitStdIn; ///< ConsoleIn for use in the split.\r
60} SPLIT_LIST;\r
61\r
62typedef struct {\r
63 UINT32 Startup:1; ///< Was "-startup" found on command line.\r
64 UINT32 NoStartup:1; ///< Was "-nostartup" found on command line.\r
65 UINT32 NoConsoleOut:1; ///< Was "-noconsoleout" found on command line.\r
66 UINT32 NoConsoleIn:1; ///< Was "-noconsolein" found on command line.\r
67 UINT32 NoInterrupt:1; ///< Was "-nointerrupt" found on command line.\r
68 UINT32 NoMap:1; ///< Was "-nomap" found on command line.\r
69 UINT32 NoVersion:1; ///< Was "-noversion" found on command line.\r
70 UINT32 Delay:1; ///< Was "-delay[:n] found on command line\r
71 UINT32 Reserved:8; ///< Extra bits\r
72} SHELL_BITS;\r
73\r
74typedef union {\r
75 SHELL_BITS Bits;\r
76 UINT16 AllBits;\r
77} SHELL_BIT_UNION;\r
78\r
79typedef struct {\r
80 SHELL_BIT_UNION BitUnion;\r
81 UINTN Delay; ///< Seconds of delay default:5.\r
82 CHAR16 *FileName; ///< Filename to run upon successful initialization.\r
83 CHAR16 *FileOptions; ///< Options to pass to FileName.\r
84} SHELL_INIT_SETTINGS;\r
85\r
86typedef struct {\r
87 BUFFER_LIST CommandHistory;\r
88 UINTN VisibleRowNumber;\r
89 UINTN OriginalVisibleRowNumber;\r
90 BOOLEAN InsertMode; ///< Is the current typing mode insert (FALSE = overwrite).\r
91} SHELL_VIEWING_SETTINGS;\r
92\r
93typedef struct {\r
94 EFI_SHELL_PARAMETERS_PROTOCOL *NewShellParametersProtocol;\r
95 EFI_SHELL_PROTOCOL *NewEfiShellProtocol;\r
96 BOOLEAN PageBreakEnabled;\r
97 BOOLEAN RootShellInstance;\r
98 SHELL_INIT_SETTINGS ShellInitSettings;\r
99 BUFFER_LIST BufferToFreeList; ///< List of buffers that were returned to the user to free.\r
100 SHELL_VIEWING_SETTINGS ViewingSettings;\r
101 EFI_HII_HANDLE HiiHandle; ///< Handle from HiiLib.\r
102 UINTN LogScreenCount; ///< How many screens of log information to save.\r
103 EFI_EVENT UserBreakTimer; ///< Timer event for polling for CTRL-C.\r
104 EFI_DEVICE_PATH_PROTOCOL *ImageDevPath; ///< DevicePath for ourselves.\r
105 EFI_DEVICE_PATH_PROTOCOL *FileDevPath; ///< DevicePath for ourselves.\r
106 CONSOLE_LOGGER_PRIVATE_DATA *ConsoleInfo; ///< Pointer for ConsoleInformation.\r
107 EFI_SHELL_PARAMETERS_PROTOCOL *OldShellParameters; ///< old shell parameters to reinstall upon exiting.\r
108 SHELL_PROTOCOL_HANDLE_LIST OldShellList; ///< List of other instances to reinstall when closing.\r
109 SPLIT_LIST SplitList; ///< List of Splits in FILO stack.\r
8be0ba36 110 EFI_HANDLE CtrlCNotifyHandle1; ///< The NotifyHandle returned from SimpleTextInputEx.RegisterKeyNotify.\r
111 EFI_HANDLE CtrlCNotifyHandle2; ///< The NotifyHandle returned from SimpleTextInputEx.RegisterKeyNotify.\r
112 EFI_HANDLE CtrlCNotifyHandle3; ///< The NotifyHandle returned from SimpleTextInputEx.RegisterKeyNotify.\r
113 EFI_HANDLE CtrlCNotifyHandle4; ///< The NotifyHandle returned from SimpleTextInputEx.RegisterKeyNotify.\r
733f138d 114 EFI_HANDLE CtrlSNotifyHandle1; ///< The NotifyHandle returned from SimpleTextInputEx.RegisterKeyNotify.\r
115 EFI_HANDLE CtrlSNotifyHandle2; ///< The NotifyHandle returned from SimpleTextInputEx.RegisterKeyNotify.\r
116 EFI_HANDLE CtrlSNotifyHandle3; ///< The NotifyHandle returned from SimpleTextInputEx.RegisterKeyNotify.\r
117 EFI_HANDLE CtrlSNotifyHandle4; ///< The NotifyHandle returned from SimpleTextInputEx.RegisterKeyNotify.\r
a49f6a2f 118 BOOLEAN HaltOutput; ///< TRUE to start a CTRL-S halt.\r
a405b86d 119} SHELL_INFO;\r
120\r
121extern SHELL_INFO ShellInfoObject;\r
122\r
123/**\r
124 Sets all the alias' that were registered with the ShellCommandLib library.\r
125\r
126 @retval EFI_SUCCESS all init commands were run sucessfully.\r
127**/\r
128EFI_STATUS\r
129EFIAPI\r
130SetBuiltInAlias(\r
131 VOID\r
132 );\r
133\r
134/**\r
135 This function will populate the 2 device path protocol parameters based on the\r
136 global gImageHandle. the DevPath will point to the device path for the handle that has\r
137 loaded image protocol installed on it. the FilePath will point to the device path\r
138 for the file that was loaded.\r
139\r
140 @param[in,out] DevPath on a sucessful return the device path to the loaded image\r
141 @param[in,out] FilePath on a sucessful return the device path to the file\r
142\r
143 @retval EFI_SUCCESS the 2 device paths were sucessfully returned.\r
144 @return other a error from gBS->HandleProtocol\r
145\r
146 @sa HandleProtocol\r
147**/\r
148EFI_STATUS\r
149EFIAPI\r
150GetDevicePathsForImageAndFile (\r
151 IN OUT EFI_DEVICE_PATH_PROTOCOL **DevPath,\r
152 IN OUT EFI_DEVICE_PATH_PROTOCOL **FilePath\r
153 );\r
154\r
155/**\r
156 Process all Uefi Shell 2.0 command line options.\r
157\r
158 see Uefi Shell 2.0 section 3.2 for full details.\r
159\r
160 the command line should resemble the following:\r
161\r
162 shell.efi [ShellOpt-options] [options] [file-name [file-name-options]]\r
163\r
164 ShellOpt options Options which control the initialization behavior of the shell.\r
165 These options are read from the EFI global variable "ShellOpt"\r
166 and are processed before options or file-name.\r
167\r
168 options Options which control the initialization behavior of the shell.\r
169\r
170 file-name The name of a UEFI shell application or script to be executed\r
171 after initialization is complete. By default, if file-name is\r
172 specified, then -nostartup is implied. Scripts are not supported\r
173 by level 0.\r
174\r
175 file-nameoptions The command-line options that are passed to file-name when it\r
176 is invoked.\r
177\r
178 This will initialize the ShellInitSettings global variable.\r
179\r
180 @retval EFI_SUCCESS the variable is initialized.\r
181**/\r
182EFI_STATUS\r
183EFIAPI\r
184ProcessCommandLine(\r
185 VOID\r
186 );\r
187\r
188/**\r
189 Handles all interaction with the default startup script.\r
190\r
191 this will check that the correct command line parameters were passed, handle the delay, and then start running the script.\r
192\r
193 @param[in] ImagePath The path to the image for shell. The first place to look for the startup script.\r
194 @param[in] FilePath The path to the file for shell. The second place to look for the startup script.\r
195\r
196 @retval EFI_SUCCESS The variable is initialized.\r
197**/\r
198EFI_STATUS\r
199EFIAPI\r
200DoStartupScript(\r
201 IN EFI_DEVICE_PATH_PROTOCOL *ImagePath,\r
202 IN EFI_DEVICE_PATH_PROTOCOL *FilePath\r
203 );\r
204\r
205/**\r
206 Function to perform the shell prompt looping. It will do a single prompt,\r
207 dispatch the result, and then return. It is expected that the caller will\r
208 call this function in a loop many times.\r
209\r
210 @retval EFI_SUCCESS\r
211 @retval RETURN_ABORTED\r
212**/\r
213EFI_STATUS\r
214EFIAPI\r
215DoShellPrompt (\r
216 VOID\r
217 );\r
218\r
219/**\r
220 Add a buffer to the Buffer To Free List for safely returning buffers to other\r
221 places without risking letting them modify internal shell information.\r
222\r
223 @param Buffer Something to pass to FreePool when the shell is exiting.\r
224**/\r
225VOID*\r
226EFIAPI\r
227AddBufferToFreeList(\r
228 VOID *Buffer\r
229 );\r
230\r
231/**\r
232 Add a buffer to the Command History List.\r
233\r
234 @param Buffer[in] The line buffer to add.\r
235**/\r
236VOID\r
237EFIAPI\r
238AddLineToCommandHistory(\r
239 IN CONST CHAR16 *Buffer\r
240 );\r
241\r
242/**\r
243 Function will process and run a command line.\r
244\r
245 This will determine if the command line represents an internal shell command or dispatch an external application.\r
246\r
247 @param[in] CmdLine the command line to parse\r
248\r
249 @retval EFI_SUCCESS the command was completed\r
250 @retval EFI_ABORTED the command's operation was aborted\r
251**/\r
252EFI_STATUS\r
253EFIAPI\r
254RunCommand(\r
255 IN CONST CHAR16 *CmdLine\r
256 );\r
257\r
258/**\r
259 Function determins if the CommandName COULD be a valid command. It does not determine whether\r
260 this is a valid command. It only checks for invalid characters.\r
261\r
262 @param[in] CommandName The name to check\r
263\r
264 @retval TRUE CommandName could be a command name\r
265 @retval FALSE CommandName could not be a valid command name\r
266**/\r
267BOOLEAN\r
268EFIAPI\r
269IsValidCommandName(\r
270 IN CONST CHAR16 *CommandName\r
271 );\r
272\r
273/**\r
274 Function to process a NSH script file via SHELL_FILE_HANDLE.\r
275\r
276 @param[in] Handle The handle to the already opened file.\r
277 @param[in] Name The name of the script file.\r
278\r
279 @retval EFI_SUCCESS the script completed sucessfully\r
280**/\r
281EFI_STATUS\r
282EFIAPI\r
283RunScriptFileHandle (\r
284 IN SHELL_FILE_HANDLE Handle,\r
285 IN CONST CHAR16 *Name\r
286 );\r
287\r
288/**\r
289 Function to process a NSH script file.\r
290\r
291 @param[in] ScriptPath Pointer to the script file name (including file system path).\r
292\r
293 @retval EFI_SUCCESS the script completed sucessfully\r
294**/\r
295EFI_STATUS\r
296EFIAPI\r
297RunScriptFile (\r
298 IN CONST CHAR16 *ScriptPath\r
299 );\r
300\r
301\r
302#endif //_SHELL_INTERNAL_HEADER_\r
303\r