]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ShellPkg: Eliminate loss of high bits in return value from exit command on 64 bit...
authorjcarsey <jcarsey@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 15 Sep 2011 20:10:39 +0000 (20:10 +0000)
committerjcarsey <jcarsey@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 15 Sep 2011 20:10:39 +0000 (20:10 +0000)
submitted-by: jcarsey
reviewed-by:  gookboy15a
reviewed-by:  niruiyu

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@12356 6f19259b-4bc3-4df7-8a09-765794883524

ShellPkg/Application/Shell/Shell.c
ShellPkg/Include/Library/ShellCommandLib.h
ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c
ShellPkg/Library/UefiShellLevel1CommandsLib/Exit.c
ShellPkg/Library/UefiShellLevel3CommandsLib/Pause.c

index 3a5899f342ee989f9683e731e96f11a931078ea9..614c1e9595d3d02132750a1c3550a82c02db47d8 100644 (file)
@@ -475,6 +475,9 @@ UefiMain (
     DEBUG_CODE(ShellInfoObject.ConsoleInfo = NULL;);\r
   }\r
 \r
+  if (ShellCommandGetExit()) {\r
+    return ((EFI_STATUS)ShellCommandGetExitCode());\r
+  }\r
   return (Status);\r
 }\r
 \r
@@ -1622,6 +1625,7 @@ RunScriptFileHandle (
   BOOLEAN             PreCommandEchoState;\r
   CONST CHAR16        *CurDir;\r
   UINTN               LineCount;\r
+  CHAR16              LeString[50];\r
 \r
   ASSERT(!ShellCommandGetScriptExit());\r
 \r
@@ -1826,7 +1830,11 @@ RunScriptFileHandle (
         }\r
 \r
         if (ShellCommandGetScriptExit()) {\r
-          ShellCommandRegisterExit(FALSE);\r
+          UnicodeSPrint(LeString, sizeof(LeString)*sizeof(LeString[0]), L"0x%Lx", ShellCommandGetExitCode());\r
+          DEBUG_CODE(InternalEfiShellSetEnv(L"DebugLasterror", LeString, TRUE););\r
+          InternalEfiShellSetEnv(L"Lasterror", LeString, TRUE);\r
+\r
+          ShellCommandRegisterExit(FALSE, 0);\r
           Status = EFI_SUCCESS;\r
           break;\r
         }\r
index f453d22f3d8e12fdc39fa481f1bc9dbc8f50cf4b..0f4f503410f4474fbab4647f3483fff0b58b8ac0 100644 (file)
@@ -340,11 +340,24 @@ ShellCommandSetEchoState (
   Indicate that the current shell or script should exit.\r
 \r
   @param[in] ScriptOnly   TRUE if exiting a script; FALSE otherwise.\r
+  @param[in] ErrorCode    The 64 bit error code to return.\r
 **/\r
 VOID\r
 EFIAPI\r
 ShellCommandRegisterExit (\r
-  IN BOOLEAN ScriptOnly\r
+  IN BOOLEAN      ScriptOnly,\r
+  IN CONST UINT64 ErrorCode\r
+  );\r
+\r
+/**\r
+  Retrieve the Exit code.\r
+\r
+  @return the value passed into RegisterExit.\r
+**/\r
+UINT64\r
+EFIAPI\r
+ShellCommandGetExitCode (\r
+  VOID\r
   );\r
 \r
 /**\r
index 2c1dcd3c1308f59a43a69ff576611e4dcdc90daf..971294ffd44c26ddb5a788770003b9fe4ad7c2f8 100644 (file)
@@ -26,6 +26,7 @@ STATIC SCRIPT_FILE_LIST                   mScriptList;
 STATIC ALIAS_LIST                         mAliasList;\r
 STATIC BOOLEAN                            mEchoState;\r
 STATIC BOOLEAN                            mExitRequested;\r
+STATIC UINT64                             mExitCode;\r
 STATIC BOOLEAN                            mExitScript;\r
 STATIC CHAR16                             *mProfileList;\r
 STATIC UINTN                              mProfileListSize;\r
@@ -697,12 +698,14 @@ ShellCommandSetEchoState(
 /**\r
   Indicate that the current shell or script should exit.\r
 \r
-  @param[in] ScriptOnly   TRUE if only exiting a script, FALSE othrwise.\r
+  @param[in] ScriptOnly   TRUE if exiting a script; FALSE otherwise.\r
+  @param[in] ErrorCode    The 64 bit error code to return.\r
 **/\r
 VOID\r
 EFIAPI\r
 ShellCommandRegisterExit (\r
-  IN BOOLEAN ScriptOnly\r
+  IN BOOLEAN      ScriptOnly,\r
+  IN CONST UINT64 ErrorCode\r
   )\r
 {\r
   mExitRequested = (BOOLEAN)(!mExitRequested);\r
@@ -711,6 +714,7 @@ ShellCommandRegisterExit (
   } else {\r
     mExitScript    = FALSE;\r
   }\r
+  mExitCode = ErrorCode;\r
 }\r
 \r
 /**\r
@@ -728,6 +732,21 @@ ShellCommandGetExit (
   return (mExitRequested);\r
 }\r
 \r
+/**\r
+  Retrieve the Exit code.\r
+\r
+  If ShellCommandGetExit returns FALSE than the return from this is undefined.\r
+\r
+  @return the value passed into RegisterExit.\r
+**/\r
+UINT64\r
+EFIAPI\r
+ShellCommandGetExitCode (\r
+  VOID\r
+  )\r
+{\r
+  return (mExitCode);\r
+}\r
 /**\r
   Retrieve the Exit script indicator.\r
 \r
index 5620d023b1223ac05e32d5a9bc330343ce137a8b..3a3c59fa0396eed88f65d4066309a78c3c4c5ddb 100644 (file)
@@ -77,16 +77,16 @@ ShellCommandRunExit (
         //\r
         // If we are in a batch file and /b then pass TRUE otherwise false...\r
         //\r
-        ShellCommandRegisterExit((BOOLEAN)(gEfiShellProtocol->BatchIsActive() && ShellCommandLineGetFlag(Package, L"/b")));\r
+        ShellCommandRegisterExit((BOOLEAN)(gEfiShellProtocol->BatchIsActive() && ShellCommandLineGetFlag(Package, L"/b")), RetVal);\r
 \r
-        ShellStatus = (SHELL_STATUS)(RetVal);\r
+        ShellStatus = SHELL_SUCCESS;\r
       }\r
     } else {\r
       // If we are in a batch file and /b then pass TRUE otherwise false...\r
       //\r
-      ShellCommandRegisterExit((BOOLEAN)(gEfiShellProtocol->BatchIsActive() && ShellCommandLineGetFlag(Package, L"/b")));\r
+      ShellCommandRegisterExit((BOOLEAN)(gEfiShellProtocol->BatchIsActive() && ShellCommandLineGetFlag(Package, L"/b")), 0);\r
 \r
-      ShellStatus = (SHELL_STATUS)0;\r
+      ShellStatus = SHELL_SUCCESS;\r
     }\r
 \r
     ShellCommandLineFreeVarList (Package);\r
index d6ed793579d430edce72be83f33fbc59e339d41b..bedd591c0de9ecd68826b9e2e7a7d0f3eaa43a3b 100644 (file)
@@ -84,7 +84,7 @@ ShellCommandRunPause (
       }\r
 \r
       if (EFI_ERROR(Status) || Resp == NULL || *Resp == ShellPromptResponseQuit) {\r
-        ShellCommandRegisterExit(TRUE);\r
+        ShellCommandRegisterExit(TRUE, 0);\r
         ShellStatus = SHELL_ABORTED;\r
       }\r
 \r