Repository navigation
Closed
Labels
Resolution-FixedThe issue is fixed.
Description
Prerequisites
- Write a descriptive title.
- Make sure you are able to repro it on the latest released version
- Search the existing issues.
- Refer to the FAQ.
- Refer to Differences between Windows PowerShell 5.1 and PowerShell.
Steps to reproduce
- Install PowerShell 7.3.0 x86 on a Windows x64 system.
- Start
pwsh.exe.
No previous version of PowerShell 7 behaved in this way.
Expected behavior
PowerShell 7.3.0
PS C:\Users\Me>Actual behavior
PowerShell 7.3.0
Fatal error. 0xC0000005
at System.Management.Automation.Security.SystemPolicy+WldpNativeMethods.WldpCanExecuteFile(System.Guid, WLDP_EXECUTION_EVALUATION_OPTIONS, IntPtr, System.String, WLDP_EXECUTION_POLICY ByRef)
at System.Management.Automation.Security.SystemPolicy.GetFilePolicyEnforcement(System.String, System.IO.FileStream)
at System.Management.Automation.ExternalScriptInfo.ReadScriptContents()
at System.Management.Automation.ExternalScriptInfo.get_ScriptBlock()
at Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadModuleManifestData(System.Management.Automation.ExternalScriptInfo, System.String[], ManifestProcessingFlags, Boolean ByRef)
at Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadModuleManifestData(System.Management.Automation.ExternalScriptInfo, ManifestProcessingFlags, System.Collections.Hashtable ByRef, System.Collections.Hashtable ByRef, Boolean ByRef)
at Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadModule(System.Management.Automation.PSModuleInfo, System.String, System.String, System.String, System.Management.Automation.SessionState, System.Object, ImportModuleOptions ByRef, ManifestProcessingFlags, Boolean ByRef, Boolean ByRef)
at Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadUsingExtensions(System.Management.Automation.PSModuleInfo, System.String, System.String, System.String, System.String, System.String, System.Management.Automation.SessionState, ImportModuleOptions, ManifestProcessingFlags, Boolean ByRef, Boolean ByRef)
at Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadUsingModulePath(System.Management.Automation.PSModuleInfo, System.Collections.Generic.IEnumerable`1<System.String>, System.String, System.Management.Automation.SessionState, ImportModuleOptions, ManifestProcessingFlags, System.Management.Automation.PSModuleInfo ByRef)
at Microsoft.PowerShell.Commands.ImportModuleCommand.ImportModule_LocallyViaName(ImportModuleOptions, System.String)
at Microsoft.PowerShell.Commands.ImportModuleCommand.ImportModule_LocallyViaName_WithTelemetry(ImportModuleOptions, System.String)
at Microsoft.PowerShell.Commands.ImportModuleCommand.ProcessRecord()
at System.Management.Automation.Cmdlet.DoProcessRecord()
at System.Management.Automation.CommandProcessor.ProcessRecord()
at System.Management.Automation.CommandProcessorBase.DoExecute()
at System.Management.Automation.Internal.PipelineProcessor.Inject(System.Object, Boolean)
at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(System.Object)
at System.Management.Automation.Runspaces.LocalPipeline.InvokeHelper()
at System.Management.Automation.Runspaces.LocalPipeline.InvokeThreadProc()
at System.Management.Automation.Runspaces.LocalPipeline.InvokeThreadProcImpersonate()
at System.Management.Automation.Runspaces.PipelineThread.WorkerProc()
at System.Threading.Thread+StartHelper.Callback(System.Object)
at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
at System.Threading.Thread.StartCallback()Error details
No response
Environment data
Not available because PowerShell crashes on startup.Visuals
No response
Metadata
Metadata
Assignees
Labels
Resolution-FixedThe issue is fixed.
Activity
chrullrich commentedon Nov 13, 2022
I have looked for a statement on whether using the x86 version of PS on an x64 platform is supported, but could not find any.
rhubarb-geek-nz commentedon Nov 13, 2022
A few questions..
ZIP,MSIor some other way?MSIdid you add it to the globalPATH?x64version installed?pwsh.exe, from oldpowershell, from start menu or from 32bit or 64bitcmd.exe?I have just installed the PowerShell-7.3.0-win-x86.msi on Windows 10 Pro 22H2 and that installs in
"C:\\Program Files (x86)\\PowerShell\7". That system also has the 64 bit version installed.I did not check the box to add to the global PATH, or any other option.
I ran it from 64 bit
cmd.exeaftercdinto"C:\\Program Files (x86)\\PowerShell\7", and it started cleanly and now sits waiting at the prompt.chrullrich commentedon Nov 13, 2022
Sometimes I'm too impatient when writing bug reports.
Reproduction:
cdto the directory just extracted.pwsh.exe.The crash happens both with my regular cluttered PATH and with
PATH=C:\windows\system32;C:\windows, and when starting it from another directory with an absolute path on the command line. It also happens with the MSI installed the same way you describe (same path, same no options), both from command prompt and start menu. Installing the MSI had no effect on the behavior of the copy I unzipped earlier. It also happens when run from an elevated "real" command prompt window.I noticed that the delay, both before the first line of output and between the last line of the stack trace and the return of the prompt, is much shorter with the MSI (<< 1 s start, 1.5 s finish) than with the Zip (~2.5 s start, ~6 s finish).
Hope that's better :-)
rhubarb-geek-nz commentedon Nov 13, 2022
Does the 64-bit version from a zip work on your system? Given the CPU requirements for Windows 11, are there any x86 only Windows 11 installations?
chrullrich commentedon Nov 13, 2022
rhubarb-geek-nz commentedon Nov 13, 2022
I just tried the 7.3.0 x86 zip on my Windows 11 Pro 22H2 and that throws exactly the same exception as you describe.
chrullrich commentedon Nov 13, 2022
The function it crashes in only exists in 11 22H2. That at least explains why it works on 10. Procmon shows no obvious smoking gun, not that I expected one.
chrullrich commentedon Nov 13, 2022
If I had to guess, I would guess that https://github.com/PowerShell/PowerShell/blob/master/src/System.Management.Automation/security/wldpNativeMethods.cs#L699 should be "ref Guid". But what do I know?
rhubarb-geek-nz commentedon Nov 13, 2022
https://learn.microsoft.com/en-us/previous-versions/troubleshoot/visualstudio/foxpro/c0000005-error-troubleshoot
https://learn.microsoft.com/en-us/windows/win32/api/wldp/nf-wldp-wldpcanexecutefile
Does the export
WldpCanExecuteFileexist in the x86wldp.dll?chrullrich commentedon Nov 13, 2022
The code at the call site (line 120 of the same file I linked above; I hope it's the right one) catches
EntryPointNotFoundExceptionand continues with "legacy system checks".chrullrich commentedon Nov 13, 2022
Adding
[MarshalAs(UnmanagedType.LPStruct)]to the Guid argument (refdoes not work here) fixes the crash when building the v7.3.0 tag. I'm getting unrelated compiler errors from themasterbranch. Whether this is the correct fix is beyond me.I can create a PR for adding the attribute, but I cannot be held responsible for it ...
rhubarb-geek-nz commentedon Nov 13, 2022
So how does the 64 bit code work if it goes through the same code path?
chrullrich commentedon Nov 13, 2022
Calling conventions.
Per
wldp.hthe first argument is aREFGUID, also known as aGUID*. The Windows x64 calling convention says that values larger than 64 bits (that is, larger than a register) are passed by address (i.e. as pointers). This means that in C# terms,Guidandref Guidlook the same to the called native function (but I think in the non-refcase the Guid is probably copied somewhere in case the native function changes it).The x86 calling conventions, in this case
__stdcall, are more complicated. Here, structures (such as Guid) are passed on the stack, that is, the compiler copies the structure to the stack instead of just pushing a pointer to it. This also means that the function will mistake the last four bytes of the GUID as a pointer to one, dereference it, and ... boom. I tried it from C, and this is exactly what happens.My fix tells .NET to pass the Guid as a pointer to a structure, and the fact that this changes the behavior at all is the best proof that it is correct: If it works when passing a pointer, then it must not have been passing one before, and that is definitely wrong because we know the function expects a
REFGUID.Also note that a few lines down in the file, the declaration of
SHGetKnownFolderPath()already uses the attribute, and that function's first argument is aREFKNOWNFOLDERID, another alternative spelling ofGUID*.Now that I have convinced myself of that (and you, I hope), my next problem is how to create a PR for the fix if I cannot get
masterto build for testing.For illustration, this is a call to
WldpCanExecuteFile(REFGUID, int, int, int, int)(the exact types don't matter):This is
WldpCanExecuteFile(GUID, 0, 0, 0, 0):chrullrich commentedon Nov 13, 2022
I just found that
masterworks on another system (no idea why). There,Start-PSBuild -Runtime win7-x86 -Configuration Debugitself fails with the same error when it calls its own just-builtpwsh.exesomewhere along the way. This probably just means that the "official" release was created on something other than 11 22H2.3 remaining items
rhubarb-geek-nz commentedon Nov 13, 2022
Does 7.2.7 work?
chrullrich commentedon Nov 13, 2022
Yes, 7.2.7 works. It does not contain this particular bug anyway, that was introduced between v7.3.0-preview.3 and .4 according to git.
flawrist commentedon Nov 13, 2022
rhubarb-geek-nz, not sure if you asked me or Christian, so let me reply as well.
Yes, 7.2.7 launches fine. Upgraded from 7.2.5 successfully. Thanks for mentioning it.
Edit.
However I am not happy as it advises me to upgrade to 7.3.0 on every launch.
Too intrusive, not to mention that very build is not that stable after all.
chrullrich commentedon Nov 13, 2022
sergeevabc It can be turned off by setting an environment variable:
POWERSHELL_UPDATECHECK=OffSource: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_update_notifications?view=powershell-7.2
iSazonov commentedon Nov 14, 2022
It is Windows 10.
Fix native access violation (#18545) (#18547)
Fix native access violation (#18545)
Fix native access violation (PowerShell#18545) (PowerShell#18547)