Enable /permissive- and remaining /Zc flags
This commit is contained in:
parent
f2386de422
commit
5f65c59f17
|
@ -116,9 +116,11 @@
|
|||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
<MinimalRebuild>false</MinimalRebuild>
|
||||
<RuntimeTypeInfo>false</RuntimeTypeInfo>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<UseStandardPreprocessor>true</UseStandardPreprocessor>
|
||||
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||
<LanguageStandard_C>stdc17</LanguageStandard_C>
|
||||
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
|
||||
<AdditionalOptions>%(AdditionalOptions) /utf-8 /Zc:externConstexpr /Zc:lambda /Zc:throwingNew</AdditionalOptions>
|
||||
<ControlFlowGuard>Guard</ControlFlowGuard>
|
||||
<FloatingPointModel>Fast</FloatingPointModel>
|
||||
</ClCompile>
|
||||
|
|
|
@ -72,8 +72,6 @@
|
|||
<PrecompiledHeaderOutputFile>$(IntDir)pch.pch</PrecompiledHeaderOutputFile>
|
||||
|
||||
<!-- All new code should be in non-permissive mode. Big objects for C++/WinRT. -->
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<UseStandardPreprocessor>true</UseStandardPreprocessor>
|
||||
<AdditionalOptions>%(AdditionalOptions) /bigobj /Zc:twoPhase-</AdditionalOptions>
|
||||
<DisableSpecificWarnings>5104;28204;%(DisableSpecificWarnings)</DisableSpecificWarnings>
|
||||
|
||||
|
|
|
@ -12,8 +12,6 @@
|
|||
// - Ensures the SxS initialization for the process.
|
||||
void InitSideBySide(_Out_writes_(ScratchBufferSize) PWSTR ScratchBuffer, __range(MAX_PATH, MAX_PATH) DWORD ScratchBufferSize)
|
||||
{
|
||||
ACTCTXW actctx = { 0 };
|
||||
|
||||
// Account for the fact that sidebyside stuff happens in CreateProcess
|
||||
// but conhost is run with RtlCreateUserProcess.
|
||||
|
||||
|
@ -30,38 +28,35 @@ void InitSideBySide(_Out_writes_(ScratchBufferSize) PWSTR ScratchBuffer, __range
|
|||
// make references to DLLs in the system that are in the SxS cache (ex. a 3rd party IME is loaded and asks for
|
||||
// comctl32.dll. The load will fail if SxS wasn't initialized.) This was bug# WIN7:681280.
|
||||
|
||||
// We look at the first few chars without being careful about a terminal nul, so init them.
|
||||
ScratchBuffer[0] = 0;
|
||||
ScratchBuffer[1] = 0;
|
||||
ScratchBuffer[2] = 0;
|
||||
ScratchBuffer[3] = 0;
|
||||
ScratchBuffer[4] = 0;
|
||||
ScratchBuffer[5] = 0;
|
||||
ScratchBuffer[6] = 0;
|
||||
|
||||
// GetModuleFileNameW truncates its result to fit in the buffer, so to detect if we fit, we have to do this.
|
||||
ScratchBuffer[ScratchBufferSize - 2] = 0;
|
||||
DWORD const dwModuleFileNameLength = GetModuleFileNameW(nullptr, ScratchBuffer, ScratchBufferSize);
|
||||
if (dwModuleFileNameLength == 0)
|
||||
{
|
||||
RIPMSG1(RIP_ERROR, "GetModuleFileNameW failed %d.\n", GetLastError());
|
||||
goto Exit;
|
||||
return;
|
||||
}
|
||||
if (ScratchBuffer[ScratchBufferSize - 2] != 0)
|
||||
// GetModuleFileNameW truncates its result to fit in the buffer
|
||||
// and returns the given buffer size in such cases.
|
||||
if (dwModuleFileNameLength == ScratchBufferSize)
|
||||
{
|
||||
RIPMSG1(RIP_ERROR, "GetModuleFileNameW requires more than ScratchBufferSize(%d) - 1.\n", ScratchBufferSize);
|
||||
goto Exit;
|
||||
return;
|
||||
}
|
||||
|
||||
// We get an NT path from the Win32 api. Fix it to be Win32.
|
||||
// We can test for NT paths by checking whether the string starts with "\??\C:\", or any
|
||||
// alternative letter other than C. We specifically don't test for the drive letter below.
|
||||
UINT NtToWin32PathOffset = 0;
|
||||
if (ScratchBuffer[0] == '\\' && ScratchBuffer[1] == '?' && ScratchBuffer[2] == '?' && ScratchBuffer[3] == '\\'
|
||||
//&& ScratchBuffer[4] == a drive letter
|
||||
&& ScratchBuffer[5] == ':' && ScratchBuffer[6] == '\\')
|
||||
static constexpr wchar_t ntPathSpec1[]{ L'\\', L'?', L'?', L'\\' };
|
||||
static constexpr wchar_t ntPathSpec2[]{ L':', L'\\' };
|
||||
if (
|
||||
dwModuleFileNameLength >= 7 &&
|
||||
memcmp(&ScratchBuffer[0], &ntPathSpec1[0], sizeof(ntPathSpec1)) == 0 &&
|
||||
memcmp(&ScratchBuffer[5], &ntPathSpec2[0], sizeof(ntPathSpec2)) == 0)
|
||||
{
|
||||
NtToWin32PathOffset = 4;
|
||||
}
|
||||
|
||||
ACTCTXW actctx{};
|
||||
actctx.cbSize = sizeof(actctx);
|
||||
actctx.dwFlags = (ACTCTX_FLAG_RESOURCE_NAME_VALID | ACTCTX_FLAG_SET_PROCESS_DEFAULT);
|
||||
actctx.lpResourceName = MAKEINTRESOURCE(IDR_SYSTEM_MANIFEST);
|
||||
|
@ -83,11 +78,7 @@ void InitSideBySide(_Out_writes_(ScratchBufferSize) PWSTR ScratchBuffer, __range
|
|||
{
|
||||
RIPMSG1(RIP_WARNING, "InitSideBySide failed create an activation context. Error: %d\r\n", error);
|
||||
}
|
||||
goto Exit;
|
||||
}
|
||||
|
||||
Exit:
|
||||
ScratchBuffer[0] = 0;
|
||||
}
|
||||
|
||||
// Routine Description:
|
||||
|
|
|
@ -58,7 +58,7 @@ Tracing::~Tracing()
|
|||
// Return Value:
|
||||
// - An object for the caller to hold until the API call is complete.
|
||||
// Then destroy it to signal that the call is over so the stop trace can be written.
|
||||
Tracing Tracing::s_TraceApiCall(const NTSTATUS& result, PCSTR traceName)
|
||||
Tracing Tracing::s_TraceApiCall(const NTSTATUS result, PCSTR traceName)
|
||||
{
|
||||
// clang-format off
|
||||
TraceLoggingWrite(
|
||||
|
|
|
@ -40,7 +40,7 @@ class Tracing
|
|||
public:
|
||||
~Tracing();
|
||||
|
||||
static Tracing s_TraceApiCall(const NTSTATUS& result, PCSTR traceName);
|
||||
static Tracing s_TraceApiCall(const NTSTATUS result, PCSTR traceName);
|
||||
|
||||
static void s_TraceApi(const NTSTATUS status, const CONSOLE_GETLARGESTWINDOWSIZE_MSG* const a);
|
||||
static void s_TraceApi(const NTSTATUS status, const CONSOLE_SCREENBUFFERINFO_MSG* const a, const bool fSet);
|
||||
|
|
|
@ -97,7 +97,7 @@ namespace til // Terminal Implementation Library. Also: "Today I Learned"
|
|||
public:
|
||||
template<typename... Args>
|
||||
constexpr explicit presorted_static_map(const Args&... args) noexcept :
|
||||
static_map{ args... } {};
|
||||
static_map<K, V, Compare, N, details::presorted_input_t>{ args... } {};
|
||||
};
|
||||
|
||||
// this is a deduction guide that ensures two things:
|
||||
|
|
|
@ -169,7 +169,7 @@ namespace til // Terminal Implementation Library. Also: "Today I Learned"
|
|||
// and 5x or more for long strings (128 characters or more).
|
||||
// See: https://github.com/microsoft/STL/issues/2289
|
||||
template<typename T, typename Traits>
|
||||
bool equals(const std::basic_string_view<T, Traits>& str1, const std::basic_string_view<T, Traits>& str2) noexcept
|
||||
bool equals(const std::basic_string_view<T, Traits>& lhs, const std::basic_string_view<T, Traits>& rhs) noexcept
|
||||
{
|
||||
return lhs.size() == rhs.size() && __builtin_memcmp(lhs.data(), rhs.data(), lhs.size() * sizeof(T)) == 0;
|
||||
}
|
||||
|
|
|
@ -18,14 +18,7 @@ static CONSOLE_STATE_INFO g_csi;
|
|||
using namespace Microsoft::WRL;
|
||||
|
||||
// This class exposes console property sheets for use when launching the filesystem shortcut properties dialog.
|
||||
// clang-format off
|
||||
[uuid(D2942F8E-478E-41D3-870A-35A16238F4EE)]
|
||||
class ConsolePropertySheetHandler WrlFinal : public RuntimeClass<RuntimeClassFlags<ClassicCom>,
|
||||
IShellExtInit,
|
||||
IShellPropSheetExt,
|
||||
IPersist,
|
||||
FtmBase>
|
||||
// clang-format on
|
||||
class __declspec(uuid("D2942F8E-478E-41D3-870A-35A16238F4EE")) ConsolePropertySheetHandler final : public RuntimeClass<RuntimeClassFlags<ClassicCom>, IShellExtInit, IShellPropSheetExt, IPersist, FtmBase>
|
||||
{
|
||||
public:
|
||||
HRESULT RuntimeClassInitialize()
|
||||
|
@ -34,7 +27,7 @@ public:
|
|||
}
|
||||
|
||||
// IPersist
|
||||
STDMETHODIMP GetClassID(_Out_ CLSID * clsid) override
|
||||
STDMETHODIMP GetClassID(_Out_ CLSID* clsid) override
|
||||
{
|
||||
*clsid = __uuidof(this);
|
||||
return S_OK;
|
||||
|
@ -43,7 +36,7 @@ public:
|
|||
// IShellExtInit
|
||||
// Shell QI's for IShellExtInit and calls Initialize first. If we return a succeeding HRESULT, the shell will QI for
|
||||
// IShellPropSheetExt and call AddPages. A failing HRESULT causes the shell to skip us.
|
||||
STDMETHODIMP Initialize(_In_ PCIDLIST_ABSOLUTE /*pidlFolder*/, _In_ IDataObject * pdtobj, _In_ HKEY /*hkeyProgID*/)
|
||||
STDMETHODIMP Initialize(_In_ PCIDLIST_ABSOLUTE /*pidlFolder*/, _In_ IDataObject* pdtobj, _In_ HKEY /*hkeyProgID*/)
|
||||
{
|
||||
WCHAR szLinkFileName[MAX_PATH];
|
||||
HRESULT hr = _ShouldAddPropertySheet(pdtobj, szLinkFileName, ARRAYSIZE(szLinkFileName));
|
||||
|
@ -139,7 +132,7 @@ private:
|
|||
///////////////////////////////////////////////////////////////////////////
|
||||
// CODE FROM THE SHELL DEPOT'S `idllib.h`
|
||||
// get a link target item without resolving it.
|
||||
HRESULT GetTargetIdList(_In_ IShellItem * psiLink, _COM_Outptr_ PIDLIST_ABSOLUTE * ppidl)
|
||||
HRESULT GetTargetIdList(_In_ IShellItem* psiLink, _COM_Outptr_ PIDLIST_ABSOLUTE* ppidl)
|
||||
{
|
||||
*ppidl = nullptr;
|
||||
|
||||
|
@ -156,7 +149,7 @@ private:
|
|||
}
|
||||
return hr;
|
||||
}
|
||||
HRESULT GetTargetItem(_In_ IShellItem * psiLink, _In_ REFIID riid, _COM_Outptr_ void** ppv)
|
||||
HRESULT GetTargetItem(_In_ IShellItem* psiLink, _In_ REFIID riid, _COM_Outptr_ void** ppv)
|
||||
{
|
||||
*ppv = nullptr;
|
||||
|
||||
|
@ -171,7 +164,7 @@ private:
|
|||
}
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
HRESULT _GetShellItemLinkTargetExpanded(_In_ IShellItem * pShellItem,
|
||||
HRESULT _GetShellItemLinkTargetExpanded(_In_ IShellItem* pShellItem,
|
||||
_Out_writes_(cchFilePathExtended) PWSTR pszFilePathExtended,
|
||||
const size_t cchFilePathExtended)
|
||||
{
|
||||
|
@ -190,7 +183,7 @@ private:
|
|||
return hr;
|
||||
}
|
||||
|
||||
HRESULT _ShouldAddPropertySheet(_In_ IDataObject * pdtobj,
|
||||
HRESULT _ShouldAddPropertySheet(_In_ IDataObject* pdtobj,
|
||||
_Out_writes_(cchLinkFileName) PWSTR pszLinkFileName,
|
||||
const size_t cchLinkFileName)
|
||||
{
|
||||
|
|
|
@ -359,7 +359,9 @@ namespace Microsoft::Console::Render
|
|||
|
||||
bool is_inline() const noexcept
|
||||
{
|
||||
return (__builtin_bit_cast(uintptr_t, allocated) & 1) != 0;
|
||||
// VSO-1430353: __builtin_bitcast crashes the compiler under /permissive-.
|
||||
#pragma warning(suppress : 26490) // Don't use reinterpret_cast (type.1).
|
||||
return (reinterpret_cast<uintptr_t>(allocated) & 1) != 0;
|
||||
}
|
||||
|
||||
const T* data() const noexcept
|
||||
|
|
|
@ -144,11 +144,10 @@ PCONSOLE_API_MSG ApiSorter::ConsoleDispatchRequest(_Inout_ PCONSOLE_API_MSG Mess
|
|||
ULONG const LayerNumber = (Message->msgHeader.ApiNumber >> 24) - 1;
|
||||
ULONG const ApiNumber = Message->msgHeader.ApiNumber & 0xffffff;
|
||||
|
||||
NTSTATUS Status;
|
||||
if ((LayerNumber >= RTL_NUMBER_OF(ConsoleApiLayerTable)) || (ApiNumber >= ConsoleApiLayerTable[LayerNumber].Count))
|
||||
if ((LayerNumber >= std::size(ConsoleApiLayerTable)) || (ApiNumber >= ConsoleApiLayerTable[LayerNumber].Count))
|
||||
{
|
||||
Status = STATUS_ILLEGAL_FUNCTION;
|
||||
goto Complete;
|
||||
Message->SetReplyStatus(STATUS_ILLEGAL_FUNCTION);
|
||||
return Message;
|
||||
}
|
||||
|
||||
CONSOLE_API_DESCRIPTOR const* Descriptor = &ConsoleApiLayerTable[LayerNumber].Descriptor[ApiNumber];
|
||||
|
@ -159,8 +158,8 @@ PCONSOLE_API_MSG ApiSorter::ConsoleDispatchRequest(_Inout_ PCONSOLE_API_MSG Mess
|
|||
(Message->msgHeader.ApiDescriptorSize > Message->Descriptor.InputSize - sizeof(CONSOLE_MSG_HEADER)) ||
|
||||
(Message->msgHeader.ApiDescriptorSize < Descriptor->RequiredSize))
|
||||
{
|
||||
Status = STATUS_ILLEGAL_FUNCTION;
|
||||
goto Complete;
|
||||
Message->SetReplyStatus(STATUS_ILLEGAL_FUNCTION);
|
||||
return Message;
|
||||
}
|
||||
|
||||
BOOL ReplyPending = FALSE;
|
||||
|
@ -173,6 +172,7 @@ PCONSOLE_API_MSG ApiSorter::ConsoleDispatchRequest(_Inout_ PCONSOLE_API_MSG Mess
|
|||
// hard dependencies on NTSTATUS codes that aren't readily expressible as an HRESULT. There's currently only one
|
||||
// such known code -- STATUS_BUFFER_TOO_SMALL. There's a conlibk dependency on this being returned from the console
|
||||
// alias API.
|
||||
NTSTATUS Status = S_OK;
|
||||
{
|
||||
const auto trace = Tracing::s_TraceApiCall(Status, Descriptor->TraceName);
|
||||
Status = (*Descriptor->Routine)(Message, &ReplyPending);
|
||||
|
@ -184,14 +184,9 @@ PCONSOLE_API_MSG ApiSorter::ConsoleDispatchRequest(_Inout_ PCONSOLE_API_MSG Mess
|
|||
|
||||
if (!ReplyPending)
|
||||
{
|
||||
goto Complete;
|
||||
Message->SetReplyStatus(Status);
|
||||
return Message;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
|
||||
Complete:
|
||||
|
||||
Message->SetReplyStatus(Status);
|
||||
|
||||
return Message;
|
||||
}
|
||||
|
|
|
@ -92,7 +92,9 @@ PCONSOLE_API_MSG IoDispatchers::ConsoleCreateObject(_In_ PCONSOLE_API_MSG pMessa
|
|||
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
goto Error;
|
||||
UnlockConsole();
|
||||
pMessage->SetReplyStatus(Status);
|
||||
return pMessage;
|
||||
}
|
||||
|
||||
auto deviceComm{ ServiceLocator::LocateGlobals().pDeviceComm };
|
||||
|
@ -110,16 +112,6 @@ PCONSOLE_API_MSG IoDispatchers::ConsoleCreateObject(_In_ PCONSOLE_API_MSG pMessa
|
|||
UnlockConsole();
|
||||
|
||||
return nullptr;
|
||||
|
||||
Error:
|
||||
|
||||
FAIL_FAST_IF(NT_SUCCESS(Status));
|
||||
|
||||
UnlockConsole();
|
||||
|
||||
pMessage->SetReplyStatus(Status);
|
||||
|
||||
return pMessage;
|
||||
}
|
||||
|
||||
// Routine Description:
|
||||
|
@ -256,17 +248,32 @@ PCONSOLE_API_MSG IoDispatchers::ConsoleHandleConnectionRequest(_In_ PCONSOLE_API
|
|||
Telemetry::Instance().LogApiCall(Telemetry::ApiCall::AttachConsole);
|
||||
|
||||
ConsoleProcessHandle* ProcessData = nullptr;
|
||||
NTSTATUS Status;
|
||||
|
||||
LockConsole();
|
||||
|
||||
const auto cleanup = wil::scope_exit([&]() noexcept {
|
||||
UnlockConsole();
|
||||
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
pReceiveMsg->SetReplyStatus(Status);
|
||||
if (ProcessData != nullptr)
|
||||
{
|
||||
CommandHistory::s_Free(ProcessData);
|
||||
gci.ProcessHandleList.FreeProcessData(ProcessData);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
DWORD const dwProcessId = (DWORD)pReceiveMsg->Descriptor.Process;
|
||||
DWORD const dwThreadId = (DWORD)pReceiveMsg->Descriptor.Object;
|
||||
|
||||
CONSOLE_API_CONNECTINFO Cac;
|
||||
NTSTATUS Status = ConsoleInitializeConnectInfo(pReceiveMsg, &Cac);
|
||||
Status = ConsoleInitializeConnectInfo(pReceiveMsg, &Cac);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
goto Error;
|
||||
return pReceiveMsg;
|
||||
}
|
||||
|
||||
// If we pass the tests...
|
||||
|
@ -354,7 +361,7 @@ PCONSOLE_API_MSG IoDispatchers::ConsoleHandleConnectionRequest(_In_ PCONSOLE_API
|
|||
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
goto Error;
|
||||
return pReceiveMsg;
|
||||
}
|
||||
|
||||
ProcessData->fRootProcess = WI_IsFlagClear(gci.Flags, CONSOLE_INITIALIZED);
|
||||
|
@ -376,7 +383,7 @@ PCONSOLE_API_MSG IoDispatchers::ConsoleHandleConnectionRequest(_In_ PCONSOLE_API
|
|||
Status = ConsoleAllocateConsole(&Cac);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
goto Error;
|
||||
return pReceiveMsg;
|
||||
}
|
||||
|
||||
WI_SetFlag(gci.Flags, CONSOLE_INITIALIZED);
|
||||
|
@ -389,7 +396,7 @@ PCONSOLE_API_MSG IoDispatchers::ConsoleHandleConnectionRequest(_In_ PCONSOLE_API
|
|||
catch (...)
|
||||
{
|
||||
LOG_CAUGHT_EXCEPTION();
|
||||
goto Error;
|
||||
return pReceiveMsg;
|
||||
}
|
||||
|
||||
gci.ProcessHandleList.ModifyConsoleProcessFocus(WI_IsFlagSet(gci.Flags, CONSOLE_HAS_FOCUS));
|
||||
|
@ -403,7 +410,7 @@ PCONSOLE_API_MSG IoDispatchers::ConsoleHandleConnectionRequest(_In_ PCONSOLE_API
|
|||
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
goto Error;
|
||||
return pReceiveMsg;
|
||||
}
|
||||
|
||||
auto& screenInfo = gci.GetActiveOutputBuffer().GetMainBuffer();
|
||||
|
@ -414,7 +421,7 @@ PCONSOLE_API_MSG IoDispatchers::ConsoleHandleConnectionRequest(_In_ PCONSOLE_API
|
|||
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
goto Error;
|
||||
return pReceiveMsg;
|
||||
}
|
||||
|
||||
// Complete the request.
|
||||
|
@ -434,24 +441,7 @@ PCONSOLE_API_MSG IoDispatchers::ConsoleHandleConnectionRequest(_In_ PCONSOLE_API
|
|||
|
||||
Tracing::s_TraceConsoleAttachDetach(ProcessData, true);
|
||||
|
||||
UnlockConsole();
|
||||
|
||||
return nullptr;
|
||||
|
||||
Error:
|
||||
FAIL_FAST_IF(NT_SUCCESS(Status));
|
||||
|
||||
if (ProcessData != nullptr)
|
||||
{
|
||||
CommandHistory::s_Free((HANDLE)ProcessData);
|
||||
gci.ProcessHandleList.FreeProcessData(ProcessData);
|
||||
}
|
||||
|
||||
UnlockConsole();
|
||||
|
||||
pReceiveMsg->SetReplyStatus(Status);
|
||||
|
||||
return pReceiveMsg;
|
||||
}
|
||||
|
||||
// Routine Description:
|
||||
|
|
Loading…
Reference in a new issue