Skip to content

Commit

Permalink
ha it works.
Browse files Browse the repository at this point in the history
  • Loading branch information
miniksa committed Aug 6, 2020
1 parent 075be44 commit b5054c8
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 17 deletions.
3 changes: 2 additions & 1 deletion OpenConsole.sln
Expand Up @@ -12,6 +12,7 @@ Project("{C7167F0D-BC9F-4E6E-AFE1-012C56B48DB5}") = "CascadiaPackage", "src\casc
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Host.EXE", "src\host\exe\Host.EXE.vcxproj", "{9CBD7DFA-1754-4A9D-93D7-857A9D17CB1B}"
ProjectSection(ProjectDependencies) = postProject
{E437B604-3E98-4F40-A927-E173E818EA4B} = {E437B604-3E98-4F40-A927-E173E818EA4B}
{0CF235BD-2DA0-407E-90EE-C467E8BBC714} = {0CF235BD-2DA0-407E-90EE-C467E8BBC714}
EndProjectSection
EndProject
Expand Down Expand Up @@ -87,8 +88,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Host.Tests.Feature", "src\h
ProjectSection(ProjectDependencies) = postProject
{18D09A24-8240-42D6-8CB6-236EEE820263} = {18D09A24-8240-42D6-8CB6-236EEE820263}
{FC802440-AD6A-4919-8F2C-7701F2B38D79} = {FC802440-AD6A-4919-8F2C-7701F2B38D79}
{9CBD7DFA-1754-4A9D-93D7-857A9D17CB1B} = {9CBD7DFA-1754-4A9D-93D7-857A9D17CB1B}
{58A03BB2-DF5A-4B66-91A0-7EF3BA01269A} = {58A03BB2-DF5A-4B66-91A0-7EF3BA01269A}
{9CBD7DFA-1754-4A9D-93D7-857A9D17CB1B} = {9CBD7DFA-1754-4A9D-93D7-857A9D17CB1B}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TerminalParser.UnitTests", "src\terminal\parser\ut_parser\Parser.UnitTests.vcxproj", "{12144E07-FE63-4D33-9231-748B8D8C3792}"
Expand Down
23 changes: 14 additions & 9 deletions src/host/srvinit.cpp
Expand Up @@ -258,7 +258,8 @@ void ConsoleCheckDebug()

HRESULT ConsoleEstablishHandoff(_In_ HANDLE Server,
const ConsoleArguments* const args, // this can't stay like this because ConsoleArguments could change...
HANDLE driverInputEvent)
HANDLE driverInputEvent,
PCONSOLE_API_MSG connectMessage)
{
auto& g = ServiceLocator::LocateGlobals();
g.handoffTarget = true;
Expand All @@ -269,7 +270,7 @@ HRESULT ConsoleEstablishHandoff(_In_ HANDLE Server,
// Store the driver input event. It's already been told that it exists by whomever started us.
g.hInputEvent.reset(driverInputEvent);

HANDLE const hThread = CreateThread(nullptr, 0, ConsoleIoThread, nullptr, 0, nullptr);
HANDLE const hThread = CreateThread(nullptr, 0, ConsoleIoThread, connectMessage, 0, nullptr);
RETURN_HR_IF(E_HANDLE, hThread == nullptr);
LOG_IF_WIN32_BOOL_FALSE(CloseHandle(hThread)); // The thread will run on its own and close itself. Free the associated handle.

Expand All @@ -286,11 +287,6 @@ HRESULT ConsoleEstablishHandoff(_In_ HANDLE Server,
return S_OK;
}

[[nodiscard]] bool TestFunc()
{
return false;
}

[[nodiscard]] HRESULT ConsoleCreateIoThreadLegacy(_In_ HANDLE Server, const ConsoleArguments* const args)
{
auto& g = ServiceLocator::LocateGlobals();
Expand Down Expand Up @@ -688,10 +684,10 @@ PWSTR TranslateConsoleTitle(_In_ PCWSTR pwszConsoleTitle, const BOOL fUnexpand,
// - This routine is the main one in the console server IO thread.
// - It reads IO requests submitted by clients through the driver, services and completes them in a loop.
// Arguments:
// - <none>
// - lpParameter - PCONSOLE_API_MSG being handed off to us from the previous I/O.
// Return Value:
// - This routine never returns. The process exits when no more references or clients exist.
DWORD WINAPI ConsoleIoThread(LPVOID /*lpParameter*/)
DWORD WINAPI ConsoleIoThread(LPVOID lpParameter)
{
auto& globals = ServiceLocator::LocateGlobals();

Expand All @@ -700,6 +696,15 @@ DWORD WINAPI ConsoleIoThread(LPVOID /*lpParameter*/)
ReceiveMsg._pDeviceComm = globals.pDeviceComm;
PCONSOLE_API_MSG ReplyMsg = nullptr;

// If we were given a message on startup, process that in our context and then continue with the IO loop normally.
if (lpParameter)
{
ReceiveMsg = *(PCONSOLE_API_MSG)lpParameter;
ReceiveMsg._pApiRoutines = &globals.api;
ReceiveMsg._pDeviceComm = globals.pDeviceComm;
IoSorter::ServiceIoOperation(&ReceiveMsg, &ReplyMsg);
}

bool fShouldExit = false;
while (!fShouldExit)
{
Expand Down
5 changes: 2 additions & 3 deletions src/host/srvinit.h
Expand Up @@ -30,8 +30,7 @@ PWSTR TranslateConsoleTitle(_In_ PCWSTR pwszConsoleTitle, const BOOL fUnexpand,

extern "C" __declspec(dllexport) HRESULT ConsoleEstablishHandoff(_In_ HANDLE Server,
const ConsoleArguments* const args, // this can't stay like this because ConsoleArguments could change...
HANDLE driverInputEvent);

extern "C" __declspec(dllexport) bool TestFunc();
HANDLE driverInputEvent,
PCONSOLE_API_MSG connectMessage);

void ConsoleCheckDebug();
8 changes: 4 additions & 4 deletions src/server/IoDispatchers.cpp
Expand Up @@ -165,16 +165,16 @@ PCONSOLE_API_MSG IoDispatchers::ConsoleHandleConnectionRequest(_In_ PCONSOLE_API

typedef HRESULT (*PFNHANDOFF)(HANDLE,
const ConsoleArguments* const, // this can't stay like this because ConsoleArguments could change...
HANDLE);
HANDLE,
PCONSOLE_API_MSG);

typedef bool (*PFNTEST)();

HMODULE mod = LoadLibraryW(L"OpenConsoleDll.dll");
PFNHANDOFF addr = (PFNHANDOFF)GetProcAddress(mod, "ConsoleEstablishHandoff");
/*PFNTEST addr = (PFNTEST)GetProcAddress(mod, "TestFunc");*/
HRESULT res = addr(Globals.pDeviceComm->_Server.get(), &Globals.launchArgs, Globals.hInputEvent.get());
res;
if (res)
HRESULT res = addr(Globals.pDeviceComm->_Server.get(), &Globals.launchArgs, Globals.hInputEvent.get(), pReceiveMsg);
if (res == S_OK)
{
Sleep(INFINITE);
auto rect = til::rectangle{};
Expand Down

1 comment on commit b5054c8

@github-actions

This comment was marked as outdated.

Please sign in to comment.