terminal/src/server
Dustin L. Howett fb3d772615
Convert DeviceComm into an interface and add handle exchange (#8367)
This commit replaces DeviceComm with the interface IDeviceComm and the
concrete implementation type ConDrvDeviceComm. This work is done in
preparation for different device backends.

In addition to separating out ConDrv-specific behavior, I've introduced
a "handle exchange" interface.

HANDLE EXCHANGE
---------------

There are points where we give ConDrv opaque handle identifiers to our
input buffer, output buffer and process data. The exact content of the
opaque identifier is meaningless to ConDrv: the driver's only
interaction with these identifiers is to hold onto them and send back
whichever are pertinent for each API call.

Because of that, we used the raw register-width pointer value of the
input buffer, output buffer or process data _as_ the opaque handle
value.

This works very well for ConDrv <-> conhost using the ConDrvDeviceComm.
It works less well for something like the "logging" DeviceComm that will
log packets to a file: those packets *cannot* contain pointer values (!)

To address this, and to afford flexibility to DeviceComm implementers,
I've introduced a two-member complement of handle management functions:

* `ULONG_PTR PutHandle(void*)` registers an object with the DeviceComm
  and returns an opaque identifier.
* `void* GetHandle(ULONG_PTR)` takes an opaque identifier and returns
  the original object.

ConDrvDeviceComm implements PutHandle and GetHandle by casting the
object pointer to the "opaque handle value", which maintains wire format
compatibility[1] with revisions of conhost prior to this change.

Simpler DeviceComm implementations that require handle tracking but
cannot bear raw pointers can implement these functions by returning an
autoincrementing ID (or similar) and registering the raw object pointer
in a mapping.

I've audited all existing handle exchanges with the driver and updated
them to use Put/GetHandle.

(I intended to add DestroyHandle, but we are not equipped for handle
removal at the moment. ConsoleHandleData/ConsoleProcessHandle are
destroyed during wait routine completion, on client disconnect, etc.
This does mean that an id<->pointer mapping will grow without bound, but
at a cost of ~8 bytes per entry and a short-lived console session I am
not too concerned about the cost.)

[1] Wire format compatibility is not required, and later we may want to
switch ConDrvDeviceComm to `EncodePointer` and `DecodePointer` just to
insulate us against a spurious ConDrv packet allowing for an arbitrary
4/8-byte read and subsequent liftoff into space.
2020-12-15 23:07:43 +00:00
..
lib Convert DeviceComm into an interface and add handle exchange (#8367) 2020-12-15 23:07:43 +00:00
ApiDispatchers.cpp Replace basic_string_view<T> with span<const T> (#6921) 2020-07-15 16:40:42 +00:00
ApiDispatchers.h Initial release of the Windows Terminal source code 2019-05-02 15:29:04 -07:00
ApiDispatchersInternal.cpp Change backslashes in include statements to forward slashes (#8205) 2020-11-25 21:02:10 +00:00
ApiMessage.cpp Convert DeviceComm into an interface and add handle exchange (#8367) 2020-12-15 23:07:43 +00:00
ApiMessage.h Convert DeviceComm into an interface and add handle exchange (#8367) 2020-12-15 23:07:43 +00:00
ApiMessageState.cpp add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
ApiMessageState.h add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
ApiSorter.cpp add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
ApiSorter.h add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
ConDrvDeviceComm.cpp Convert DeviceComm into an interface and add handle exchange (#8367) 2020-12-15 23:07:43 +00:00
ConDrvDeviceComm.h Convert DeviceComm into an interface and add handle exchange (#8367) 2020-12-15 23:07:43 +00:00
ConsoleShimPolicy.cpp Reintroduce a color compatibility hack, but only for PowerShells (#6810) 2020-07-10 15:25:39 -07:00
ConsoleShimPolicy.h Reintroduce a color compatibility hack, but only for PowerShells (#6810) 2020-07-10 15:25:39 -07:00
DeviceComm.h Convert DeviceComm into an interface and add handle exchange (#8367) 2020-12-15 23:07:43 +00:00
DeviceHandle.cpp Apply audit mode to TerminalConnection/Core/Settings and WinCon… (#4016) 2020-01-03 10:44:27 -08:00
DeviceHandle.h add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
dirs Initial release of the Windows Terminal source code 2019-05-02 15:29:04 -07:00
Entrypoints.cpp Change NULL to nullptr since they are pointers (#4960) 2020-03-20 20:35:12 +00:00
Entrypoints.h add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
IApiRoutines.h Replace basic_string_view<T> with span<const T> (#6921) 2020-07-15 16:40:42 +00:00
IoDispatchers.cpp Convert DeviceComm into an interface and add handle exchange (#8367) 2020-12-15 23:07:43 +00:00
IoDispatchers.h Initial release of the Windows Terminal source code 2019-05-02 15:29:04 -07:00
IoSorter.cpp Change backslashes in include statements to forward slashes (#8205) 2020-11-25 21:02:10 +00:00
IoSorter.h Initial release of the Windows Terminal source code 2019-05-02 15:29:04 -07:00
IoThread.h add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
IWaitRoutine.h add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
ObjectHandle.cpp Change backslashes in include statements to forward slashes (#8205) 2020-11-25 21:02:10 +00:00
ObjectHandle.h Prevent cleanup of object given to handle that failed access check (#3414) 2019-11-05 14:22:55 -08:00
ObjectHeader.cpp Change backslashes in include statements to forward slashes (#8205) 2020-11-25 21:02:10 +00:00
ObjectHeader.h Prevent cleanup of object given to handle that failed access check (#3414) 2019-11-05 14:22:55 -08:00
precomp.cpp Initial release of the Windows Terminal source code 2019-05-02 15:29:04 -07:00
precomp.h Change backslashes in include statements to forward slashes (#8205) 2020-11-25 21:02:10 +00:00
ProcessHandle.cpp Convert DeviceComm into an interface and add handle exchange (#8367) 2020-12-15 23:07:43 +00:00
ProcessHandle.h Convert DeviceComm into an interface and add handle exchange (#8367) 2020-12-15 23:07:43 +00:00
ProcessList.cpp Change backslashes in include statements to forward slashes (#8205) 2020-11-25 21:02:10 +00:00
ProcessList.h Revert locking changes (#3488) 2019-11-08 13:44:52 -08:00
ProcessPolicy.cpp Change backslashes in include statements to forward slashes (#8205) 2020-11-25 21:02:10 +00:00
ProcessPolicy.h Initial release of the Windows Terminal source code 2019-05-02 15:29:04 -07:00
sources.inc Convert DeviceComm into an interface and add handle exchange (#8367) 2020-12-15 23:07:43 +00:00
WaitBlock.cpp Change backslashes in include statements to forward slashes (#8205) 2020-11-25 21:02:10 +00:00
WaitBlock.h Change backslashes in include statements to forward slashes (#8205) 2020-11-25 21:02:10 +00:00
WaitQueue.cpp Change backslashes in include statements to forward slashes (#8205) 2020-11-25 21:02:10 +00:00
WaitQueue.h Change backslashes in include statements to forward slashes (#8205) 2020-11-25 21:02:10 +00:00
WaitTerminationReason.h Initial release of the Windows Terminal source code 2019-05-02 15:29:04 -07:00
winbasep.h add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
WinNTControl.cpp Apply audit mode to TerminalConnection/Core/Settings and WinCon… (#4016) 2020-01-03 10:44:27 -08:00
WinNTControl.h Apply audit mode to TerminalConnection/Core/Settings and WinCon… (#4016) 2020-01-03 10:44:27 -08:00