7c12d90086
Prior to Windows 7, the undocumented NtQuerySystemInformation API did not return valid handle information when called by a WOW64 process. To work around this problem, the 32-bit test program connects to a 64-bit worker and uses the existing RPC mechanism, issuing LookupKernelObject commands, which call NtQuerySystemInformation in a native 64-bit environment. Even on Windows 7, the NtQuerySystemInformation API returns truncated kernel object pointers, so, AFAIK, we still need to do this work. Maybe not, though, if the lower 32 bits are guaranteed to be unique. On Windows 10, there is a CompareObjectHandles API that works in WOW64 mode.
46 lines
1.3 KiB
C++
46 lines
1.3 KiB
C++
#pragma once
|
|
|
|
#include <windows.h>
|
|
|
|
#include <string>
|
|
|
|
#include "RemoteHandle.h"
|
|
|
|
struct SpawnParams {
|
|
BOOL bInheritHandles = FALSE;
|
|
DWORD dwCreationFlags = 0;
|
|
STARTUPINFOW sui = { sizeof(STARTUPINFOW), 0 };
|
|
static const size_t NoInheritList = static_cast<size_t>(~0);
|
|
size_t inheritCount = NoInheritList;
|
|
std::array<HANDLE, 1024> inheritList = {};
|
|
bool nativeWorkerBitness = false;
|
|
|
|
SpawnParams(bool bInheritHandles=false, DWORD dwCreationFlags=0) :
|
|
bInheritHandles(bInheritHandles),
|
|
dwCreationFlags(dwCreationFlags)
|
|
{
|
|
}
|
|
|
|
SpawnParams(bool bInheritHandles, DWORD dwCreationFlags,
|
|
std::vector<RemoteHandle> stdHandles) :
|
|
bInheritHandles(bInheritHandles),
|
|
dwCreationFlags(dwCreationFlags)
|
|
{
|
|
ASSERT(stdHandles.size() == 3);
|
|
sui.dwFlags |= STARTF_USESTDHANDLES;
|
|
sui.hStdInput = stdHandles[0].value();
|
|
sui.hStdOutput = stdHandles[1].value();
|
|
sui.hStdError = stdHandles[2].value();
|
|
}
|
|
};
|
|
|
|
struct SpawnFailure {
|
|
enum Kind { Success, CreateProcess, UpdateProcThreadAttribute };
|
|
Kind kind = Success;
|
|
DWORD errCode = 0;
|
|
};
|
|
|
|
HANDLE spawn(const std::string &workerName,
|
|
const SpawnParams ¶ms,
|
|
SpawnFailure &error);
|