Skip to content

Conversation

@DHowett-MSFT
Copy link
Contributor

Summary of the Pull Request

This pull request introduces a copy of the code from kernel32.dll that implements CreatePseudoConsole, ClosePseudoConsole and ResizePseudoConsole. Apart from some light modifications to fit into the infrastructure in this project and support launching OpenConsole.exe, it is intended to be 1:1 with the code that ships in Windows.

Any guideline violations in this code are likely intentional. Since this was built into kernel32, it used the STL only very sparingly.

kernel32 is on the default link line, so we need to figure out how to get included before it. Either that, or we should export different function names.

References

#1130

PR Checklist

  • Closes #xxx
  • Tests added/passed
  • Requires documentation to be updated
  • I've discussed this with core contributors already.

Validation Steps Performed

Launched vtpipeterm.

@DHowett-MSFT DHowett-MSFT requested a review from miniksa August 30, 2019 00:09
<ClCompile Include="precomp.cpp">
<PrecompiledHeader>Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="../server/DeviceHandle.cpp" />
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not great, but necessary to avoid duplicating code.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eh, good enough.

@fcharlie
Copy link
Contributor

This PR is great. Regarding the export function with the same name as kernel32, my suggestion is that since the conpty code is not long, you can turn it into an implementation of header only. Then isolate it with a namespace.

@driver1998
Copy link

If we are taking it out from Windows, will it be possible to backport ConPTY to earlier version of Windows?

@fcharlie
Copy link
Contributor

@driver1998 I think it depends on conhost.exe. In this code, we can see that this is essentially conhost running in PTY mode, so the porting of conpty to the old Windows is based on the premise that the new version of conhost.exe can be used on older Windows. run. Having said that, the problem of porting the new conhost.exe to the old Windows may need to consider factors such as graphics and kernel console handles.

@Biswa96
Copy link

Biswa96 commented Aug 31, 2019

will it be possible to backport ConPTY to earlier version of Windows?

Also it depends on the CreateProcess() because a process uses PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE flag for ConPTY. And the actual kernel mode driver ConDrv.sys.

  • Some queries:

    • Is not this code proprietary (kernelbase.dll)?
    • Will this code be somewhat stable among future Windows OS versions?

@DHowett-MSFT
Copy link
Contributor Author

DHowett-MSFT commented Sep 3, 2019

@Biswa96

  • The code was proprietary, but we're open-sourcing it as it's a minimal facade around code you can already find in other parts of this repository.
  • condrv is not involved in establishing a pseudoconsole session.
  • It will only remain stable to the extent that it needs to. As two examples:
    • the signal pipe is an implementation detail
    • the only thing that will need to remain stable between this repository's version and the OS version is the position of the reference handle in the HPCON.
    • we reserve the right to change the internal conpty interface at any point within our compatibility guarantee.

Copy link
Member

@zadjii-msft zadjii-msft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple questions. Additionally:

  • should we also push the tests for this out?

#pragma warning(push)
#pragma warning(disable : 4273) // inconsistent dll linkage (we are exporting things kernel32 also exports)

extern "C" __declspec(dllexport) wchar_t* _ConsoleHostPath()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe needs a doc comment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't mean to export it, but yes, a doc comment would be good

// These functions are defined in the console l1 apiset, which is generated from
// the consoleapi.apx file in minkernel\apiset\libs\Console.

HRESULT CreatePseudoConsoleAsUser(_In_ HANDLE hToken,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did we ever make this public before? I guess we're not __declspec(dllexport)ing it from this dll, so probably nbd.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not public in win32, but also not harmful. 😄

@Biswa96
Copy link

Biswa96 commented Sep 3, 2019

  • Is it possible to add STDERR instead of STDOUT in siEx.StartupInfo.hStdError parameter?
  • Is it possible to make the write pipe handle inheritable also so that child process can change conpty size?

@zadjii-msft
Copy link
Member

@Biswa96 I don't really want to make any code changes in this PR. This PR should exists solely as a port from OS code to OSS code. We can handle feature requests for the conpty API in their own separate issues.

@DHowett-MSFT
Copy link
Contributor Author

@Biswa96

  1. There is no meaningful error output from the pseudoconsole host process.
  2. Why? There is already a better API for resizing the console in SetConsoleScreenBufferInfo, which wouldn’t require us to expose an implementation detail to a child process.

<ClCompile Include="precomp.cpp">
<PrecompiledHeader>Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="../server/DeviceHandle.cpp" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eh, good enough.

@DHowett-MSFT DHowett-MSFT merged commit e0762f6 into master Sep 4, 2019
@DHowett-MSFT DHowett-MSFT deleted the dev/duhowett/winconpty branch September 4, 2019 19:03
@Biswa96
Copy link

Biswa96 commented Nov 2, 2019

Will it be possible to add a option or flag not to append --headless option in the conhost.exe command line? Because without the --headless option, the hidden conhost window shows raw buffer. It may be useful for future debugging to normal users.

@miniksa
Copy link
Member

miniksa commented Nov 4, 2019

Will it be possible to add a option or flag not to append --headless option in the conhost.exe command line? Because without the --headless option, the hidden conhost window shows raw buffer . It may be useful for future debugging to normal users.

We're not planning on adding debugging options like that to the actual public-facing API or DLL. It is a valid debugging scenario to just launch the conhost yourself manually passing the PTY handles and without the flag if you want to see the hidden window for debugging. I believe the vtpipeterm.exe tool in our project has the potential to do that for debugging purposes.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants