[+] Initial HWInfo stat implementations

[+] General fixes and clean up
This commit is contained in:
Reece Wilson 2021-09-13 21:11:12 +01:00
parent 97f1ae087e
commit 5d18f3535c
54 changed files with 1049 additions and 316 deletions

View File

@ -9,6 +9,78 @@
namespace Aurora::HWInfo namespace Aurora::HWInfo
{ {
struct AUKN_SYM CpuId
{
bool SSE3();
bool PCLMULQDQ();
bool MONITOR();
bool SSSE3();
bool FMA();
bool CMPXCHG16B();
bool SSE41();
bool SSE42();
bool MOVBE();
bool POPCNT();
bool AES();
bool XSAVE();
bool OSXSAVE();
bool AVX();
bool F16C();
bool RDRAND();
bool MSR();
bool CX8();
bool SEP();
bool CMOV();
bool CLFSH();
bool MMX();
bool FXSR();
bool SSE();
bool SSE2();
bool FSGSBASE();
bool BMI1();
bool HLE();
bool AVX2();
bool BMI2();
bool ERMS();
bool INVPCID();
bool RTM();
bool AVX512F();
bool RDSEED();
bool ADX();
bool AVX512PF();
bool AVX512ER();
bool AVX512CD();
bool SHA();
bool PREFETCHWT1();
bool LAHF();
bool LZCNT();
bool ABM();
bool SSE4a();
bool XOP();
bool TBM();
bool SYSCALL();
bool MMXEXT();
bool RDTSCP();
bool _3DNOWEXT();
bool _3DNOW();
AuString vendor;
AuString brand;
bool isIntel;
bool isAMD;
AuUInt32 f_1_ECX;
AuUInt32 f_1_EDX;
AuUInt32 f_7_EBX;
AuUInt32 f_7_ECX;
AuUInt32 f_81_ECX;
AuUInt32 f_81_EDX;
};
struct CpuInfo struct CpuInfo
{ {
Aurora::Build::EArchitecture cpuArch; Aurora::Build::EArchitecture cpuArch;
@ -16,10 +88,8 @@ namespace Aurora::HWInfo
AuUInt8 socket; AuUInt8 socket;
AuUInt8 cores; AuUInt8 cores;
AuUInt8 threads; AuUInt8 threads;
AuUInt32 cpuId[4]; CpuId cpuId;
char vendor[12];
unsigned features;
}; };
AUKN_SYM const CpuInfo &GetCPUInfo(); AUKN_SYM const CpuInfo &GetCPUInfo();

View File

@ -9,7 +9,13 @@
namespace Aurora::HWInfo namespace Aurora::HWInfo
{ {
AUKN_SYM AuUInt32 GetRamAvailableMb(); struct RamStat
AUKN_SYM AuUInt32 GetRamStartupAvailableMb(); {
AUKN_SYM AuUInt32 GetRamTotalMb(); AuUInt64 used;
AuUInt64 available;
};
AUKN_SYM AuOptional<RamStat> GetMemStatProcess();
AUKN_SYM AuOptional<RamStat> GetMemStatSystem();
AUKN_SYM AuOptional<RamStat> GetMemStatStartup();
} }

View File

@ -7,7 +7,7 @@
***/ ***/
#pragma once #pragma once
namespace Aurora::IO::AFIO namespace Aurora::IO::FS
{ {
class IAsyncTransaction; class IAsyncTransaction;
@ -20,14 +20,14 @@ namespace Aurora::IO::AFIO
class IAsyncFinishedSubscriber class IAsyncFinishedSubscriber
{ {
public: public:
virtual OnAsyncFileOpFinished(AuUInt64 offset, AuUInt32 length) = 0; virtual void OnAsyncFileOpFinished(AuUInt64 offset, AuUInt32 length) = 0;
}; };
class IAsyncTransaction class IAsyncTransaction
{ {
public: public:
virtual void StartRead(AuUInt64 offset, void *, AuUInt32 length) = 0; virtual bool StartRead(AuUInt64 offset, void *, AuUInt32 length) = 0;
virtual void StartWrite(AuUInt64 offset, const void *, AuUInt32 length) = 0; virtual bool StartWrite(AuUInt64 offset, const void *, AuUInt32 length) = 0;
virtual bool Complete() = 0; virtual bool Complete() = 0;
virtual AuUInt32 GetLastPacketLength() = 0; virtual AuUInt32 GetLastPacketLength() = 0;
@ -37,7 +37,7 @@ namespace Aurora::IO::AFIO
virtual void Wait(AuUInt32 timeout) = 0; virtual void Wait(AuUInt32 timeout) = 0;
}; };
AUKN_SHARED_API(Open, IAsyncFileStream, const AuString &path, bool readOnly = true, bool directIO = false); AUKN_SHARED_API(OpenAsync, IAsyncFileStream, const AuString &path, bool readOnly = true, bool directIO = false);
AUKN_SHARED bool WaitMultiple(const AuList<IAsyncTransaction> &files, AuUInt32 timeout); AUKN_SYM bool WaitMultiple(const AuList<IAsyncTransaction> &files, AuUInt32 timeout);
} }

View File

@ -44,4 +44,5 @@ namespace Aurora::IO::FS
#include "FileReader.hpp" #include "FileReader.hpp"
#include "FileWriter.hpp" #include "FileWriter.hpp"
#include "Resources.hpp" #include "Resources.hpp"
#include "Stat.hpp" #include "Stat.hpp"
#include "Async.hpp"

View File

@ -1,7 +0,0 @@
/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: LSAsync.hpp
Date: 2021-8-21
Author: Reece
***/

View File

@ -1,7 +0,0 @@
/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: LSCV.hpp
Date: 2021-8-28
Author: Reece
***/

View File

@ -1,7 +0,0 @@
/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: LSEvent.hpp
Date: 2021-8-28
Author: Reece
***/

View File

@ -1,7 +0,0 @@
/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: LSFd.hpp
Date: 2021-8-21
Author: Reece
***/

View File

@ -1,7 +0,0 @@
/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: LSGlib.hpp
Date: 2021-8-21
Author: Reece
***/

View File

@ -1,7 +0,0 @@
/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: LSMutex.hpp
Date: 2021-8-28
Author: Reece
***/

View File

@ -1,7 +0,0 @@
/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: LSRWMutex.hpp
Date: 2021-8-21
Author: Reece
***/

View File

@ -1,7 +0,0 @@
/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: LSSemaphore.hpp
Date: 2021-8-28
Author: Reece
***/

View File

@ -1,7 +0,0 @@
/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: LSTimer.hpp
Date: 2021-8-21
Author: Reece
***/

View File

@ -1,7 +0,0 @@
/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: LSWin32.hpp
Date: 2021-8-21
Author: Reece
***/

View File

@ -1,7 +0,0 @@
/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: LSX11.hpp
Date: 2021-8-21
Author: Reece
***/

View File

@ -5,36 +5,108 @@
Date: 2021-8-21 Date: 2021-8-21
Author: Reece Author: Reece
***/ ***/
#pragma once
enum class ELoopSource namespace Aurora::Loop
{ {
eSourceInternalReserved1, enum class ELoopSource
eSourceInternalReserved2, {
eSourceInternalReserved3, eSourceInternalReserved1,
eSourceInternalReserved4, eSourceInternalReserved2,
eSourceInternalReserved3,
// unix only eSourceInternalReserved4,
eSourceFileDescriptor,
// generic
// generic eSourceSemaphore,
eSourceSemaphore, eSourceCV,
eSourceMutex, eSourceEvent,
eSourceTimer, eSourceMutex,
eSourceSRW,
// Specific to the runtime subsystem eSourceTimer,
eSourceAsync, eSourceHandle,
// glib oses only // Specific to the runtime subsystem
eSourceGlib, eSourceAsync,
// window messge loops // glib oses only
eSourceApple, eSourceGlib,
eSourceX11,
eSourceWin32 // window messge loops
}; eSourceApple,
eSourceX11,
eSourceWin32
};
class ILoopSource class ILoopSource
{ {
public:
virtual bool IsSignaled() = 0;
virtual ELoopSource GetType() = 0;
};
}; AUKN_SYM AuList<AuSPtr<ILoopSource>> WaitMultipleObjects(AuList<AuSPtr<ILoopSource>>, AuUInt32 timeout);
class ILSSemaphore : public ILoopSource
{
public:
virtual bool AddOne() = 0;
};
class ILSEvent : public ILoopSource
{
public:
virtual bool Reset() = 0;
};
class ILSMutex : public ILoopSource
{
public:
virtual bool Unlock() = 0;
};
class IConditionVar : public ILoopSource
{
public:
virtual bool Signal() = 0;
virtual bool Broadcast() = 0;
};
class ITimer : public ILoopSource
{
public:
virtual void UpdateTime(AuUInt64 absTimeMs) = 0;
};
AUKN_SYM AuSPtr<IConditionVar> NewLSCondVar(const AuSPtr<Aurora::Threading::> &primitive);
AUKN_SYM AuSPtr<IConditionVar> NewLSCondVar(const AuSPtr<ILSMutex> &source);
AUKN_SYM AuSPtr<ITimer> NewLSTimer(AuUInt64 absTimeMs);
AUKN_SYM AuSPtr<ILSMutex> NewLSMutex();
AUKN_SYM AuSPtr<ILSEvent> NewLSEvent(bool triggerd = false, bool atomicRelease = true, bool permitMultipleTriggers = false);
AUKN_SYM AuSPtr<ILSSemaphore> NewLSSemaphore(AuUInt32 initialCount = 0);
AUKN_SYM AuSPtr<ILoopSource> NewLSAsync();
AUKN_SYM AuSPtr<ILoopSource> NewLSWin32Source();
AUKN_SYM AuSPtr<ILoopSource> NewLSAppleSource();
AUKN_SYM AuSPtr<ILoopSource> NewLSOSHandle(AuUInt);
#if defined(X_PROTOCOL)
static AuSPtr<ILoopSource> NewLSX11(Display *display)
{
return NewLSOSHandle(ConnectionNumber(display));
}
#endif
#if defined(AURORA_IS_POSIX_DERIVED)
static AuSPtr<ILoopSource> NewLSFd(int fd)
{
return NewLSOSHandle(fd);
}
#endif
#if defined(AURORA_IS_MODERNNT_DERIVED)
static AuSPtr<ILoopSource> NewLSHandle(HANDLE handle)
{
return NewLSOSHandle(static_cast<AuUInt>(handle));
}
#endif
}

View File

@ -1,7 +0,0 @@
/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: Wait.hpp
Date: 2021-8-21
Author: Reece
***/

View File

@ -116,8 +116,8 @@ namespace Aurora
/// In conjunction with !enableStdPassthrough, enables stdout logging /// In conjunction with !enableStdPassthrough, enables stdout logging
bool enableStdIn {true}; bool enableStdIn {true};
/// In conjunction with enableStdPassthrough, enables Aurora::Console::WriteStd to write binary /// In conjunction with enableStdPassthrough, enables Aurora::Console::WriteStd to write binary, otherwise enables the console logger
/// In conjunction with !enableStdPassthrough, enables stdin logger /// In conjunction with !enableStdPassthrough, enables stdin cmd processing, otherwise disables stdin input
bool enableStdOut {true}; bool enableStdOut {true};
/// Use WxWidgets when possible /// Use WxWidgets when possible

View File

@ -34,5 +34,5 @@ namespace Aurora::Threading::Primitives
virtual void Set() = 0; virtual void Set() = 0;
}; };
AUKN_SHARED_API(Event, IEvent, bool triggerd, bool atomicRelease, bool permitMultipleTriggers = false); AUKN_SHARED_API(Event, IEvent, bool triggerd = false, bool atomicRelease = true, bool permitMultipleTriggers = false);
} }

View File

@ -473,4 +473,9 @@ struct is_base_of_template_impl_au
}; };
template < template <typename...> class base,typename derived> template < template <typename...> class base,typename derived>
using AuIsBaseOfTemplate = typename is_base_of_template_impl_au<base,derived>::type; using AuIsBaseOfTemplate = typename is_base_of_template_impl_au<base,derived>::type;
static inline bool AuTestBit(AuUInt32 value, AuUInt8 idx)
{
return value & (1 << idx);
}

View File

@ -14,9 +14,9 @@ namespace Aurora::Console::ConsoleFIO
static Threading::Primitives::RWLockUnique_t gLogMutex; static Threading::Primitives::RWLockUnique_t gLogMutex;
static IO::FS::OpenWriteUnique_t gFileHandle; static IO::FS::OpenWriteUnique_t gFileHandle;
static const auto & gLogConfig = gRuntimeConfig.console.fio; static const auto &gLogConfig = gRuntimeConfig.console.fio;
static AuString GetLogDirectory() AuString GetLogDirectory()
{ {
AuString path; AuString path;
AuString procName; AuString procName;
@ -70,7 +70,7 @@ namespace Aurora::Console::ConsoleFIO
AuList<AuString> files; AuList<AuString> files;
AuBST<AuString, IO::FS::Stat> fileMeta; AuBST<AuString, IO::FS::Stat> fileMeta;
AuUInt32 size {}; AuUInt32 size {};
auto baseLogPath = GetLogDirectory(); auto baseLogPath = GetLogDirectory();
IO::FS::FilesInDirectory(baseLogPath, files); IO::FS::FilesInDirectory(baseLogPath, files);
@ -113,10 +113,10 @@ namespace Aurora::Console::ConsoleFIO
static bool OpenLogFile() static bool OpenLogFile()
{ {
AuString path; AuString path;
auto tm = Time::ToCivilTime(Time::CurrentClockMS()); auto tm = Time::ToCivilTime(Time::CurrentClockMS());
path = fmt::format("{}/{:04}-{:02}-{:02}T{:02}-{:02}-{:02}Z.txt", path = fmt::format("{}/{:04}-{:02}-{:02}T{:02}-{:02}-{:02}Z.txt",
GetLogDirectory(), GetLogDirectory(),
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec); tm.tm_hour, tm.tm_min, tm.tm_sec);
@ -142,21 +142,21 @@ namespace Aurora::Console::ConsoleFIO
{ {
return; return;
} }
gLogMutex = Threading::Primitives::RWLockUnique(); gLogMutex = Threading::Primitives::RWLockUnique();
if (!gLogMutex) if (!gLogMutex)
{ {
return; return;
} }
Console::Hooks::AddFunctionalHook([&](const Console::ConsoleMessage &string) -> void Console::Hooks::AddFunctionalHook([&](const Console::ConsoleMessage &string) -> void
{ {
AU_LOCK_GUARD(gLogMutex->AsWritable()); AU_LOCK_GUARD(gLogMutex->AsWritable());
auto str = string.ToSimplified(); auto str = string.ToSimplified();
gLogBuffer.reserve(gLogBuffer.size() + str.size() + 2); gLogBuffer.reserve(gLogBuffer.size() + str.size() + 2);
gLogBuffer.insert(gLogBuffer.end(), reinterpret_cast<AuUInt8*>(str.data()), reinterpret_cast<AuUInt8*>(str.data()) + str.size()); gLogBuffer.insert(gLogBuffer.end(), reinterpret_cast<AuUInt8 *>(str.data()), reinterpret_cast<AuUInt8 *>(str.data()) + str.size());
#if defined(AURORA_IS_MODERNNT_DERIVED) #if defined(AURORA_IS_MODERNNT_DERIVED)
gLogBuffer.insert(gLogBuffer.end(), AuUInt8('\r')); gLogBuffer.insert(gLogBuffer.end(), AuUInt8('\r'));

View File

@ -13,5 +13,6 @@ namespace Aurora::Console::ConsoleFIO
void Pump(); void Pump();
void Exit(); void Exit();
void Flush(); void Flush();
AuString GetLogDirectory();
void FIOCleanup(); void FIOCleanup();
} }

View File

@ -77,6 +77,60 @@ namespace Aurora::Console::ConsoleStd
} }
#endif #endif
static void StartLogger()
{
if (gRuntimeConfig.console.enableStdPassthrough && gRuntimeConfig.console.enableStdOut)
{
return;
}
Console::Hooks::AddFunctionalHook([](const Aurora::Console::ConsoleMessage &string) -> void
{
#if (defined(DEBUG) || defined(STAGING)) && defined(AURORA_IS_MODERNNT_DERIVED)
auto debugLine = string.ToSimplified() + "\r\n";
OutputDebugStringW(Locale::ConvertFromUTF8(debugLine).c_str());
#endif
if (!gRuntimeConfig.console.enableStdOut)
{
return;
}
auto writeLine = string.ToConsole();
#if defined(AURORA_IS_MODERNNT_DERIVED)
writeLine += '\r';
#endif
writeLine += '\n';
#if defined(IO_POSIX_STREAMS)
if (Locale::GetInternalCodePage() == Locale::ECodePage::eUTF8)
{
WriteStdOut(writeLine.data(), writeLine.size());
}
else
{
AuString slow;
slow.resize(writeLine.size() * 4);
auto len = Locale::Encoding::EncodeUTF8(writeLine, reinterpret_cast<AuUInt8 *>(slow.data()), slow.size(), Locale::ECodePage::eSysUnk);
if (len.first != 0)
{
WriteStdOut(slow.data(), len.second);
}
else
{
// better write this than nothing
WriteStdOut(writeLine.data(), writeLine.size());
}
}
#elif defined(AURORA_IS_MODERNNT_DERIVED)
WriteStdOut(writeLine.data(), writeLine.size());
#endif
});
}
void Start() void Start()
{ {
static bool gConsoleStarted = false; static bool gConsoleStarted = false;
@ -126,7 +180,7 @@ namespace Aurora::Console::ConsoleStd
} }
} }
// Set binary mode if redirecting stdin to user
if (gRuntimeConfig.console.enableStdPassthrough && gRuntimeConfig.console.enableStdOut) if (gRuntimeConfig.console.enableStdPassthrough && gRuntimeConfig.console.enableStdOut)
{ {
SetConsoleMode(gOutputStream, 0); SetConsoleMode(gOutputStream, 0);
@ -149,10 +203,11 @@ namespace Aurora::Console::ConsoleStd
SysAssert(ok, "Couldn't maintain binary stdin stream"); SysAssert(ok, "Couldn't maintain binary stdin stream");
} }
} }
else
gTerminateConsole = CreateEvent(nullptr, true, false, nullptr); {
gTerminateConsole = CreateEvent(nullptr, true, false, nullptr);
gWin32Thread = CreateThread(nullptr, 0, StdInWin32Thread, nullptr, 0, nullptr); gWin32Thread = CreateThread(nullptr, 0, StdInWin32Thread, nullptr, 0, nullptr);
}
#elif defined(AURORA_IS_POSIX_DERIVED) #elif defined(AURORA_IS_POSIX_DERIVED)
@ -164,51 +219,7 @@ namespace Aurora::Console::ConsoleStd
SysAssert(gInputStream, "Couldn't allocate input stream handler"); SysAssert(gInputStream, "Couldn't allocate input stream handler");
SysAssert(gOutputStream, "Couldn't allocate output stream handler"); SysAssert(gOutputStream, "Couldn't allocate output stream handler");
Console::Hooks::AddFunctionalHook([](const Aurora::Console::ConsoleMessage &string) -> void StartLogger();
{
#if (defined(DEBUG) || defined(STAGING)) && defined(AURORA_IS_MODERNNT_DERIVED)
auto debugLine = string.ToSimplified() + "\r\n";
OutputDebugStringW(Locale::ConvertFromUTF8(debugLine).c_str());
#endif
if (!gRuntimeConfig.console.enableStdOut)
{
return;
}
auto writeLine = string.ToConsole();
#if defined(AURORA_IS_MODERNNT_DERIVED)
writeLine += '\r';
#endif
writeLine += '\n';
#if defined(IO_POSIX_STREAMS)
if (Locale::GetInternalCodePage() == Locale::ECodePage::eUTF8)
{
WriteStdOut(writeLine.data(), writeLine.size());
}
else
{
AuString slow;
slow.resize(writeLine.size() * 4);
auto len = Locale::Encoding::EncodeUTF8(writeLine, reinterpret_cast<AuUInt8 *>(slow.data()), slow.size(), Locale::ECodePage::eSysUnk);
if (len.first != 0)
{
WriteStdOut(slow.data(), len.second);
}
else
{
// better write this than nothing
WriteStdOut(writeLine.data(), writeLine.size());
}
}
#elif defined(AURORA_IS_MODERNNT_DERIVED)
WriteStdOut(writeLine.data(), writeLine.size());
#endif
});
} }
void Init() void Init()
@ -249,7 +260,6 @@ namespace Aurora::Console::ConsoleStd
} }
#endif #endif
Start(); Start();
} }
@ -289,7 +299,7 @@ namespace Aurora::Console::ConsoleStd
return (FD_ISSET(0, &fds)); return (FD_ISSET(0, &fds));
#elif defined(AURORA_IS_MODERNNT_DERIVED) #elif defined(AURORA_IS_MODERNNT_DERIVED)
// Inline non-blocking is not legal on windows. // Inline non-blocking is not legal on windows.
// One can force it with the overlapped flag, seemingly vaid since win8, but defined as illegal since the 90s // One can force it with the overlapped flag, seemingly valid since win8, but defined as illegal since the 90s
return false; return false;
#else #else
return false; return false;
@ -441,18 +451,23 @@ namespace Aurora::Console::ConsoleStd
static bool AsyncReadAnyOrReadStreamBlock() static bool AsyncReadAnyOrReadStreamBlock()
{ {
if (SyncReadConsole()) if (!SyncReadConsole())
{
return false;
}
if (gRuntimeConfig.console.enableStdPassthrough && gRuntimeConfig.console.enableStdIn)
{ {
ProcessLinesSysCP();
return true; return true;
} }
return false; ProcessLinesSysCP();
return true;
} }
void Pump() void Pump()
{ {
if (!gRuntimeConfig.console.enableStdIn) if (!gRuntimeConfig.console.enableStdPassthrough && !gRuntimeConfig.console.enableStdIn)
{ {
return; return;
} }

View File

@ -7,8 +7,15 @@
***/ ***/
#include <RuntimeInternal.hpp> #include <RuntimeInternal.hpp>
#include "ConsoleWxWidgets.hpp" #include "ConsoleWxWidgets.hpp"
#include <Console/ConsoleFIO/ConsoleFIO.hpp>
#if defined(_AUHAS_WXWIDGETS) #if defined(_AUHAS_WXWIDGETS)
#if defined(AURORA_PLATFORM_WIN32)
#include <Uxtheme.h>
#include <Extensions/Win32/DarkTheme.hpp>
#endif
#include <wx/wxprec.h> #include <wx/wxprec.h>
#include <wx/wx.h> #include <wx/wx.h>
@ -16,8 +23,6 @@
#include <wx/wx.h> #include <wx/wx.h>
#include <wx/richtext/richtextctrl.h> #include <wx/richtext/richtextctrl.h>
static bool DarkModeEnabled();
class ConsoleFrame; class ConsoleFrame;
static AuList<Aurora::Console::ConsoleMessage> gPendingLines; static AuList<Aurora::Console::ConsoleMessage> gPendingLines;
@ -86,6 +91,8 @@ private:
void OnExit(wxCommandEvent &event); void OnExit(wxCommandEvent &event);
void OnAbout(wxCommandEvent &event); void OnAbout(wxCommandEvent &event);
void OnBugWrite(wxCommandEvent &event); void OnBugWrite(wxCommandEvent &event);
void OnIssueWrite(wxCommandEvent &event);
void OpenLogDir(wxCommandEvent &event);
void OnInit(wxWindowCreateEvent &event); void OnInit(wxWindowCreateEvent &event);
void OnShow(wxWindowCreateEvent &event); void OnShow(wxWindowCreateEvent &event);
void OnCmd(wxCommandEvent &event); void OnCmd(wxCommandEvent &event);
@ -97,9 +104,6 @@ private:
wxDECLARE_EVENT_TABLE(); wxDECLARE_EVENT_TABLE();
wxRichTextCtrl *richtextbox_; wxRichTextCtrl *richtextbox_;
wxTextCtrl *commandbox_; wxTextCtrl *commandbox_;
wxMenuBar *menuBar_;
wxBoxSizer *sizer_;
AuList<WxSplitterLine *> _splitters;
wxTimer timer_; wxTimer timer_;
}; };
@ -107,15 +111,18 @@ enum
{ {
ID_Hello = 1, ID_Hello = 1,
ID_BLACKBOX, ID_BLACKBOX,
ID_WRITE_REPORT, ID_WRITE_CARD,
ID_OPENTXT, ID_WRITE_BUG,
ID_OPEN_LOG_DIR,
ID_OPENBIN ID_OPENBIN
}; };
wxBEGIN_EVENT_TABLE(ConsoleFrame, wxFrame) wxBEGIN_EVENT_TABLE(ConsoleFrame, wxFrame)
EVT_MENU(ID_Hello, ConsoleFrame::OnHello) EVT_MENU(ID_Hello, ConsoleFrame::OnHello)
EVT_MENU(wxID_EXIT, ConsoleFrame::OnExit) EVT_MENU(wxID_EXIT, ConsoleFrame::OnExit)
EVT_MENU(wxID_ABOUT, ConsoleFrame::OnAbout) EVT_MENU(wxID_ABOUT, ConsoleFrame::OnAbout)
EVT_MENU(ID_WRITE_REPORT, ConsoleFrame::OnBugWrite) EVT_MENU(ID_WRITE_CARD, ConsoleFrame::OnIssueWrite)
EVT_MENU(ID_WRITE_BUG, ConsoleFrame::OnBugWrite)
EVT_MENU(ID_OPEN_LOG_DIR, ConsoleFrame::OpenLogDir)
EVT_WINDOW_CREATE(ConsoleFrame::OnInit) EVT_WINDOW_CREATE(ConsoleFrame::OnInit)
wxEND_EVENT_TABLE() wxEND_EVENT_TABLE()
@ -147,16 +154,12 @@ void ConsoleFrame::OnCmd(wxCommandEvent &event)
WxSplitterLine *ConsoleFrame::NewSplitter(wxSize splitter, wxColor color) WxSplitterLine *ConsoleFrame::NewSplitter(wxSize splitter, wxColor color)
{ {
auto re = new WxSplitterLine(splitter, color, this, -1); return new WxSplitterLine(splitter, color, this, -1);
_splitters.push_back(re);
return re;
} }
WxSplitterLine *ConsoleFrame::NewSplitter(wxSize splitter) WxSplitterLine *ConsoleFrame::NewSplitter(wxSize splitter)
{ {
auto re = new WxSplitterLine(splitter, {}, this, -1); return new WxSplitterLine(splitter, {}, this, -1);
_splitters.push_back(re);
return re;
} }
void ConsoleFrame::WriteLine(const Aurora::Console::ConsoleMessage &string) void ConsoleFrame::WriteLine(const Aurora::Console::ConsoleMessage &string)
@ -197,7 +200,7 @@ void ConsoleFrame::WriteLine(const Aurora::Console::ConsoleMessage &string)
auto writeLine = string.ToSimplified(); auto writeLine = string.ToSimplified();
bool useColor = DarkModeEnabled(); bool useColor = true;// DarkModeEnabled();
auto color = useColor ? ColorMap[static_cast<int>(string.color)] : wxColor(0, 0, 0); auto color = useColor ? ColorMap[static_cast<int>(string.color)] : wxColor(0, 0, 0);
auto bold = useColor ? HahaBald[static_cast<int>(string.color)] : false; auto bold = useColor ? HahaBald[static_cast<int>(string.color)] : false;
@ -250,7 +253,7 @@ ConsoleFrame::ConsoleFrame(const wxString &title, const wxPoint &pos, const wxSi
: wxFrame(NULL, wxID_ANY, title, pos, size) : wxFrame(NULL, wxID_ANY, title, pos, size)
{ {
#if defined(AURORA_PLATFORM_WIN32) #if defined(AURORA_PLATFORM_WIN32)
bool useWin32DarkHack = DarkModeEnabled(); bool useWin32DarkHack = Aurora::Extensions::Win32::g_darkModeSupported;
#else #else
bool useWin32DarkHack = false; bool useWin32DarkHack = false;
#endif #endif
@ -262,6 +265,7 @@ ConsoleFrame::ConsoleFrame(const wxString &title, const wxPoint &pos, const wxSi
// \ V V / (_| | | | (__| | | | | | | | | __/\__ \ | (_| | | | | __/ (_| | (_| | |_| |_| |_| |_| // \ V V / (_| | | | (__| | | | | | | | | __/\__ \ | (_| | | | | __/ (_| | (_| | |_| |_| |_| |_|
// \_/\_/ \__,_|_| \___|_| |_|_| |_| |_|\___||___/ \__,_|_| |_|\___|\__,_|\__,_| (_) (_) (_) (_) // \_/\_/ \__,_|_| \___|_| |_|_| |_| |_|\___||___/ \__,_|_| |_|\___|\__,_|\__,_| (_) (_) (_) (_)
// //
//
static const auto kEnableDark = (useWin32DarkHack) || static const auto kEnableDark = (useWin32DarkHack) ||
@ -286,17 +290,16 @@ ConsoleFrame::ConsoleFrame(const wxString &title, const wxPoint &pos, const wxSi
// 1080, 550 // 1080, 550
this->SetClientSize(this->FromDIP(wxSize(903, 434))); this->SetClientSize(this->FromDIP(wxSize(903, 434)));
menuBar_ = _new wxMenuBar(); auto menuBar_ = _new wxMenuBar();
if (!menuBar_) return; if (!menuBar_) return;
{ {
auto menuFile = _new wxMenu(); auto menuFile = _new wxMenu();
if (!menuFile) return; if (!menuFile) return;
menuFile->Append(wxID_SAVE, "Export text log"); menuFile->Append(wxID_SAVE, "Export text log");
menuFile->AppendSeparator(); menuFile->AppendSeparator();
menuFile->Append(ID_OPENTXT, "Open text log"); menuFile->Append(ID_OPEN_LOG_DIR, "Open log directory");
menuFile->Append(ID_OPENBIN, "Open binary log");
menuBar_->Append(menuFile, "&Logs"); menuBar_->Append(menuFile, "&Logs");
} }
@ -306,8 +309,10 @@ ConsoleFrame::ConsoleFrame(const wxString &title, const wxPoint &pos, const wxSi
if (!menuHelp) return; if (!menuHelp) return;
menuHelp->Append(ID_BLACKBOX, "&Report application state to the black box"); menuHelp->Append(ID_BLACKBOX, "&Report application state to the black box");
menuHelp->Append(ID_WRITE_REPORT, "&[Internal] Write a bug report"); #if defined(STAGING) || defined(DEBUG)
menuHelp->Append(ID_WRITE_REPORT, "&[Public] Write a bug report"); menuHelp->Append(ID_WRITE_CARD, "&[Internal] Write a bug report");
#endif
menuHelp->Append(ID_WRITE_BUG, "&[Public] Write a bug report");
menuBar_->Append(menuHelp, "&Bugs"); menuBar_->Append(menuHelp, "&Bugs");
} }
@ -317,8 +322,8 @@ ConsoleFrame::ConsoleFrame(const wxString &title, const wxPoint &pos, const wxSi
this->Connect(wxEVT_SHOW, wxWindowCreateEventHandler(ConsoleFrame::OnShow)); this->Connect(wxEVT_SHOW, wxWindowCreateEventHandler(ConsoleFrame::OnShow));
} }
sizer_ = _new wxBoxSizer(wxVERTICAL); auto sizer = _new wxBoxSizer(wxVERTICAL);
if (!sizer_) return; if (!sizer) return;
auto font = this->GetFont(); auto font = this->GetFont();
font.SetPointSize(9); font.SetPointSize(9);
@ -334,12 +339,12 @@ ConsoleFrame::ConsoleFrame(const wxString &title, const wxPoint &pos, const wxSi
if (!filterBarContainer) return {}; if (!filterBarContainer) return {};
auto filterBar = _new wxBoxSizer(wxHORIZONTAL); auto filterBar = _new wxBoxSizer(wxHORIZONTAL);
if (!filterBar) return{}; if (!filterBar) return{}; // TODO: a leak idc about
auto filterBox = _new wxTextCtrl(this, -1, wxEmptyString, auto filterBox = _new wxTextCtrl(this, -1, wxEmptyString,
wxDefaultPosition, alt ? wxDefaultSize : wxSize(400, 20), wxDefaultPosition, alt ? wxDefaultSize : wxSize(400, 20),
(kTextBoxHandlePad ? wxBORDER_NONE : 0) | wxTE_PROCESS_ENTER | wxEXPAND); (kTextBoxHandlePad ? wxBORDER_NONE : 0) | wxTE_PROCESS_ENTER | wxEXPAND);
if (!filterBox) return{}; if (!filterBox) return{}; // TODO: a leak idc about
filterBox->SetMinSize({minx, miny}); filterBox->SetMinSize({minx, miny});
@ -502,14 +507,14 @@ ConsoleFrame::ConsoleFrame(const wxString &title, const wxPoint &pos, const wxSi
addHeaderPanel(header, checkboxesContainer, true, true, false, true, kHeaderPadUpDown, kHeaderPadLeftRight); addHeaderPanel(header, checkboxesContainer, true, true, false, true, kHeaderPadUpDown, kHeaderPadLeftRight);
} }
sizer_->Add(header, 0, wxEXPAND); sizer->Add(header, 0, wxEXPAND);
// Shadow down // Shadow down
if (/*useWin32DarkHack*/ true) if (/*useWin32DarkHack*/ true)
{ {
sizer_->Add(NewSplitter(wxSize(kTextboxWin32PadInner, kTextboxWin32PadInner), kTextBoxInner), 0, wxEXPAND); sizer->Add(NewSplitter(wxSize(kTextboxWin32PadInner, kTextboxWin32PadInner), kTextBoxInner), 0, wxEXPAND);
sizer_->Add(NewSplitter(wxSize(kTextboxWin32PadOutter, kTextboxWin32PadOutter), kTextBoxOutter), 0, wxEXPAND); sizer->Add(NewSplitter(wxSize(kTextboxWin32PadOutter, kTextboxWin32PadOutter), kTextBoxOutter), 0, wxEXPAND);
} }
// Rich text box // Rich text box
@ -526,25 +531,25 @@ ConsoleFrame::ConsoleFrame(const wxString &title, const wxPoint &pos, const wxSi
this->Connect(wxEVT_SHOW, wxWindowCreateEventHandler(ConsoleFrame::OnShow)); this->Connect(wxEVT_SHOW, wxWindowCreateEventHandler(ConsoleFrame::OnShow));
} }
sizer_->Add(richtextbox_, 1, wxEXPAND); sizer->Add(richtextbox_, 1, wxEXPAND);
} }
// Shadow down // Shadow down
if (/*useWin32DarkHack*/ true) if (/*useWin32DarkHack*/ true)
{ {
sizer_->Add(NewSplitter(wxSize(kTextboxWin32PadInner, kTextboxWin32PadInner), kTextBoxInner), 0, wxEXPAND); sizer->Add(NewSplitter(wxSize(kTextboxWin32PadInner, kTextboxWin32PadInner), kTextBoxInner), 0, wxEXPAND);
sizer_->Add(NewSplitter(wxSize(kTextboxWin32PadOutter, kTextboxWin32PadOutter), kTextBoxOutter), 0, wxEXPAND); sizer->Add(NewSplitter(wxSize(kTextboxWin32PadOutter, kTextboxWin32PadOutter), kTextBoxOutter), 0, wxEXPAND);
} }
// Command Box // Command Box
{ {
commandbox_ = addTextbox(sizer_, 0, kTextboxHeight, true); commandbox_ = addTextbox(sizer, 0, kTextboxHeight, true);
commandbox_->SetHint("Type a command here"); commandbox_->SetHint("Type a command here");
commandbox_->Connect(wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler(ConsoleFrame::OnCmd)); commandbox_->Connect(wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler(ConsoleFrame::OnCmd));
} }
SetSizer(sizer_); SetSizer(sizer);
SetMenuBar(menuBar_); SetMenuBar(menuBar_);
// SetAutoLayout(true); // SetAutoLayout(true);
@ -553,23 +558,16 @@ ConsoleFrame::ConsoleFrame(const wxString &title, const wxPoint &pos, const wxSi
gWxConsoleReady = true; gWxConsoleReady = true;
} }
#if defined(AURORA_PLATFORM_WIN32)
#include <Uxtheme.h>
#include <Extensions/Win32/DarkTheme.hpp>
static bool DarkModeEnabled()
{
return Aurora::Extensions::Win32::g_darkModeSupported;
}
void ConsoleFrame::OnInit(wxWindowCreateEvent &event) void ConsoleFrame::OnInit(wxWindowCreateEvent &event)
{ {
OnShow(event); OnShow(event);
} }
#if defined(AURORA_PLATFORM_WIN32)
void ConsoleFrame::OnShow(wxWindowCreateEvent &event) void ConsoleFrame::OnShow(wxWindowCreateEvent &event)
{ {
if (!DarkModeEnabled()) return; if (!Aurora::Extensions::Win32::g_darkModeSupported) return;
auto handle = event.GetWindow()->GetHWND(); auto handle = event.GetWindow()->GetHWND();
Aurora::Extensions::Win32::AllowDarkModeForWindow(handle, true); Aurora::Extensions::Win32::AllowDarkModeForWindow(handle, true);
@ -584,9 +582,6 @@ ConsoleFrame::ConsoleFrame(const wxString &title, const wxPoint &pos, const wxSi
UpdateWindow(handle); UpdateWindow(handle);
} }
#else #else
void ConsoleFrame::OnInit(wxWindowCreateEvent &event)
{}
void ConsoleFrame::OnShow(wxWindowCreateEvent &event) void ConsoleFrame::OnShow(wxWindowCreateEvent &event)
{} {}
@ -610,12 +605,22 @@ void ConsoleFrame::OnHello(wxCommandEvent &event)
{ {
LogGame("nani?!"); LogGame("nani?!");
} }
void ConsoleFrame::OnBugWrite(wxCommandEvent &event) void ConsoleFrame::OnBugWrite(wxCommandEvent &event)
{
Aurora::Processes::OpenUri(gRuntimeConfig.console.supportPublic);
}
void ConsoleFrame::OnIssueWrite(wxCommandEvent &event)
{ {
Aurora::Processes::OpenUri(gRuntimeConfig.console.supportInternal); Aurora::Processes::OpenUri(gRuntimeConfig.console.supportInternal);
} }
void ConsoleFrame::OpenLogDir(wxCommandEvent &event)
{
Aurora::Processes::OpenFile(Aurora::Console::ConsoleFIO::GetLogDirectory());
}
namespace Aurora::Console::ConsoleWxWidgets namespace Aurora::Console::ConsoleWxWidgets
{ {
static void WxWidgetsPump(); static void WxWidgetsPump();

View File

@ -21,38 +21,46 @@ namespace Aurora::Crypto::PEM
str.reserve(src.size()); str.reserve(src.size());
Parse::SplitNewlines(src, Parse::SplitNewlines(src,
[&](const AuString &src) [&](const AuString &src)
{
if (lines == 0)
{ {
fail |= (int)(src != begin); if (lines == 0)
lines++; {
return; fail |= (int)(src != begin);
} lines++;
return;
}
if (src == end) if (src == end)
{ {
fail |= (int)!Parse::Base64Decode(str, buf); fail |= (int)!Parse::Base64Decode(str, buf);
finished = true; finished = true;
return; return;
} }
str += src; str += src;
}); }
);
return fail ? false : finished; return fail ? false : finished;
} }
static AuString SerializePEM(const AuString &begin, const AuString &end, const AuList<AuUInt8> &buf) static AuString SerializePEM(const AuString &begin, const AuString &end, const AuList<AuUInt8> &buf)
{ {
auto delm = Aurora::Build::kCurrentVendor == Aurora::Build::EVendor::eGenericMicrosoft ? "\r\n" : "\n";
AuString ret; AuString ret;
ret += begin; ret += begin;
ret += '\n'; ret += delm;
AuString b64; AuString b64;
if (!Parse::Base64Encode(buf, b64)) if (!Parse::Base64Encode(buf, b64))
{
return ""; return "";
}
else
{
b64 = Parse::SplitStringDelm(b64, delm, 16);
}
ret += b64; ret += b64;
ret += '\n'; ret += delm;
ret += end; ret += end;
return ret; return ret;
} }

View File

@ -17,6 +17,7 @@
#include "Hashing/Hashing.hpp" #include "Hashing/Hashing.hpp"
#include "Debug/Debug.hpp" #include "Debug/Debug.hpp"
#include "Async/Async.hpp" #include "Async/Async.hpp"
#include "HWInfo/HWInfo.hpp"
#if defined(AURORA_PLATFORM_WIN32) #if defined(AURORA_PLATFORM_WIN32)
#include "Extensions/Win32/DarkTheme.hpp" #include "Extensions/Win32/DarkTheme.hpp"
#endif #endif
@ -37,6 +38,7 @@ static void Init()
Aurora::RNG::Init(); Aurora::RNG::Init();
Aurora::Hashing::InitHashing(); Aurora::Hashing::InitHashing();
Aurora::Async::InitAsync(); Aurora::Async::InitAsync();
Aurora::HWInfo::Init();
} }
static void Pump() static void Pump()

View File

@ -23,7 +23,7 @@ int rsa_basic_export(unsigned char *out, unsigned long *outlen, const rsa_key *k
if (key->type == PK_PUBLIC) if (key->type == PK_PUBLIC)
{ {
return CRYPT_INVALID_ARG; return CRYPT_INVALID_ARG;
}; }
/* private key */ /* private key */
/* output is /* output is
@ -110,7 +110,7 @@ int rsa_pkcs8_export(unsigned char *out, unsigned long *outlen, const rsa_key *k
if (key->type == PK_PUBLIC) if (key->type == PK_PUBLIC)
{ {
return CRYPT_INVALID_ARG; return CRYPT_INVALID_ARG;
}; }
void *keyType; void *keyType;

View File

@ -9,3 +9,458 @@
#include "HWInfo.hpp" #include "HWInfo.hpp"
#include "CpuInfo.hpp" #include "CpuInfo.hpp"
#if defined(AURORA_IS_BSD_DERIVED)
#include <sys/types.h>
#include <sys/sysctl.h>
#endif
namespace Aurora::HWInfo
{
static CpuInfo gCpuInfo;
union CPUIdContext
{
struct
{
AuUInt32 eax;
AuUInt32 ebx;
AuUInt32 ecx;
AuUInt32 edx;
};
int regs[4];
};
#if defined(AURORA_ARCH_X64) || defined(AURORA_ARCH_X86)
#if defined(AURORA_COMPILER_MSVC)
static inline CPUIdContext cpuid(AuUInt32 a)
{
CPUIdContext context;
__cpuid(context.regs, a);
return context;
}
#elif defined(AURORA_COMPILER_CLANG) || defined(AURORA_COMPILER_GCC)
static inline CPUIdContext cpuid(AuUInt32 a)
{
CPUIdContext context;
__get_cpuid(a, &context.eax, &context.ebx, &context.ecx, &context.edx);
return context;
}
#else
static inline CPUIdContext cpuid(AuUInt32 a)
{
return {};
}
#endif
#else
static inline CPUIdContext cpuid(AuUInt32 a)
{
return {};
}
#endif
bool CpuId::SSE3()
{
return AuTestBit(f_1_ECX, 0);
}
bool CpuId::PCLMULQDQ()
{
return AuTestBit(f_1_ECX, 1);
}
bool CpuId::MONITOR()
{
return AuTestBit(f_1_ECX, 3);
}
bool CpuId::SSSE3()
{
return AuTestBit(f_1_ECX, 9);
}
bool CpuId::FMA()
{
return AuTestBit(f_1_ECX, 12);
}
bool CpuId::CMPXCHG16B()
{
return AuTestBit(f_1_ECX, 13);
}
bool CpuId::SSE41()
{
return AuTestBit(f_1_ECX, 19);
}
bool CpuId::SSE42()
{
return AuTestBit(f_1_ECX, 20);
}
bool CpuId::MOVBE()
{
return AuTestBit(f_1_ECX, 22);
}
bool CpuId::POPCNT()
{
return AuTestBit(f_1_ECX, 23);
}
bool CpuId::AES()
{
return AuTestBit(f_1_ECX, 25);
}
bool CpuId::XSAVE()
{
return AuTestBit(f_1_ECX, 26);
}
bool CpuId::OSXSAVE()
{
return AuTestBit(f_1_ECX, 27);
}
bool CpuId::AVX()
{
return AuTestBit(f_1_ECX, 28);
}
bool CpuId::F16C()
{
return AuTestBit(f_1_ECX, 29);
}
bool CpuId::RDRAND()
{
return AuTestBit(f_1_ECX, 30);
}
bool CpuId::MSR()
{
return AuTestBit(f_1_EDX, 5);
}
bool CpuId::CX8()
{
return AuTestBit(f_1_EDX, 8);
}
bool CpuId::SEP()
{
return AuTestBit(f_1_EDX, 11);
}
bool CpuId::CMOV()
{
return AuTestBit(f_1_EDX, 15);
}
bool CpuId::CLFSH()
{
return AuTestBit(f_1_EDX, 19);
}
bool CpuId::MMX()
{
return AuTestBit(f_1_EDX, 23);
}
bool CpuId::FXSR()
{
return AuTestBit(f_1_EDX, 24);
}
bool CpuId::SSE()
{
return AuTestBit(f_1_EDX, 25);
}
bool CpuId::SSE2()
{
return AuTestBit(f_1_EDX, 26);
}
bool CpuId::FSGSBASE()
{
return AuTestBit(f_7_EBX, 0);
}
bool CpuId::BMI1()
{
return AuTestBit(f_7_EBX, 3);
}
bool CpuId::HLE()
{
return AuTestBit(isIntel && f_7_EBX, 4);
}
bool CpuId::AVX2()
{
return AuTestBit(f_7_EBX, 5);
}
bool CpuId::BMI2()
{
return AuTestBit(f_7_EBX, 8);
}
bool CpuId::ERMS()
{
return AuTestBit(f_7_EBX, 9);
}
bool CpuId::INVPCID()
{
return AuTestBit(f_7_EBX, 10);
}
bool CpuId::RTM()
{
return AuTestBit(isIntel && f_7_EBX, 11);
}
bool CpuId::AVX512F()
{
return AuTestBit(f_7_EBX, 16);
}
bool CpuId::RDSEED()
{
return AuTestBit(f_7_EBX, 18);
}
bool CpuId::ADX()
{
return AuTestBit(f_7_EBX, 19);
}
bool CpuId::AVX512PF()
{
return AuTestBit(f_7_EBX, 26);
}
bool CpuId::AVX512ER()
{
return AuTestBit(f_7_EBX, 27);
}
bool CpuId::AVX512CD()
{
return AuTestBit(f_7_EBX, 28);
}
bool CpuId::SHA()
{
return AuTestBit(f_7_EBX, 29);
}
bool CpuId::PREFETCHWT1()
{
return AuTestBit(f_7_ECX, 0);
}
bool CpuId::LAHF()
{
return AuTestBit(f_81_ECX, 0);
}
bool CpuId::LZCNT()
{
return AuTestBit(isIntel && f_81_ECX, 5);
}
bool CpuId::ABM()
{
return AuTestBit(isAMD && f_81_ECX, 5);
}
bool CpuId::SSE4a()
{
return AuTestBit(isAMD && f_81_ECX, 6);
}
bool CpuId::XOP()
{
return AuTestBit(isAMD && f_81_ECX, 11);
}
bool CpuId::TBM()
{
return AuTestBit(isAMD && f_81_ECX, 21);
}
bool CpuId::SYSCALL()
{
return AuTestBit(isIntel && f_81_EDX, 11);
}
bool CpuId::MMXEXT()
{
return AuTestBit(isAMD && f_81_EDX, 22);
}
bool CpuId::RDTSCP()
{
return AuTestBit(isIntel && f_81_EDX, 27);
}
bool CpuId::_3DNOWEXT()
{
return AuTestBit(isAMD && f_81_EDX, 30);
}
bool CpuId::_3DNOW()
{
return AuTestBit(isAMD && f_81_EDX, 31);
}
AUKN_SYM const CpuInfo &GetCPUInfo()
{
return gCpuInfo;
}
static void SetCpuId()
{
// Credit: https://docs.microsoft.com/en-us/cpp/intrinsics/cpuid-cpuidex?view=msvc-160
#if defined(AURORA_ARCH_X64) || defined(AURORA_ARCH_X86)
std::vector<CPUIdContext> data;
std::vector<CPUIdContext> extdata;
auto cpuInfo = cpuid(0);
auto nIds = cpuInfo.eax;
for (int i = 0; i <= nIds; ++i)
{
data.push_back(cpuid(i));
}
char vendor[0x20];
memset(vendor, 0, sizeof(vendor));
*reinterpret_cast<int*>(vendor) = cpuInfo.ebx;
*reinterpret_cast<int*>(vendor + 4) = cpuInfo.edx;
*reinterpret_cast<int*>(vendor + 8) = cpuInfo.ecx;
gCpuInfo.cpuId.vendor = vendor;
if (gCpuInfo.cpuId.vendor == "GenuineIntel")
{
gCpuInfo.cpuId.isIntel = true;
}
else if (gCpuInfo.cpuId.vendor == "AuthenticAMD")
{
gCpuInfo.cpuId.isAMD = true;
}
// load bitset with flags for function 0x00000001
if (nIds >= 1)
{
gCpuInfo.cpuId.f_1_ECX = data[1].ecx;
gCpuInfo.cpuId.f_1_EDX = data[1].edx;
}
// load bitset with flags for function 0x00000007
if (nIds >= 7)
{
gCpuInfo.cpuId.f_7_EBX = data[7].ebx;
gCpuInfo.cpuId.f_7_ECX = data[7].ecx;
}
// gets the number of the highest valid extended ID.
auto cpui = cpuid(0x80000000);
auto nExIds = cpui.eax;
char brand[0x40];
memset(brand, 0, sizeof(brand));
for (int i = 0x80000000; i <= nExIds; ++i)
{
extdata.push_back(cpuid(i));
}
// load bitset with flags for function 0x80000001
if (nExIds >= 0x80000001)
{
gCpuInfo.cpuId.f_81_ECX = extdata[1].ecx;
gCpuInfo.cpuId.f_81_EDX = extdata[1].edx;
}
// Interpret CPU brand string if reported
if (nExIds >= 0x80000004)
{
memcpy(brand, &extdata[2], sizeof(cpui));
memcpy(brand + 16, &extdata[3], sizeof(cpui));
memcpy(brand + 32, &extdata[4], sizeof(cpui));
gCpuInfo.cpuId.brand = brand;
}
#endif
}
static void SetCpuTopology()
{
#if defined(AURORA_IS_MODERNNT_DERIVED)
SYSTEM_LOGICAL_PROCESSOR_INFORMATION sysinfo[128];
DWORD length = AuArraySize(sysinfo) * sizeof(*sysinfo);
if (!GetLogicalProcessorInformation(sysinfo, &length))
{
SYSTEM_INFO sysinfo;
GetSystemInfo(&sysinfo);
gCpuInfo.socket = 1;
gCpuInfo.cores = 1;
gCpuInfo.threads = sysinfo.dwNumberOfProcessors;
return;
}
length /= sizeof(*sysinfo);
gCpuInfo.socket = 0;
gCpuInfo.cores = 0;
gCpuInfo.threads = 0;
for (auto i = 0; i < length; i++)
{
if (sysinfo[i].Relationship == RelationProcessorCore)
{
gCpuInfo.cores++;
auto mask = sysinfo[i].ProcessorMask;
unsigned long offset, count;
BitScanForward(&offset, mask);
BitScanForward(&count, ~(mask >> offset));
gCpuInfo.threads += count;
}
else if (sysinfo[i].Relationship == RelationProcessorPackage)
{
gCpuInfo.socket++;
}
}
#elif defined(AURORA_IS_BSD_DERIVED)
auto opt = QueryBsdHwStat(HW_AVAILCPU);
if (opt.value_or(0) < 1)
{
opt = QueryBsdHwStat(HW_NCPU);
}
gCpuInfo.socket = 1;
gCpuInfo.cores = 1;
gCpuInfo.threads = opt.value_or(1)
#elif defined(AURORA_IS_POSIX_DERIVED)
gCpuInfo.socket = 1;
gCpuInfo.cores = 1;
gCpuInfo.threads = sysconf(_SC_NPROCESSORS_ONLN);
#endif
}
void InitCpuInfo()
{
gCpuInfo.cpuArch = Aurora::Build::kCurrentArchitecture;
SetCpuId();
SetCpuTopology();
}
}

View File

@ -7,3 +7,7 @@
***/ ***/
#pragma once #pragma once
namespace Aurora::HWInfo
{
void InitCpuInfo();
}

42
Source/HWInfo/HWInfo.cpp Normal file
View File

@ -0,0 +1,42 @@
/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: HWInfo.hpp
Date: 2021-6-19
Author: Reece
***/
#include <RuntimeInternal.hpp>
#include "HWInfo.hpp"
#include "CpuInfo.hpp"
#include "RamInfo.hpp"
#if defined(AURORA_IS_BSD_DERIVED)
#include <sys/types.h>
#include <sys/sysctl.h>
#endif
namespace Aurora::HWInfo
{
AuOptional<AuUInt> QueryBsdHwStat(int id)
{
#if defined(AURORA_IS_BSD_DERIVED)
int mib[4];
AuUInt stat;
size_t len = sizeof(stat);
mib[0] = CTL_HW;
mib[1] = id;
auto ret = sysctl(mib, 2, &stat, &len, NULL, 0);
return ret == 0 ? stat : {};
#else
return {};
#endif
}
void Init()
{
InitCpuInfo();
InitRamInfo();
}
}

View File

@ -5,3 +5,10 @@
Date: 2021-6-19 Date: 2021-6-19
Author: Reece Author: Reece
***/ ***/
#pragma once
namespace Aurora::HWInfo
{
AuOptional<AuUInt> QueryBsdHwStat(int id);
void Init();
}

View File

@ -1,7 +0,0 @@
/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: RamInfo.Linux.cpp
Date: 2021-6-12
Author: Reece
***/

View File

@ -1,7 +0,0 @@
/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: RamInfo.Linux.hpp
Date: 2021-6-12
Author: Reece
***/

View File

@ -1,12 +0,0 @@
/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: RamInfo.Win32.cpp
Date: 2021-6-12
Author: Reece
***/
#include <RuntimeInternal.hpp>
#include "HWInfo.hpp"
#include "RamInfo.hpp"
#include "RamInfo.Win32.hpp"

View File

@ -1,9 +0,0 @@
/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: RamInfo.Win32.hpp
Date: 2021-6-12
Author: Reece
***/
#pragma once

127
Source/HWInfo/RamInfo.cpp Normal file
View File

@ -0,0 +1,127 @@
/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: RamInfo.cpp
Date: 2021-6-12
Author: Reece
***/
#include <RuntimeInternal.hpp>
#include "HWInfo.hpp"
#include "RamInfo.hpp"
#if defined(AURORA_IS_BSD_DERIVED)
#include <sys/sysctl.h>
#include <sys/vmmeter.h>
#include <sys/limits.h>
#include <vm/vm_param.h>
#endif
#if defined(AURORA_IS_LINUX_DERIVED)
#include <sys/sysinfo.h>
#endif
#if defined(AURORA_IS_MODERNNT_DERIVED)
#include <psapi.h>
#endif
namespace Aurora::HWInfo
{
static AuOptional<RamStat> gMemStartup;
static AuOptional<RamStat> gMemSystem;
AUKN_SYM AuOptional<RamStat> GetMemStatProcess()
{
auto max = GetMemStatSystem().value_or(RamStat {}).available;
#if defined(AURORA_IS_MODERNNT_DERIVED)
PROCESS_MEMORY_COUNTERS pmc;
if (!GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(PROCESS_MEMORY_COUNTERS)))
{
return {};
}
return RamStat {pmc.WorkingSetSize, max};
#elif defined(AURORA_IS_POSIX_DERIVED)
struct rusage usage;
getrusage(RUSAGE_SELF, &usage);
auto used = AuUInt64(usage.ru_maxrss) * 1024;
return RamStat {used, max};
#else
return {};
#endif
}
#if defined(AURORA_IS_BSD_DERIVED)
struct vmtotal GetVMInfo()
{
struct vmtotal info;
int mib[2];
mib[0] = CTL_VM;
mib[1] = VM_TOTAL;
size_t len = sizeof(info);
sysctl(mib, 2, &info, &len, NULL, 0);
return info;
}
#endif
AUKN_SYM AuOptional<RamStat> GetMemStatSystem()
{
#if defined(AURORA_IS_MODERNNT_DERIVED)
MEMORYSTATUSEX statex;
statex.dwLength = sizeof(statex);
if (!GlobalMemoryStatusEx(&statex))
{
return {};
}
return RamStat {statex.ullTotalPhys - statex.ullAvailPhys, statex.ullTotalPhys};
#elif defined(AURORA_IS_BSD_DERIVED)
auto maxMem = QueryBsdHwStat(HW_PHYSMEM);
auto vmInfo = GetVMInfo();
auto freeMem = AuUInt64(vmInfo.t_free) * QueryBsdHwStat(HW_PAGESIZE).value_or(4096);
return RamStat {maxMem.value_or(freeMem * 2) - freeMem, maxMem.value_or(0)};
#elif defined(AURORA_IS_LINUX_DERIVED)
struct sysinfo info;
if (sysinfo(&info) != 0)
{
return {};
}
return RamStat {info.totalram - info.freeram, info.totalram}
#else
return {};
#endif
}
AUKN_SYM AuOptional<RamStat> GetMemStatStartup()
{
return gMemStartup;
}
void InitRamInfo()
{
gMemStartup = GetMemStatSystem();
}
}

View File

@ -5,3 +5,9 @@
Date: 2021-6-12 Date: 2021-6-12
Author: Reece Author: Reece
***/ ***/
#pragma once
namespace Aurora::HWInfo
{
void InitRamInfo();
}

View File

View File

View File

View File

View File

View File

@ -13,7 +13,7 @@
#if !defined(_AURUNTIME_GENERICFS) #if !defined(_AURUNTIME_GENERICFS)
namespace Aurora::IO::FS namespace Aurora::IO::FS
{ {
static const AuUInt64 kFileCopyBlock = 0x4000; // 16KiB static const AuUInt64 kFileCopyBlock = 0xFFFF; // 64KiB
bool _MkDir(const AuString &str) bool _MkDir(const AuString &str)
{ {
@ -91,7 +91,7 @@ namespace Aurora::IO::FS
status = true; status = true;
out: out:
if (fileHandle != INVALID_HANDLE_VALUE) CloseHandle(fileHandle); AuWin32CloseHandle(fileHandle);
return status; return status;
} }
@ -145,7 +145,7 @@ namespace Aurora::IO::FS
status = true; status = true;
out: out:
if (fileHandle != INVALID_HANDLE_VALUE) CloseHandle(fileHandle); AuWin32CloseHandle(fileHandle);
return status; return status;
} }

View File

@ -13,7 +13,7 @@
namespace Aurora::IO::FS namespace Aurora::IO::FS
{ {
static const AuUInt64 kFileCopyBlock = 0x4000; // 16KiB static const AuUInt64 kFileCopyBlock = 0xFFFF; // 64KiB, 1k iterations to max out 64MB/s disk, 2k iteration to make out 128MB/s disk, is this number still way too low? cpu go brr
WinFileStream::~WinFileStream() WinFileStream::~WinFileStream()
{ {
@ -160,12 +160,7 @@ namespace Aurora::IO::FS
void WinFileStream::Close() void WinFileStream::Close()
{ {
HANDLE handle; AuWin32CloseHandle(handle_);
if ((handle = std::exchange(handle_, INVALID_HANDLE_VALUE)) != INVALID_HANDLE_VALUE)
{
CloseHandle(handle);
}
} }
void WinFileStream::Flush() void WinFileStream::Flush()

0
Source/Loop/Loop.cpp Normal file
View File

0
Source/Loop/Loop.hpp Normal file
View File

View File

@ -105,8 +105,8 @@ namespace Aurora::Parse
bool escapedQuote = false; bool escapedQuote = false;
auto isTerminating = IsTerminating(state, terminatingChars); auto isTerminating = IsTerminating(state, terminatingChars);
auto isSpace = ContainedHerein(whiteChars); static auto isSpace = ContainedHerein(whiteChars);
auto isIgnore = ContainedHerein(illegalCharacters); static auto isIgnore = ContainedHerein(illegalCharacters);
while (true) while (true)
{ {
@ -251,7 +251,10 @@ namespace Aurora::Parse
{ {
auto c = *itr; auto c = *itr;
if ((c < '0') || (c > '9')) return false; if ((c < '0') || (c > '9'))
{
return false;
}
auto old = res; auto old = res;
@ -374,11 +377,11 @@ namespace Aurora::Parse
} }
case ParsableTag::kParseBoolean: case ParsableTag::kParseBoolean:
{ {
if (str == "0" || (stricmp(str.c_str(), "false") == 0) || (stricmp(str.c_str(), "no") == 0)) if ((str == "0") || (stricmp(str.c_str(), "false") == 0) || (stricmp(str.c_str(), "no") == 0))
{ {
out.primitive.boolean = false; out.primitive.boolean = false;
} }
else if (str == "1" || (stricmp(str.c_str(), "true") == 0) || (stricmp(str.c_str(), "yes") == 0)) else if ((str == "1") || (stricmp(str.c_str(), "true") == 0) || (stricmp(str.c_str(), "yes") == 0))
{ {
out.primitive.boolean = true; out.primitive.boolean = true;
} }

View File

@ -2,7 +2,7 @@
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved. Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: Paths.cpp File: Paths.cpp
Date: 2021-6-12 Date: 2021-7-14
Author: Reece Author: Reece
***/ ***/
#include <RuntimeInternal.hpp> #include <RuntimeInternal.hpp>

View File

@ -1,3 +1,10 @@
/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: Process.cpp
Date: 2021-8-20
Author: Reece
***/
#include <RuntimeInternal.hpp> #include <RuntimeInternal.hpp>
#include "Process.hpp" #include "Process.hpp"
#if defined(AURORA_IS_POSIX_DERIVED) #if defined(AURORA_IS_POSIX_DERIVED)

View File

@ -1,3 +1,10 @@
/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: Process.hpp
Date: 2021-8-20
Author: Reece
***/
#pragma once #pragma once
namespace Aurora::Process namespace Aurora::Process

View File

@ -1,3 +1,10 @@
/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: RandomDevice.cpp
Date: 2021-9-3
Author: Reece
***/
#include <AuroraRuntime.hpp> #include <AuroraRuntime.hpp>
#include "RNG/WELL.hpp" #include "RNG/WELL.hpp"
#include "RandomDevice.hpp" #include "RandomDevice.hpp"

View File

@ -1,3 +1,10 @@
/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: RandomDevice.hpp
Date: 2021-9-3
Author: Reece
***/
#pragma once #pragma once
namespace Aurora::RNG namespace Aurora::RNG

View File

@ -496,7 +496,7 @@ namespace Aurora::Threading::Threads
return; return;
} }
if (prio == ThreadPrio::kPrioAboveHigh) if (prio == EThreadPrio::ePrioRT)
{ {
sched_param param {}; sched_param param {};
param.sched_priority = sched_get_priority_min(SCHED_RR); param.sched_priority = sched_get_priority_min(SCHED_RR);