Skip to content

Selected apphost is not a valid PE file on s390x #92344

Description

@omajid

Using a .NET 8 RC 1 SDK compiled on s390x with #90292 applied locally, dotnet tool install -g dotnet-ef fails:

    $ dotnet tool install -g dotnet-ef
    Unhandled exception: Microsoft.NET.HostModel.AppHost.AppHostNotPEFileException: Selected apphost is not a valid PE file. Subsystem offset out of file range.
       at Microsoft.NET.HostModel.AppHost.PEUtils.GetWindowsGraphicalUserInterfaceBit(MemoryMappedViewAccessor accessor)
       at Microsoft.NET.HostModel.AppHost.PEUtils.GetWindowsGraphicalUserInterfaceBit(String filePath)
       at Microsoft.DotNet.ShellShim.AppHostShellShimMaker.CreateApphostShellShim(FilePath entryPoint, FilePath shimPath)
       at Microsoft.DotNet.ShellShim.ShellShimRepository.<>c__DisplayClass5_0.<CreateShim>b__0()
       at Microsoft.DotNet.Cli.TransactionalAction.<>c__DisplayClass5_0.<Run>b__0()
       at Microsoft.DotNet.Cli.TransactionalAction.Run[Object](Func`1 action, Action commit, Action rollback)
       at Microsoft.DotNet.Cli.TransactionalAction.Run(Action action, Action commit, Action rollback)
       at Microsoft.DotNet.ShellShim.ShellShimRepository.CreateShim(FilePath targetExecutablePath, ToolCommandName commandName, IReadOnlyList`1 packagedShims)
       at Microsoft.DotNet.Tools.Tool.Install.ToolInstallGlobalOrToolPathCommand.Execute()
       at Microsoft.DotNet.Tools.Tool.Install.ToolInstallCommand.Execute()
       at Microsoft.DotNet.Cli.ToolInstallCommandParser.<>c.<ConstructCommand>b__17_0(ParseResult parseResult)
       at System.CommandLine.Invocation.AnonymousCliAction.Invoke(ParseResult parseResult)
       at System.CommandLine.Invocation.InvocationPipeline.Invoke(ParseResult parseResult)
       at System.CommandLine.ParseResult.Invoke()
       at Microsoft.DotNet.Cli.Program.ProcessArgs(String[] args, TimeSpan startupTime, ITelemetry telemetryClient)

The stack trace suggests this is the culprit:

internal static unsafe ushort GetWindowsGraphicalUserInterfaceBit(MemoryMappedViewAccessor accessor)
{
byte* pointer = null;
try
{
accessor.SafeMemoryMappedViewHandle.AcquirePointer(ref pointer);
byte* bytes = pointer + accessor.PointerOffset;
// https://en.wikipedia.org/wiki/Portable_Executable
uint peHeaderOffset = ((uint*)(bytes + PEOffsets.DosStub.PESignatureOffset))[0];
if (accessor.Capacity < peHeaderOffset + PEOffsets.PEHeader.Subsystem + sizeof(ushort))
{
throw new AppHostNotPEFileException("Subsystem offset out of file range.");
}
ushort* subsystem = ((ushort*)(bytes + peHeaderOffset + PEOffsets.PEHeader.Subsystem));
return subsystem[0];
}
finally
{
if (pointer != null)
{
accessor.SafeMemoryMappedViewHandle.ReleasePointer();
}
}
}

Probably an endianness issue?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    arch-s390xRelated to s390x architecture (unsupported)

    Type

    No type

    Projects

    • Status
      No status

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions