Hi

I am not accessing it from my app, i am fixing a bug in udk2014.

My app is only calling ShellExecute.

Try it yourself in helloworld, im sure if you call shellexecute in an efi shell 
1.0 it will crash

--- Original Message ---

From: "Andrew Fish" <[email protected]>
Sent: 23 September 2014 2:05 AM
To: [email protected]
Subject: Re: [edk2] ShellExecute crashing in NT emulator - [Bug Found]


On Sep 21, 2014, at 11:01 PM, J. E. <[email protected]> wrote:

> I found the problem!
>
> *ParentHandle should not have the pointer in it.
> Removing the '*' solved the problem.
>
> ShellExecute now works fine in the Emulator and on an actual UEFI machine 
> (Which I assume is booting the EFI Shell, not the new UEFI 2.0 shell, hence 
> why it is choosing mEfiShellEnvironment2).
>
>
> Original code:
>
>     //
>     // Call EFI Shell version.
>     // Due to oddity in the EFI shell we want to dereference the ParentHandle 
> here
>     //
>     CmdStatus = (mEfiShellEnvironment2->Execute(*ParentHandle,
>                                           CommandLine,
>                                           Output));
>
> Change to:
>
>     CmdStatus = (mEfiShellEnvironment2->Execute(ParentHandle,
>                                           CommandLine,
>                                           Output));
>
>
> I don't know if changing this will break on earlier EFI Shells / machines, 
> perhaps there needs to be code added to check if the pointer is needed or not.
>

It will always break on the older shell, and could break at any time on the 
current shell.

mEfiShellEvnironment2 is a private global that is part of the implementation of 
the library. You should NOT be accessing it! You should not look at the 
implementation of the library and copy globals out of it, or call internal 
functions.

The public APIs are defined in the library class .h file, and this is what you 
should code against. 
https://svn.code.sf.net/p/edk2/code/trunk/edk2/ShellPkg/Include/Library/ShellLib.h

Thanks,

Andrew Fish



> Thanks Andrew and Tim for your help.
>
>
> From: [email protected]
> To: [email protected]
> Date: Mon, 22 Sep 2014 11:45:04 +1000
> Subject: Re: [edk2] ShellExecute crashing in NT emulator
>
> I figured out how to run UefiShellExecute using gEfiShellProtocol->Execute() 
> by taking the code from ShellExecute() shown below.
> But gEfiShellProtocol is NULL in the NT32 Emulator and on a UEFI 2.4 machine.
>
>
>   // Check for UEFI Shell 2.0 protocols
> mEfiShellEnvironment2 = NULL
> gEfiShellProtocol->Execute() = stack crash because gEfiShellProtocol is NULL
>
>   // Check for EFI shell
> mEfiShellEnvironment2 = OK
> mEfiShellEnvironment2->Execute() = Freezes application in the proper EFI 
> shell, or crashes NT32 emulator.
>
>
> Q. Do I need to initialize UEFI Shell 2.0 first, so mEfiShellEnvironment2 is 
> not NULL? Or is my app actually running in the EFI Shell, not the UEFI 2.0 
> shell?
>
> If I type ver in the shell, it shows me:
> EFI Specification Revision: 2.40
> EFI Vendor: INSYDE Corp.
> EFI Revision: 21521.32
>
> That is a UEFI 2.0 Shell right?
> So why is mEfiShellEnvironment2 NULL?
>
>
> EFI_STATUS
> EFIAPI
> ShellExecute (
>   IN EFI_HANDLE                 *ParentHandle,
>   IN CHAR16                     *CommandLine OPTIONAL,
>   IN BOOLEAN                    Output OPTIONAL,
>   IN CHAR16                     **EnvironmentVariables OPTIONAL,
>   OUT EFI_STATUS                *Status OPTIONAL
>   )
> {
>   EFI_STATUS                CmdStatus;
>   //
>   // Check for UEFI Shell 2.0 protocols
>   //
>   if (gEfiShellProtocol != NULL) {
>     //
>     // Call UEFI Shell 2.0 version (not using Output parameter)
>     //
>     Print(L"gEfiShellProtocol->Execute..\n");
>     return (gEfiShellProtocol->Execute(ParentHandle,
>                                       CommandLine,
>                                       EnvironmentVariables,
>                                       Status));
>   }
>
>   //
>   // Check for EFI shell
>   //
>
>   if (mEfiShellEnvironment2 != NULL) {
>     //
>     // Call EFI Shell version.
>     // Due to oddity in the EFI shell we want to dereference the ParentHandle 
> here
>     //
>     Print(L"mEfiShellEnvironment2->Execute..\n");
>     CmdStatus = (mEfiShellEnvironment2->Execute(*ParentHandle,
>                                           CommandLine,
>                                           Output));
>     //
>     // No Status output parameter so just use the returned status
>     //
>     if (Status != NULL) {
>       *Status = CmdStatus;
>     }
>     //
>     // If there was an error, we can't tell if it was from the command or from
>     // the Execute() function, so we'll just assume the shell ran successfully
>     // and the error came from the command.
>     //
>     return EFI_SUCCESS;
>   }
>
>   return (EFI_UNSUPPORTED);
> }
>
> From: [email protected]
> To: [email protected]
> Date: Mon, 22 Sep 2014 10:54:11 +1000
> Subject: Re: [edk2] ShellExecute crashing in NT emulator
>
> I think you are on to something, I am using UEFI not the EDK shell. That 
> would explain why ShellExecute is crashing.
>
> I'm seeing a compile error though:
> Error LNK2001: unresolved external symbol _EfiShellExecute
>
> I tried including various header files and libraries but I'm not sure if the 
> below references are correct.
> There are no sample apps that use EfiShellExecute and google came up with 
> nothing so I'm at a bit of a loss on how to reference EfiShellExecute into my 
> app correctly.
>
>
> Project H File
> #include <Protocol/EfiShell.h>
> -----------------
> Project INF File
> [LibraryClasses]
> UefiShellLib
> -----------------
> MdeModulePkg.dsc
> [LibraryClasses]
>   UefiShellLib|ShellPkg\Library\UefiShellLib/UefiShellLib.inf
>
>
>
> From: [email protected]
> To: [email protected]
> Date: Fri, 19 Sep 2014 16:30:18 +0000
> Subject: Re: [edk2] ShellExecute crashing in NT emulator
>
> It appears you are using the EDK Shell (not the UEFI shell) since you are 
> using ShellEnvironment2. Is that your intention?
>
> In the UEFI shell, this would be ShellPkg/Include/Protocol/EfiShell.h and the 
> corresponding function is:
>
> typedef
> EFI_STATUS
> (EFIAPI *EFI_SHELL_EXECUTE) (
>   IN EFI_HANDLE                 *ParentImageHandle,
>   IN CHAR16                     *CommandLine OPTIONAL,
>   IN CHAR16                     **Environment OPTIONAL,
>   OUT EFI_STATUS                *StatusCode OPTIONAL
>   );
>
> Tim
>
> From: J. E. [mailto:[email protected]]
> Sent: Thursday, September 18, 2014 10:22 PM
> To: [email protected]
> Subject: Re: [edk2] ShellExecute crashing in NT emulator
>
> Yep thats the first thing I did, search all of UDK for SHELLENV_GET_ENV using 
> Agent Ransack which searches binary and unicode as well.
> I found nothing except for the EfiShellEnvironment2.h and UefiShellLib.lib 
> files.
> No idea where SHELLENV_GET_ENV is defined, it doesnt make sense.
>
> If I boot and run the app in the proper EFI Shell, ShellExecute doesn't hang, 
> but execution fails. Status is always EFI_SUCCESS
> The echo commands in the NSH file do not output text onscreen, and the efi 
> file in the NSH doesn't launch.
>
>     Status = ShellExecute(ImageHandle, L"fs1:", TRUE, NULL, NULL);
>     Status = ShellExecute(ImageHandle, L"cd fs1:\\TEST", TRUE, NULL, NULL);
>     Status = ShellExecute(ImageHandle, L"run.nsh", TRUE, NULL, NULL);
>
> The above commands work fine if I type them in manually in the EFI shell.
> ShellExecute just seems broken, I can find the code so I cant debug it. 
> Everything compiles ok.
> Maybe I should download the latest source instead of using the UDK2014 
> release, or change the compiler to GCC or Intel.
> From: [email protected]
> Date: Thu, 18 Sep 2014 18:48:25 -0700
> To: [email protected]
> Subject: Re: [edk2] ShellExecute crashing in NT emulator
>
>
> Sent from my iPhone
>
> On Sep 18, 2014, at 6:01 PM, J. E. <[email protected]> wrote:
> It is crashing in SHELLENV_EXECUTE but I cant seem to find the c source for 
> this function in
> UDK\ShellPkg\Include\Protocol\EfiShellEnvironment2.h
>
> typedef
> EFI_STATUS
> (EFIAPI *SHELLENV_EXECUTE) (
>   IN EFI_HANDLE   *ParentImageHandle,
>   IN CHAR16       *CommandLine,
>   IN BOOLEAN      DebugOutput
>   );
>
> Which c file has the actual source code?
>
> For protocols look at the global, EFI_GUID. Grep for that global. The 
> producer will pass it as an argument to install protocol boot service.
>
> Thanks,
>
> Andrew Fish
>
>
>
> From: [email protected]
> Date: Thu, 18 Sep 2014 16:38:51 -0700
> To: [email protected]
> Subject: Re: [edk2] ShellExecute crashing in NT emulator
>
> On Sep 18, 2014, at 4:24 PM, J. E. <[email protected]> wrote:
>
> I am compiling and running secmain from the command line with no debugger, 
> compiler is VS2005.
> Perhaps there is a way to dump the exception to file?
>
> Not sure as I don’t use VC++.
>
> It happens in Windows 7 64 as well.
>
> I'll see if I can debug the ShellExecute function directly to find out which 
> line is crashing out
>
> Look at: http://tianocore.sourceforge.net/wiki/NT32
>
> Thanks,
>
> Andrew Fish
>
> From: [email protected]
> Date: Thu, 18 Sep 2014 10:25:30 -0700
> To: [email protected]
> Subject: Re: [edk2] ShellExecute crashing in NT emulator
>
> On Sep 18, 2014, at 6:22 AM, J. E. <[email protected]> wrote:
>
> The below code is crashing the emulator, any ideas?
>
> Do you get a stack trace and error messages from the crash?
>
> Thanks,
>
> Andrew Fish
>
> Is it a Windows 8 thing? (can't test a Win7 system or via proper EFI shell 
> right now)
>
>
> EFI_STATUS
> EFIAPI
> UefiMain (
>   IN EFI_HANDLE        ImageHandle,
>   IN EFI_SYSTEM_TABLE  *SystemTable
>   )
> {
>     EFI_STATUS Status;
>     Status = ShellExecute(ImageHandle, L"startup.nsh", FALSE, NULL, NULL);   
> // Crash dxecore.dll
>     Status = ShellExecute(ImageHandle, NULL, FALSE, NULL, NULL); // Crash 
> dxecore.dll
>
> }
>
>
> UDK2014
> Win8.1 64bit
> UEFI Mode
>
>
>
> ------------------------------------------------------------------------------
> Want excitement?
> Manually upgrade your production database.
> When you want reliability, choose Perforce
> Perforce version control. Predictably reliable.
> http://pubads.g.doubleclick.net/gampad/clk?id=157508191&iu=/4140/ostg.clktrk_______________________________________________
> edk2-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/edk2-devel
>
>
> ------------------------------------------------------------------------------
>  Slashdot TV. Video for Nerds. Stuff that Matters. 
> http://pubads.g.doubleclick.net/gampad/clk?id=160591471&iu=/4140/ostg.clktrk
> _______________________________________________ edk2-devel mailing list 
> [email protected] 
> https://lists.sourceforge.net/lists/listinfo/edk2-devel
> ------------------------------------------------------------------------------
> Slashdot TV.  Video for Nerds.  Stuff that Matters.
> http://pubads.g.doubleclick.net/gampad/clk?id=160591471&iu=/4140/ostg.clktrk_______________________________________________
> edk2-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/edk2-devel
>
>
> ------------------------------------------------------------------------------
>  Slashdot TV. Video for Nerds. Stuff that 
> Matters.http://pubads.g.doubleclick.net/gampad/clk?id=160591471&iu=/4140/ostg.clktrk
> _______________________________________________ edk2-devel mailing list 
> [email protected]https://lists.sourceforge.net/lists/listinfo/edk2-devel
> ------------------------------------------------------------------------------
> Slashdot TV.  Video for Nerds.  Stuff that Matters.
> http://pubads.g.doubleclick.net/gampad/clk?id=160591471&iu=/4140/ostg.clktrk
> _______________________________________________
> edk2-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/edk2-devel
>
> ------------------------------------------------------------------------------
>  Slashdot TV. Video for Nerds. Stuff that 
> Matters.http://pubads.g.doubleclick.net/gampad/clk?id=160591471&iu=/4140/ostg.clktrk
> _______________________________________________ edk2-devel mailing list 
> [email protected]https://lists.sourceforge.net/lists/listinfo/edk2-devel
>
> ------------------------------------------------------------------------------
>  Slashdot TV. Video for Nerds. Stuff that 
> Matters.http://pubads.g.doubleclick.net/gampad/clk?id=160591471&iu=/4140/ostg.clktrk
> _______________________________________________ edk2-devel mailing list 
> [email protected]https://lists.sourceforge.net/lists/listinfo/edk2-devel
>
> ------------------------------------------------------------------------------
>  Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer Achieve PCI 
> DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports Are you 
> Audit-Ready for PCI DSS 3.0 Compliance? Download White paper Comply to PCI 
> DSS 3.0 Requirement 10 and 11.5 with EventLog 
> Analyzerhttp://pubads.g.doubleclick.net/gampad/clk?id=154622311&iu=/4140/ostg.clktrk
> _______________________________________________ edk2-devel mailing list 
> [email protected]https://lists.sourceforge.net/lists/listinfo/edk2-devel
>
> ------------------------------------------------------------------------------
>  Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer Achieve PCI 
> DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports Are you 
> Audit-Ready for PCI DSS 3.0 Compliance? Download White paper Comply to PCI 
> DSS 3.0 Requirement 10 and 11.5 with EventLog 
> Analyzerhttp://pubads.g.doubleclick.net/gampad/clk?id=154622311&iu=/4140/ostg.clktrk
> _______________________________________________ edk2-devel mailing list 
> [email protected]https://lists.sourceforge.net/lists/listinfo/edk2-devel
> ------------------------------------------------------------------------------
> Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer
> Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports
> Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper
> Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer
> http://pubads.g.doubleclick.net/gampad/clk?id=154622311&iu=/4140/ostg.clktrk_______________________________________________
> edk2-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/edk2-devel

------------------------------------------------------------------------------
Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer
Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports
Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper
Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer
http://pubads.g.doubleclick.net/gampad/clk?id=154622311&iu=/4140/ostg.clktrk
_______________________________________________
edk2-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-devel
------------------------------------------------------------------------------
Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer
Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports
Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper
Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer
http://pubads.g.doubleclick.net/gampad/clk?id=154622311&iu=/4140/ostg.clktrk
_______________________________________________
edk2-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-devel

Reply via email to