[+] Windows 7 support

This commit is contained in:
Reece Wilson 2022-12-14 01:35:18 +00:00
parent 267c2216b0
commit cbad382b6a
15 changed files with 230 additions and 29 deletions

View File

@ -34,6 +34,7 @@
#include "CmdLine/CmdLine.hpp"
#include "Grug/AuGrug.hpp"
#include "Threading/AuSleep.hpp"
#include "Memory/Cache.hpp"
#if defined(AURORA_IS_LINUX_DERIVED)
void LinuxSuperSecretIOTick();
@ -56,6 +57,8 @@ static void Init()
Aurora::Extensions::Win32::InitDarkMode();
#endif
Aurora::Memory::Cache::InitCache();
Crypto::InitCrypto();
Aurora::RNG::Init();
Aurora::IO::TLS::TLSInit();

View File

@ -87,14 +87,11 @@ namespace Aurora::Console
{
try
{
return fmt::format("{}[{}] {:<8} | {}{}",
static_cast<EAnsiColor>(color) <= EAnsiColor::eEnumCount ?
kAnsiColorForegroundToVirtualEscape[static_cast<AuUInt>(color)] :
"",
return fmt::format("[{}] {:<8} | {}",
StringifyTime(gRuntimeConfig.console.stdOutShortTime),
GetWrappedTag(),
line,
kAnsiColorForegroundToVirtualEscape[static_cast<AuUInt>(EAnsiColor::eReset)]);
line);//,
//kAnsiColorForegroundToVirtualEscape[static_cast<AuUInt>(EAnsiColor::eReset)]);
}
catch (...)
{

View File

@ -17,6 +17,8 @@
#include <Source/Console/ConsoleTTY/ConsoleTTY.hpp>
#include "../ColorConvert.hpp"
#if defined(AURORA_IS_MODERNNT_DERIVED) || defined(AURORA_IS_POSIX_DERIVED)
#if defined(AURORA_IS_MODERNNT_DERIVED)
@ -805,9 +807,19 @@ namespace Aurora::Console::ConsoleStd
{
if (gRuntimeConfig.console.enableStdPassthrough ^ gRuntimeConfig.console.enableStdOut)
{
if (AuSwInfo::IsWindows10OrGreater() && AuSwInfo::GetPlatformInfo().uKernelPatch >= 10586)
{
dwMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
}
else
{
gSupportsColorOutput = false;
}
// Enable escape processing; enable colored output
dwMode |= ENABLE_PROCESSED_OUTPUT | ENABLE_VIRTUAL_TERMINAL_PROCESSING;
dwMode |= ENABLE_PROCESSED_OUTPUT;
ok = SetConsoleMode(gOutputStream, dwMode);
auto er = GetLastError();
SysAssert(ok, "Couldn't set console mode");
// Set the output stream to use UTF-8
@ -995,13 +1007,37 @@ namespace Aurora::Console::ConsoleStd
void WriteStdOut(AuUInt8 level, const ConsoleMessage &msg)
{
bool bUseAlt {};
auto writeLine = msg.ToConsole();
if (!gSupportsColorOutput)
{
if (IsStdOutTTY())
{
bUseAlt = true;
}
}
else
{
const char *pAnsiCode =
static_cast<EAnsiColor>(msg.color) <= EAnsiColor::eEnumCount ?
kAnsiColorForegroundToVirtualEscape[static_cast<AuUInt>(msg.color)] :
"";
writeLine = pAnsiCode + writeLine + kAnsiColorForegroundToVirtualEscape[static_cast<AuUInt>(EAnsiColor::eReset)];
}
#if defined(AURORA_IS_MODERNNT_DERIVED)
writeLine += '\r';
#endif
writeLine += '\n';
if (bUseAlt)
{
ConsoleTTY::TTYWrite(writeLine.c_str(), msg.color);
return;
}
#if defined(IO_POSIX_STREAMS)
if (Locale::GetInternalCodePage() == Locale::ECodePage::eUTF8)
{

View File

@ -27,6 +27,8 @@ namespace Aurora::Console::ConsoleStd
void WriteStdOut(AuUInt8 level, const ConsoleMessage &msg);
inline bool gSupportsColorOutput { true };
#if defined(AURORA_IS_MODERNNT_DERIVED)
void ProcessCanonical(HANDLE h);
#endif

View File

@ -19,6 +19,8 @@
#include "ConsoleTTY.Unix.hpp"
#endif
#include "../ColorConvert.hpp"
namespace Aurora::Console::ConsoleTTY
{
static AuThreads::ThreadUnique_t gConsoleTTYThread;
@ -784,7 +786,7 @@ namespace Aurora::Console::ConsoleTTY
{
if (resChanged)
{
for (auto &message : this->screenBuffer)
for (auto &[color, message] : this->screenBuffer)
{
int anyLineRemoveEsc = message.rfind('\x1b', 0) == 0;
@ -833,7 +835,7 @@ namespace Aurora::Console::ConsoleTTY
int idx = AuLocale::Encoding::CountUTF8Length({str.data(), AuMin<AuUInt>(str.size(), maxWidth + (anyLineRemoveEsc * 7))}, true);
auto append = str.substr(0, idx);
AuTryInsert(this->screenBuffer, append);
AuTryInsert(this->screenBuffer, AuMakePair(message.color, append));
str = str.substr(idx);
this->bScreenBufferDoesntMap |= bool(str.size());
@ -935,7 +937,9 @@ namespace Aurora::Console::ConsoleTTY
{
for (int i = 0; i < delta; i++)
{
WriteBuffered({GetLeftBorder() + this->leftLogPadding, i + drawPos}, this->screenBuffer[i + oldSize]);
auto &[color, message] = this->screenBuffer[i + oldSize];
WriteBufferedEx({GetLeftBorder() + this->leftLogPadding, i + drawPos}, color, message);
}
}
@ -1129,7 +1133,8 @@ namespace Aurora::Console::ConsoleTTY
#if defined(AURORA_IS_MODERNNT_DERIVED)
DWORD idc;
WriteConsoleA(GetTTYHandle(), in.data(), AuUInt32(in.size()), &idc, NULL);
auto line2 = AuLocale::ConvertFromUTF8(in);
WriteConsoleW(GetTTYHandle(), line2.data(), AuUInt32(line2.size()), &idc, NULL);
#else
ConsoleStd::WriteStdOutBlocking2(in.data(), in.size());
#endif
@ -1174,13 +1179,64 @@ namespace Aurora::Console::ConsoleTTY
#if defined(AURORA_IS_MODERNNT_DERIVED)
DWORD idc;
WriteConsoleA(GetTTYHandle(), in.data(), AuUInt32(in.size()), &idc, NULL);
auto line2 = AuLocale::ConvertFromUTF8(in);
WriteConsoleW(GetTTYHandle(), line2.data(), AuUInt32(line2.size()), &idc, NULL);
#else
ConsoleStd::WriteStdOutBlocking2(in.data(), in.size());
#endif
}
void TTYConsole::WriteBufferedEx(AuPair<AuUInt32, AuUInt32> pos, EAnsiColor color, const AuString &in)
{
#if defined(AURORA_IS_MODERNNT_DERIVED)
RecordFunction(std::bind(&TTYConsole::WriteBufferedEx, this, pos, color, std::string(in)));
#endif
if (in.empty())
{
return;
}
TTYSetPos(pos);
#if defined(AURORA_IS_MODERNNT_DERIVED)
DWORD idc;
{
auto hConsole = GetTTYHandle();
DWORD attrib {};
if (color != EAnsiColor::eEnumCount)
{
attrib |= kAnsiColorForegroundToNT[AuStaticCast<AuUInt>(color)];
}
else
{
attrib = FOREGROUND_WHITE;
}
auto line2 = AuLocale::ConvertFromUTF8(in);
SetConsoleTextAttribute(hConsole, attrib);
WriteConsoleW(hConsole, line2.data(), AuUInt32(line2.size()), &idc, NULL);
SetConsoleTextAttribute(hConsole, FOREGROUND_WHITE);
}
//WriteConsoleA(GetTTYHandle(), in.data(), AuUInt32(in.size()), &idc, NULL);
#else
AuString writeLine;
const char *pAnsiCode =
static_cast<EAnsiColor>(color) <= EAnsiColor::eEnumCount ?
kAnsiColorForegroundToVirtualEscape[static_cast<AuUInt>(color)] :
"";
writeLine = pAnsiCode + in + kAnsiColorForegroundToVirtualEscape[static_cast<AuUInt>(EAnsiColor::eReset)];
x
ConsoleStd::WriteStdOutBlocking2(writeLine.data(), writeLine.size());
#endif
}
void TTYConsole::RedrawBorders()
{
TTYSetPos({});
@ -1620,7 +1676,9 @@ namespace Aurora::Console::ConsoleTTY
break;
}
WriteBuffered({GetLeftBorder() + this->leftLogPadding, i + startIndex}, this->screenBuffer[strIdx]);
auto &[color, message] = this->screenBuffer[strIdx];
WriteBufferedEx({ GetLeftBorder() + this->leftLogPadding, i + drawPos }, color, message);
//WriteBuffered({GetLeftBorder() + this->leftLogPadding, i + startIndex}, this->screenBuffer[strIdx].second);
}
}

View File

@ -157,6 +157,7 @@ namespace Aurora::Console::ConsoleTTY
virtual AuUInt8 GetPaddingHeadOfLog() override;
virtual AuUInt8 GetPaddingTopOfLog() override;
void WriteBufferedEx(AuPair<AuUInt32, AuUInt32> pos, EAnsiColor color, const AuString &in);
void WriteBuffered(AuPair<AuUInt32, AuUInt32> pos, const AuString &in);
void WriteLine(int Y, const AuString &in);
void BlankLine(int Y, bool borders = true);
@ -189,7 +190,7 @@ namespace Aurora::Console::ConsoleTTY
AuList<AuConsole::ConsoleMessage> messagesPending;
AuList<AuConsole::ConsoleMessage> messages;
AuList<AuString> screenBuffer;
AuList<AuPair<AuConsole::EAnsiColor, AuString>> screenBuffer;
bool bScreenBufferDoesntMap {};
int iScrollPos { -1 };

View File

@ -14,6 +14,14 @@
#include <VersionHelpers.h>
#endif
BOOL(__stdcall *GetSystemCpuSetInformation_f)(
PSYSTEM_CPU_SET_INFORMATION Information,
ULONG BufferLength,
PULONG ReturnedLength,
HANDLE Process,
ULONG Flags
);
namespace Aurora::HWInfo
{
static bool TrySetNtCpuSetInfoSlowExtended()
@ -22,7 +30,14 @@ namespace Aurora::HWInfo
SYSTEM_LOGICAL_PROCESSOR_INFORMATION sysinfo[128];
DWORD length = {};
if (!GetSystemCpuSetInformation(cpuSetInfo, sizeof(cpuSetInfo), &length, 0, 0))
GetSystemCpuSetInformation_f = AuReinterpretCast<decltype(GetSystemCpuSetInformation_f)>(GetProcAddress(GetModuleHandleW(L"Kernel32.dll"), "GetSystemCpuSetInformation"));
if (!GetSystemCpuSetInformation_f)
{
return false;
}
if (!GetSystemCpuSetInformation_f(cpuSetInfo, sizeof(cpuSetInfo), &length, 0, 0))
{
return false;
}
@ -181,7 +196,7 @@ namespace Aurora::HWInfo
CpuBitId serverId;
serverId.lower = mask;
gCpuInfo.coreTopology.push_back(mask);
gCpuInfo.coreTopology.push_back(serverId);
int counter {};
unsigned long offset {}, tmp;
@ -211,17 +226,19 @@ namespace Aurora::HWInfo
if (hasHTCores && (tmp == 1))
{
AuUInt8 idx {};
if (serverId.CpuBitScanForward(idx, 0))
while (serverId.CpuBitScanForward(idx, idx))
{
gCpuInfo.maskECores.Add(idx);
idx++;
}
}
else
{
AuUInt8 idx {};
if (serverId.CpuBitScanForward(idx, 0))
while (serverId.CpuBitScanForward(idx, idx))
{
gCpuInfo.maskPCores.Add(idx);
idx++;
}
gCpuInfo.pCoreTopology.push_back(mask);
}

View File

@ -53,8 +53,12 @@ namespace Aurora::IO::Net
return false;
}
int iRet {};
HANDLE hHandle = NULL;
int iRet = GetAddrInfoExW(AuLocale::ConvertFromUTF8(this->hostname).data(),
if (GetAddrInfoExCancel_f)
{
iRet = GetAddrInfoExW(AuLocale::ConvertFromUTF8(this->hostname).data(),
nullptr,
NS_DNS,
nullptr,
@ -64,6 +68,21 @@ namespace Aurora::IO::Net
&this->overlapped,
NULL,
&hHandle);
}
else
{
iRet = GetAddrInfoExW(AuLocale::ConvertFromUTF8(this->hostname).data(),
nullptr,
NS_DNS,
nullptr,
&infoEx,
&this->resultHandle_,
nullptr,
nullptr,
nullptr,
nullptr);
}
this->hName_ = hHandle;
return this->FinishOperationEx(AuSharedFromThis(),
this->pWorker_,
@ -141,7 +160,10 @@ namespace Aurora::IO::Net
auto hHandle = AuExchange(this->hName_, (HANDLE)NULL);
if (hHandle != NULL)
{
::GetAddrInfoExCancel(&hHandle);
if (GetAddrInfoExCancel_f)
{
GetAddrInfoExCancel_f(&hHandle);
}
}
while (!this->HasComplete())

View File

@ -24,6 +24,9 @@ namespace Aurora::IO::Net
wVersionRequested = MAKEWORD(2, 2);
gWin32NetReady = !WSAStartup(wVersionRequested, &wsaData);
GetAddrInfoExCancel_f = AuReinterpretCast<decltype(GetAddrInfoExCancel_f)>(GetProcAddress(GetModuleHandleW(L"Ws2_32.dll"), "GetAddrInfoExCancel"));
#endif
#if defined(AURORA_IS_LINUX_DERIVED)

View File

@ -43,5 +43,11 @@ namespace Aurora::IO::Net
{
static const auto kDefaultStreamSize = 32 * 1024; // ~960 clients for 30MB of 2x 32KiB streams. Seems... reasonable.
#if defined(AURORA_IS_MODERNNT_DERIVED)
inline INT(__stdcall *GetAddrInfoExCancel_f)(
LPHANDLE lpHandle
);
#endif
bool IsNetReady();
}

View File

@ -25,10 +25,27 @@
namespace Aurora::Memory::Cache
{
struct WIN32_MEMORY_RANGE_ENTRY2 {
PVOID VirtualAddress;
SIZE_T NumberOfBytes;
};
BOOL (__stdcall *PrefetchVirtualMemory_f)(
HANDLE hProcess,
ULONG_PTR NumberOfEntries,
WIN32_MEMORY_RANGE_ENTRY2* VirtualAddresses,
ULONG Flags
);
AUKN_SYM void OptimizeAddressRangeOnCore(const AuList<AuPair<AuUInt, AuUInt>> &addressRanges)
{
#if defined(AURORA_IS_MODERNNT_DERIVED)
AuList<WIN32_MEMORY_RANGE_ENTRY> arry;
AuList<WIN32_MEMORY_RANGE_ENTRY2> arry;
if (!PrefetchVirtualMemory_f)
{
return;
}
if (!AuTryResize(arry, addressRanges.size()))
{
@ -63,7 +80,7 @@ namespace Aurora::Memory::Cache
}
#if defined(AURORA_IS_MODERNNT_DERIVED)
if (!PrefetchVirtualMemory(GetCurrentProcess(), arry.size(), arry.data(), 0))
if (!PrefetchVirtualMemory_f(GetCurrentProcess(), arry.size(), arry.data(), 0))
{
SysPushErrorHAL("Couldn't poke memory physical memory into virtual address space (array)");
}
@ -112,4 +129,11 @@ namespace Aurora::Memory::Cache
__clear_cache(AuReinterpretCast<const char *>(base), AuReinterpretCast<const char *>(base) + length);
#endif
}
void InitCache()
{
#if defined(AURORA_IS_MODERNNT_DERIVED)
PrefetchVirtualMemory_f = AuReinterpretCast<decltype(PrefetchVirtualMemory_f)>(GetProcAddress(GetModuleHandleW(L"Kernel32.dll"), "PrefetchVirtualMemory"));
#endif
}
}

View File

@ -9,5 +9,5 @@
namespace Aurora::Memory::Cache
{
void InitCache();
}

View File

@ -90,7 +90,13 @@ namespace Aurora::RNG
#else
#if !defined(AURORA_DONT_PREFER_WIN32_USERLAND_AES_RNG)
if (::BCryptGenRandom(BCRYPT_RNG_ALG_HANDLE, reinterpret_cast<PUCHAR>(pBuf), uLen, 0) == 0)
#if !defined(BCRYPT_RNG_ALG_HANDLE)
#define BCRYPT_RNG_ALG_HANDLE ((BCRYPT_ALG_HANDLE) 0x00000081)
#endif
if (AuSwInfo::IsWindows10OrGreater() &&
::BCryptGenRandom(BCRYPT_RNG_ALG_HANDLE, reinterpret_cast<PUCHAR>(pBuf), uLen, 0) == 0)
{
return uLen;
}

View File

@ -19,7 +19,7 @@
#define WIN32_LEAN_AND_MEAN
#endif
//_WIN32_WINNT=0x0601
#define _WIN32_WINNT 0x0601
#include <SDKDDKVer.h>
#include <winsock2.h>

View File

@ -25,6 +25,24 @@
#include <Aux_ulib.h>
#endif
#if defined(AURORA_IS_MODERNNT_DERIVED)
BOOL (*SetThreadInformation_f)(
HANDLE hThread,
DWORD ThreadInformationClass,
LPVOID ThreadInformation,
DWORD ThreadInformationSize
);
static auto const kThreadPowerThrottling = 3;
struct THREAD_POWER_THROTTLING_STATE2
{
ULONG Version;
ULONG ControlMask;
ULONG StateMask;
};
#endif
#include "AuSpawnThread.hpp"
namespace Aurora
@ -798,7 +816,7 @@ namespace Aurora::Threading::Threads
SysPushErrorHAL("Couldn't update thread priority");
}
THREAD_POWER_THROTTLING_STATE throttlingState {};
THREAD_POWER_THROTTLING_STATE2 throttlingState {};
throttlingState.Version = THREAD_POWER_THROTTLING_CURRENT_VERSION;
switch (throttle)
@ -817,10 +835,13 @@ namespace Aurora::Threading::Threads
break;
}
SetThreadInformation(this->handle_,
ThreadPowerThrottling,
if (SetThreadInformation_f)
{
SetThreadInformation_f(this->handle_,
kThreadPowerThrottling,
&throttlingState,
sizeof(throttlingState));
}
//#elif defined(AURORA_IS_XNU_DERIVED)
@ -1159,6 +1180,11 @@ namespace Aurora::Threading::Threads
#if defined(AURORA_PLATFORM_WIN32)
AuxUlibInitialize();
#endif
#if defined(AURORA_IS_MODERNNT_DERIVED)
SetThreadInformation_f = AuReinterpretCast<decltype(SetThreadInformation_f)>(GetProcAddress(GetModuleHandleW(L"Kernel32.dll"), "SetThreadInformation"));
#endif
AttachSignalKiller();
}
}