diff --git a/Include/Aurora/Async/WorkPairImpl.hpp b/Include/Aurora/Async/WorkPairImpl.hpp index f47ab5c9..0f76e71b 100644 --- a/Include/Aurora/Async/WorkPairImpl.hpp +++ b/Include/Aurora/Async/WorkPairImpl.hpp @@ -12,6 +12,8 @@ namespace Aurora::Threading::Primitives class SpinLoop; } +#include + namespace Aurora::Async { struct BasicWorkStdFunc; @@ -29,7 +31,7 @@ namespace Aurora::Async /// @hideinitializer template, typename Job_t = FJob> - struct WorkPairImpl : IWorkItemHandler, std::enable_shared_from_this + struct WorkPairImpl : IWorkItemHandler, AuEnableSharedFromThis { WorkPairImpl() : caller_(Async::GetCurrentWorkerPId()) {} @@ -120,7 +122,6 @@ namespace Aurora::Async } auto pin = AuSharedFromThis(); - AuFunction func = [pin]() { try diff --git a/Include/Aurora/Memory/ExtendStlLikeSharedPtr.hpp b/Include/Aurora/Memory/ExtendStlLikeSharedPtr.hpp new file mode 100644 index 00000000..a45ae753 --- /dev/null +++ b/Include/Aurora/Memory/ExtendStlLikeSharedPtr.hpp @@ -0,0 +1,101 @@ +/*** + Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved. + + File: ExtendStlLikeSharedPtr.hpp + Date: 2022-1-25 + Author: Reece +***/ +#pragma once + +namespace Aurora::Memory +{ + template + struct ExSharedPtr : public Base_t + { + bool cached {}; + + using element_type = Base_t::element_type; + using weak_type = Base_t::weak_type; + using base_type = Base_t; + using Base_t::Base_t; + + ExSharedPtr(Base_t &&in) : Base_t(in) + {} + ExSharedPtr(const Base_t &in) : Base_t(in) + {} + + operator Base_t() const noexcept + { + return *this; + } + + ExSharedPtr &operator =(const Base_t &in) noexcept + { + Base_t::operator=(in); + return *this; + } + + TType_t &operator*() const + { + throwif(); + return Base_t::operator*(); + } + + TType_t *operator->() const + { + throwif(); + return Base_t::operator->(); + } + + TType_t &operator*() + { + throwif(); + return Base_t::operator*(); + } + + TType_t *operator->() + { + throwif(); + return Base_t::operator->(); + } + + private: + + auline void _cache() + { + cached = Base_t::operator bool(); + } + + auline void throwif() const + { + if (!cached) [[unlikely]] + { + if (!Base_t::operator bool()) [[likely]] + { + AU_THROW_STRING("ExSharedPointer Null Access Violation"); + } + } + } + + auline void throwif() + { + if (!cached) [[unlikely]] + { + cached = Base_t::operator bool(); + if (!cached) [[likely]] + { + AU_THROW_STRING("ExSharedPointer Null Access Violation"); + } + } + } + }; + + template + struct ExSharedFromThis : Base_t + { + ExSharedPtr> SharedFromThis() + { + return Base_t::shared_from_this(); + } + }; +} \ No newline at end of file diff --git a/Include/Aurora/Processes/IProcess.hpp b/Include/Aurora/Processes/IProcess.hpp index cacdf512..edaeafd9 100644 --- a/Include/Aurora/Processes/IProcess.hpp +++ b/Include/Aurora/Processes/IProcess.hpp @@ -26,6 +26,8 @@ namespace Aurora::Processes /// otherwise returns zero virtual AuSInt GetExitCode() = 0; + virtual AuUInt GetProcessId() = 0; + /// // TODO(Reece): what in the hell this is ugly virtual bool Start(enum ESpawnType, bool fwdOut, bool fwdErr, bool fwdIn) = 0; diff --git a/Include/Aurora/Runtime.hpp b/Include/Aurora/Runtime.hpp index 79a07d16..4a43c8b5 100644 --- a/Include/Aurora/Runtime.hpp +++ b/Include/Aurora/Runtime.hpp @@ -17,6 +17,9 @@ #endif #endif +#include +#include + #include #include #include @@ -29,17 +32,21 @@ #include #include "../AuroraTypedefs.hpp" + +#define _ALLOW_AURORA_ENUM_AUENVHPP +#include + #include "../AuroraUtils.hpp" #if defined(_AUHAS_FMT) -#include -#include -#include -#include + #include + #include + #include + #include #endif #if !defined(_AUHAS_UUID) -#error Missing stduuid library + #error Missing stduuid library #endif #include @@ -72,6 +79,7 @@ #include "Async/Async.hpp" #include "Processes/Processes.hpp" #include "Loop/Loop.hpp" +#include "SWInfo/SWInfo.hpp" #include "Memory/_ByteBuffer.hpp" diff --git a/Include/Aurora/SWInfo/SWInfo.hpp b/Include/Aurora/SWInfo/SWInfo.hpp index e69de29b..b51e63df 100644 --- a/Include/Aurora/SWInfo/SWInfo.hpp +++ b/Include/Aurora/SWInfo/SWInfo.hpp @@ -0,0 +1,56 @@ +/*** + Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved. + + File: SWInfo.hpp + Date: 2022-1-25 + Author: Reece +***/ +#pragma once + +namespace Aurora::SWInfo +{ + struct OSInformation + { + // I tried to make these references, but benji the retard decided that objects and functions should hold constantness, not the data + // Returning a const reference to a struct containing const references, keeping the ability to move, and disabling copy -> impossible + // Nice tardlang + + const AuString *kKernelString; // + const AuString *kUserlandBrand; // Windows 10 Pro, Xbox, glibc, Ubuntu, distro name + const AuString *kUserlandDesktopEnv; // DWM, CF, [kwin/etc] + const AuString *kBuildString; // Example: (`Linux version wtf-doxing-lts (no-lts@fingerprinterinos) (some things here) #1 SMP Mon, 69 Apr 2000 13:33:37 +0000`, `??7??.?.amd64???.rs?_release.??-??`) + + AuUInt32 uKernelMajor {}; + AuUInt32 uKernelMinor {}; + AuUInt32 uKernelPatch {}; + + AuUInt32 uUserlandMajor {}; + AuUInt32 uUserlandMinor {}; + AuUInt32 uUserlandPatch {}; + + bool bIsServer {}; + bool bIsEnterprise {}; + + Aurora::Build::EPlatform ePlatform = Aurora::Build::EPlatform::eEnumInvalid; + + private: + static inline AuString _kIgnore {}; + + public: + + OSInformation() : kKernelString(&_kIgnore), kUserlandDesktopEnv(&_kIgnore), kUserlandBrand(&_kIgnore), kBuildString(&_kIgnore), ePlatform(Build::EPlatform::eEnumInvalid) + {} + + AU_DEFINE_CTOR_VA(OSInformation, ( + kKernelString, + kUserlandBrand, + kUserlandDesktopEnv, + kBuildString, + ePlatform + )) + AU_NO_COPY(OSInformation); + AU_MOVE(OSInformation); + }; + + AUKN_SYM const OSInformation & GetPlatformInfo(); +} \ No newline at end of file diff --git a/Include/Aurora/Time/ETimezoneShift.hpp b/Include/Aurora/Time/ETimezoneShift.hpp index b272edaf..90eb723d 100644 --- a/Include/Aurora/Time/ETimezoneShift.hpp +++ b/Include/Aurora/Time/ETimezoneShift.hpp @@ -9,9 +9,8 @@ namespace Aurora::Time { - enum ETimezoneShift - { + AUE_DEFINE(ETimezoneShift, ( eUTC, eLocalTime - }; + )) } \ No newline at end of file diff --git a/Include/AuroraMacros.hpp b/Include/AuroraMacros.hpp index ccee8db5..b1d77e64 100644 --- a/Include/AuroraMacros.hpp +++ b/Include/AuroraMacros.hpp @@ -7,22 +7,28 @@ ***/ #pragma once -#define AU_NO_COPY(type) type(type&) = delete; +#define AU_COPY(type) type(const type&) = default; type &operator=(const type &) = default; +#define AU_MOVE(type) type(type&&) = default; type &operator=(type &&) = default; + +#define AU_COPY_MOVE(type) AU_COPY(type) AU_MOVE(type) + +#define AU_NO_COPY(type) type(const type&) = delete; #define AU_NO_MOVE(type) type(type&&) = delete; #define AU_NO_COPY_NO_MOVE(type) AU_NO_COPY(type) AU_NO_MOVE(type) + #if !defined(AU_SHARED_FROM_THIS) - #define AU_SHARED_FROM_THIS (AuStaticPointerCast>(this->shared_from_this())) + #define AU_SHARED_FROM_THIS (AuStaticPointerCast>(this->SharedFromThis())) #endif #if !defined(AU_WEAK_FROM_THIS) - #define AU_WEAK_FROM_THIS (AuWPtr>(AuStaticPointerCast>(this->shared_from_this()))) + #define AU_WEAK_FROM_THIS (AuWPtr>(AuStaticPointerCast>(this->SharedFromThis()))) #endif #define AU_BRACKET_SCOPE(...) __VA_ARGS__ #if !defined(AU_TEMPLATE_ENABLE_WHEN) - #define AU_TEMPLATE_ENABLE_WHEN(...) typename std::enable_if<__VA_ARGS__>::type* = nullptr + #define AU_TEMPLATE_ENABLE_WHEN(...) typename AuEnableIf<__VA_ARGS__>::type* = nullptr #endif #define AU_WHAT(n) n @@ -145,10 +151,10 @@ #define AU_ITR_N_TO_X AU_ITERATE_N_TO_X #define AU_ITR_BACKWARDS AU_ITERATE_BACKWARDS -#define AU_STRIP_BRACKETS_IMPL(X) X +#define AU_STRIP_BRACKETS_IMPL(...) __VA_ARGS__ #if !defined(AU_STRIP_BRACKETS) - #define AU_STRIP_BRACKETS(X) AU_STRIP_BRACKETS_IMPL(AU_BRACKET_SCOPE X) + #define AU_STRIP_BRACKETS(X) AU_WHAT(AU_STRIP_BRACKETS_IMPL X) #endif #if !defined(AU_STRIP) @@ -179,12 +185,48 @@ #define AuWeakFromThis() AU_SHARED_FROM_THIS #endif -#define AU_DEFINE_CTOR_ONE(thisType, pairTypeName) \ - inline thisType(AU_EMIT_FIRST pairTypeName && AU_EMIT_SECOND pairTypeName) : AU_EMIT_SECOND pairTypeName (AU_EMIT_SECOND pairTypeName) {} \ - inline thisType(const AU_EMIT_FIRST pairTypeName & AU_EMIT_SECOND pairTypeName) : AU_EMIT_SECOND pairTypeName (AU_EMIT_SECOND pairTypeName) {} +#define AU_EMIT_FIRST_COMMA_FIRST(n)n +#define AU_EMIT_FIRST_COMMA_OTHERS(n),n -#define AU_DEFINE_CTOR_TWO(thisType, pairTypeName, pairTypeName2) \ - inline thisType(AU_EMIT_FIRST pairTypeName && AU_EMIT_SECOND pairTypeName, AU_EMIT_FIRST pairTypeName2 && AU_EMIT_SECOND pairTypeName2) : AU_EMIT_SECOND pairTypeName (AU_EMIT_SECOND pairTypeName), AU_EMIT_SECOND pairTypeName2 (AU_EMIT_SECOND pairTypeName2) {} \ - inline thisType(const AU_EMIT_FIRST pairTypeName & AU_EMIT_SECOND pairTypeName, AU_EMIT_FIRST pairTypeName2 && AU_EMIT_SECOND pairTypeName2) : AU_EMIT_SECOND pairTypeName (AU_EMIT_SECOND pairTypeName), AU_EMIT_SECOND pairTypeName2 (AU_EMIT_SECOND pairTypeName2) {} \ - inline thisType(AU_EMIT_FIRST pairTypeName && AU_EMIT_SECOND pairTypeName, const AU_EMIT_FIRST pairTypeName2 & AU_EMIT_SECOND pairTypeName2) : AU_EMIT_SECOND pairTypeName (AU_EMIT_SECOND pairTypeName), AU_EMIT_SECOND pairTypeName2 (AU_EMIT_SECOND pairTypeName2) {} \ - inline thisType(const AU_EMIT_FIRST pairTypeName & AU_EMIT_SECOND pairTypeName, const AU_EMIT_FIRST pairTypeName2 & AU_EMIT_SECOND pairTypeName2) : AU_EMIT_SECOND pairTypeName (AU_EMIT_SECOND pairTypeName), AU_EMIT_SECOND pairTypeName2 (AU_EMIT_SECOND pairTypeName2) {} \ No newline at end of file +/// @hideinitializer +#define AU_EMIT_FIRST_TYPEREDUCED_PAIR_REDUCED(variable) AuRemoveConst_t> + + +/// @hideinitializer +#define AU_EMIT_CTOR_CPY(pair) const AU_EMIT_FIRST_TYPEREDUCED_PAIR_REDUCED(pair) &pair +/// @hideinitializer +#define AU_EMIT_CTOR_CPY_SECOND(pair) ,AU_EMIT_CTOR_CPY(pair) + + +/// @hideinitializer +#define AU_EMIT_CTOR_MOV(pair) AU_EMIT_FIRST_TYPEREDUCED_PAIR_REDUCED(pair) &&pair +/// @hideinitializer +#define AU_EMIT_CTOR_MOV_SECOND(pair) ,AU_EMIT_CTOR_MOV(pair) + + +/// @hideinitializer +#define AU_EMIT_CTOR_ASSIGN(pair) pair(pair) +/// @hideinitializer +#define AU_EMIT_CTOR_ASSIGN_SECOND(pair) ,AU_EMIT_CTOR_ASSIGN(pair) + + +/// @hideinitializer +#define AU_DEFINE_CTOR_CPY_VA(thisType, args) \ +inline thisType(AU_FOR_EACH_FIRST(AU_EMIT_CTOR_CPY, AU_EMIT_CTOR_CPY_SECOND, AU_STRIP_BRACKETS(args))) : AU_FOR_EACH_FIRST(AU_EMIT_CTOR_ASSIGN, AU_EMIT_CTOR_ASSIGN_SECOND, AU_STRIP_BRACKETS(args)) \ +{} + +/// @hideinitializer +#define AU_DEFINE_CTOR_MOV_VA(thisType, args) \ +inline thisType(AU_FOR_EACH_FIRST(AU_EMIT_CTOR_MOV, AU_EMIT_CTOR_MOV_SECOND, AU_STRIP_BRACKETS(args))) : AU_FOR_EACH_FIRST(AU_EMIT_CTOR_ASSIGN, AU_EMIT_CTOR_ASSIGN_SECOND, AU_STRIP_BRACKETS(args)) \ +{} + +/// @hideinitializer +#define AU_DEFINE_CTOR_VA_(thisType, args) AU_DEFINE_CTOR_CPY_VA(thisType, args) AU_DEFINE_CTOR_MOV_VA(thisType, args) + + +/// @deprecated +#define AU_DEFINE_CTOR_ONE(thisType, pairTypeName) AU_DEFINE_CTOR_VA_(thisType, (AU_EMIT_SECOND pairTypeName)) + + +/// +#define AU_DEFINE_CTOR_VA(thisType, args) AU_DEFINE_CTOR_CPY_VA(thisType, args) AU_DEFINE_CTOR_MOV_VA(thisType, args) \ No newline at end of file diff --git a/Include/AuroraRuntime.hpp b/Include/AuroraRuntime.hpp index cc22c7ce..fad2011b 100644 --- a/Include/AuroraRuntime.hpp +++ b/Include/AuroraRuntime.hpp @@ -5,5 +5,4 @@ Date: 2021-6-9 Author: Reece ***/ -#include #include "Aurora/Runtime.hpp" \ No newline at end of file diff --git a/Include/AuroraTypedefs.hpp b/Include/AuroraTypedefs.hpp index a863a451..d6c5ec62 100644 --- a/Include/AuroraTypedefs.hpp +++ b/Include/AuroraTypedefs.hpp @@ -158,6 +158,19 @@ constexpr AuRemoveReference_t &&AuMove(T &&arg) noexcept return static_cast &&>(arg); } +template struct AuRemoveConst +{ + typedef T type; +}; + +template struct AuRemoveConst +{ + typedef T type; +}; + +template +using AuRemoveConst_t = typename AuRemoveConst::type; + template struct AuEnableIf { @@ -263,9 +276,6 @@ using AuBSTEx = AURORA_RUNTIME_AU_BST; #define AURORA_RUNTIME_AU_SHARED_PTR std::shared_ptr #endif -template -using AuSPtr = AURORA_RUNTIME_AU_SHARED_PTR; - #if !defined(AURORA_RUNTIME_AU_WEAK_PTR) #define AURORA_RUNTIME_AU_WEAK_PTR std::weak_ptr #endif @@ -277,16 +287,34 @@ using AuWPtr = AURORA_RUNTIME_AU_WEAK_PTR; #define AURORA_RUNTIME_AU_UNIQUE_PTR std::unique_ptr #endif -template -using AuUPtr = AURORA_RUNTIME_AU_UNIQUE_PTR; #if !defined(AURORA_RUNTIME_AU_DEFAULT_DELETER) #define AURORA_RUNTIME_AU_DEFAULT_DELETER std::default_delete #endif + template using AuDefaultDeleter = AURORA_RUNTIME_AU_DEFAULT_DELETER; + +#include + +template +using AuSPtr = typename Aurora::Memory::ExSharedPtr>; + +template +using AuUPtr = AURORA_RUNTIME_AU_UNIQUE_PTR; + +#if !defined(AU_AuEnableSharedFromThis) +#define AU_AuEnableSharedFromThis + +template +struct AuEnableSharedFromThis : Aurora::Memory::ExSharedFromThis> +{}; + +#endif + + template AuSPtr AuStaticPointerCast(const AuSPtr &other) noexcept { diff --git a/Source/Async/ThreadPool.hpp b/Source/Async/ThreadPool.hpp index 800c714a..cad036ce 100644 --- a/Source/Async/ThreadPool.hpp +++ b/Source/Async/ThreadPool.hpp @@ -23,7 +23,7 @@ namespace Aurora::Async }; - struct ThreadPool : public IThreadPool, public IThreadPoolInternal, std::enable_shared_from_this + struct ThreadPool : public IThreadPool, public IThreadPoolInternal, AuEnableSharedFromThis { ThreadPool(); diff --git a/Source/Async/WorkItem.hpp b/Source/Async/WorkItem.hpp index cc7315b9..2f2cac25 100644 --- a/Source/Async/WorkItem.hpp +++ b/Source/Async/WorkItem.hpp @@ -11,7 +11,7 @@ namespace Aurora::Async { - class WorkItem : public IWorkItem, public IAsyncRunnable, public std::enable_shared_from_this + class WorkItem : public IWorkItem, public IAsyncRunnable, public AuEnableSharedFromThis { public: WorkItem(IThreadPoolInternal *owner, const WorkerId_t &worker_, const AuSPtr &task_, bool supportsBlocking); diff --git a/Source/Entrypoint.cpp b/Source/Entrypoint.cpp index c6e89af0..9198d5b3 100644 --- a/Source/Entrypoint.cpp +++ b/Source/Entrypoint.cpp @@ -21,6 +21,7 @@ #include "HWInfo/HWInfo.hpp" #include "Telemetry/Telemetry.hpp" #include "Threading/Threads/OSThread.hpp" +#include "SWInfo/SWInfo.hpp" #if defined(AURORA_PLATFORM_WIN32) #include "Extensions/Win32/DarkTheme.hpp" #endif @@ -44,6 +45,7 @@ static void Init() Aurora::Hashing::InitHashing(); Aurora::Async::InitAsync(); Aurora::HWInfo::Init(); + Aurora::SWInfo::InitSwInfo(); Aurora::Telemetry::Init(); Aurora::Process::InitProcessMap(); } diff --git a/Source/HWInfo/CpuId.cpp b/Source/HWInfo/CpuId.cpp new file mode 100644 index 00000000..5086293c --- /dev/null +++ b/Source/HWInfo/CpuId.cpp @@ -0,0 +1,400 @@ +/*** + Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved. + + File: CpuId.cpp + Date: 2022-1-25 + Author: Reece +***/ +#include +#include "HWInfo.hpp" +#include "CpuId.hpp" + +#if defined(AURORA_COMPILER_CLANG) || defined(AURORA_IS_POSIX_DERIVED) + #include +#endif + +#include "CPUInfo.hpp" + +namespace Aurora::HWInfo +{ + 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 CPUIdContext cpuid(AuUInt32 a) + { + CPUIdContext context; + __cpuid(context.regs, a); + return context; + } + #elif defined(AURORA_COMPILER_CLANG) || defined(AURORA_COMPILER_GCC) + static CPUIdContext cpuid(AuUInt32 a) + { + CPUIdContext context; + __get_cpuid(a, &context.eax, &context.ebx, &context.ecx, &context.edx); + return context; + } + #else + static CPUIdContext cpuid(AuUInt32 a) + { + return {}; + } + #endif +#else + static 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 isIntel && AuTestBit(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 isIntel && AuTestBit(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 isIntel && AuTestBit(f_81_ECX, 5); + } + + bool CpuId::ABM() + { + return isAMD && AuTestBit(f_81_ECX, 5); + } + + bool CpuId::SSE4a() + { + return isAMD && AuTestBit(f_81_ECX, 6); + } + + bool CpuId::XOP() + { + return isAMD && AuTestBit(f_81_ECX, 11); + } + + bool CpuId::TBM() + { + return isAMD && AuTestBit(f_81_ECX, 21); + } + + bool CpuId::SYSCALL() + { + return isIntel && AuTestBit(f_81_EDX, 11); + } + + bool CpuId::MMXEXT() + { + return isAMD && AuTestBit(f_81_EDX, 22); + } + + bool CpuId::RDTSCP() + { + return isIntel && AuTestBit(f_81_EDX, 27); + } + + bool CpuId::_3DNOWEXT() + { + return isAMD && AuTestBit(f_81_EDX, 30); + } + + bool CpuId::_3DNOW() + { + return isAMD && AuTestBit(f_81_EDX, 31); + } + + AUKN_SYM const CpuInfo &GetCPUInfo() + { + return gCpuInfo; + } + + 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) + AuList data; + AuList extdata; + + auto cpuInfo = cpuid(0); + auto nIds = cpuInfo.eax; + + for (int i = 0; i <= nIds; ++i) + { + data.push_back(cpuid(i)); + } + + char vendor[0x20]; + AuMemset(vendor, 0, sizeof(vendor)); + *reinterpret_cast(vendor) = cpuInfo.ebx; + *reinterpret_cast(vendor + 4) = cpuInfo.edx; + *reinterpret_cast(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]; + AuMemset(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) + { + AuMemcpy(brand, &extdata[2], sizeof(cpui)); + AuMemcpy(brand + 16, &extdata[3], sizeof(cpui)); + AuMemcpy(brand + 32, &extdata[4], sizeof(cpui)); + gCpuInfo.cpuId.brand = brand; + } + #endif + } +} \ No newline at end of file diff --git a/Source/HWInfo/CpuId.hpp b/Source/HWInfo/CpuId.hpp new file mode 100644 index 00000000..0c5a366b --- /dev/null +++ b/Source/HWInfo/CpuId.hpp @@ -0,0 +1,13 @@ +/*** + Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved. + + File: CpuId.hpp + Date: 2022-1-25 + Author: Reece +***/ +#pragma once + +namespace Aurora::HWInfo +{ + void SetCpuId(); +} \ No newline at end of file diff --git a/Source/HWInfo/CpuInfo.cpp b/Source/HWInfo/CpuInfo.cpp index bb3ed816..2838e4d2 100644 --- a/Source/HWInfo/CpuInfo.cpp +++ b/Source/HWInfo/CpuInfo.cpp @@ -8,6 +8,7 @@ #include #include "HWInfo.hpp" #include "CpuInfo.hpp" +#include "CpuId.hpp" #if defined(AURORA_IS_BSD_DERIVED) #include @@ -27,391 +28,9 @@ #include #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 CPUIdContext cpuid(AuUInt32 a) - { - CPUIdContext context; - __cpuid(context.regs, a); - return context; - } - #elif defined(AURORA_COMPILER_CLANG) || defined(AURORA_COMPILER_GCC) - static CPUIdContext cpuid(AuUInt32 a) - { - CPUIdContext context; - __get_cpuid(a, &context.eax, &context.ebx, &context.ecx, &context.edx); - return context; - } - #else - static CPUIdContext cpuid(AuUInt32 a) - { - return {}; - } - #endif -#else - static 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 isIntel && AuTestBit(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 isIntel && AuTestBit(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 isIntel && AuTestBit(f_81_ECX, 5); - } - - bool CpuId::ABM() - { - return isAMD && AuTestBit(f_81_ECX, 5); - } - - bool CpuId::SSE4a() - { - return isAMD && AuTestBit(f_81_ECX, 6); - } - - bool CpuId::XOP() - { - return isAMD && AuTestBit(f_81_ECX, 11); - } - - bool CpuId::TBM() - { - return isAMD && AuTestBit(f_81_ECX, 21); - } - - bool CpuId::SYSCALL() - { - return isIntel && AuTestBit(f_81_EDX, 11); - } - - bool CpuId::MMXEXT() - { - return isAMD && AuTestBit(f_81_EDX, 22); - } - - bool CpuId::RDTSCP() - { - return isIntel && AuTestBit(f_81_EDX, 27); - } - - bool CpuId::_3DNOWEXT() - { - return isAMD && AuTestBit(f_81_EDX, 30); - } - - bool CpuId::_3DNOW() - { - return isAMD && AuTestBit(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) - AuList data; - AuList extdata; - - auto cpuInfo = cpuid(0); - auto nIds = cpuInfo.eax; - - for (int i = 0; i <= nIds; ++i) - { - data.push_back(cpuid(i)); - } - - char vendor[0x20]; - AuMemset(vendor, 0, sizeof(vendor)); - *reinterpret_cast(vendor) = cpuInfo.ebx; - *reinterpret_cast(vendor + 4) = cpuInfo.edx; - *reinterpret_cast(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]; - AuMemset(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) - { - AuMemcpy(brand, &extdata[2], sizeof(cpui)); - AuMemcpy(brand + 16, &extdata[3], sizeof(cpui)); - AuMemcpy(brand + 32, &extdata[4], sizeof(cpui)); - gCpuInfo.cpuId.brand = brand; - } - #endif - } - #if defined(AURORA_IS_MODERNNT_DERIVED) static bool IsWindowsLTSC() { diff --git a/Source/HWInfo/CpuInfo.hpp b/Source/HWInfo/CpuInfo.hpp index 74762e32..90dd30c9 100644 --- a/Source/HWInfo/CpuInfo.hpp +++ b/Source/HWInfo/CpuInfo.hpp @@ -9,5 +9,7 @@ namespace Aurora::HWInfo { + inline CpuInfo gCpuInfo; + void InitCpuInfo(); } \ No newline at end of file diff --git a/Source/IO/FS/Async.NT.cpp b/Source/IO/FS/Async.NT.cpp index 84a6147d..fb68fc17 100644 --- a/Source/IO/FS/Async.NT.cpp +++ b/Source/IO/FS/Async.NT.cpp @@ -36,7 +36,7 @@ namespace Aurora::IO::FS AuSPtr handle_; }; - class NtAsyncFileTransaction : public IAsyncTransaction, std::enable_shared_from_this + class NtAsyncFileTransaction : public IAsyncTransaction, AuEnableSharedFromThis { public: ~NtAsyncFileTransaction(); diff --git a/Source/Locale/LocaleStrings.cpp b/Source/Locale/LocaleStrings.cpp index d29af3a0..cb36c874 100644 --- a/Source/Locale/LocaleStrings.cpp +++ b/Source/Locale/LocaleStrings.cpp @@ -79,6 +79,19 @@ namespace Aurora::Locale try { + // This is completely arbitrary + // I feel as though this would do juststice to large and small timescales; with sane formatting, without being too autistic on resolution, and without returning excessively long (^ and localized) strings + // We probably don't need to keep the MS around for more than a minute + // We can use the lengthy the MS padding to pad out seconds more into the ballpark of HH:MM:SS + // We can measure months, perhaps years, using mere days. We, and most normies, can comprehend 30/60/90/360/720 without much problem + // + // ! = pad + // + // S!2.MS!4s (01.5000s) + // M!2.S!2 (02:29) + // H!2:M!2:S!2 (01:02:29) + // D!0d H!2:M!2:S!2 (9d 01:02:29) + if (ms < 1000) { return AuToString(ms) + TimeLocaleGetMSChar(); diff --git a/Source/Memory/Heap.cpp b/Source/Memory/Heap.cpp index 3deef2f0..7e8484f8 100644 --- a/Source/Memory/Heap.cpp +++ b/Source/Memory/Heap.cpp @@ -49,7 +49,7 @@ namespace Aurora::Memory #endif } - class InternalHeap : public Heap, std::enable_shared_from_this + class InternalHeap : public Heap, AuEnableSharedFromThis { public: InternalHeap() : base_(nullptr), mutex_(nullptr), heap_(nullptr), count_(0) diff --git a/Source/Process/Process.cpp b/Source/Process/Process.cpp index 445e4b5e..30e093e3 100644 --- a/Source/Process/Process.cpp +++ b/Source/Process/Process.cpp @@ -42,7 +42,7 @@ namespace Aurora::Process return ".Linux"; case Build::EPlatform::ePlatformAndroid: return ".Android"; - case Build::EPlatform::ePlatformApple: + case Build::EPlatform::ePlatformAppleMacOS: return ".Mac"; case Build::EPlatform::ePlatformIos: return ".IOS"; @@ -60,7 +60,7 @@ namespace Aurora::Process case Build::EPlatform::ePlatformLinux: case Build::EPlatform::ePlatformAndroid: return ".so"; - case Build::EPlatform::ePlatformApple: + case Build::EPlatform::ePlatformAppleMacOS: case Build::EPlatform::ePlatformIos: return ".dynlib"; default: diff --git a/Source/Process/ProcessMap.cpp b/Source/Process/ProcessMap.cpp index c9ea6347..c14d7ee3 100644 --- a/Source/Process/ProcessMap.cpp +++ b/Source/Process/ProcessMap.cpp @@ -195,7 +195,7 @@ namespace Aurora::Process } catch (...) { - + return {}; } } @@ -207,7 +207,7 @@ namespace Aurora::Process } catch (...) { - + return {}; } } @@ -224,7 +224,7 @@ namespace Aurora::Process } catch (...) { - + return {}; } } } \ No newline at end of file diff --git a/Source/Processes/Process.Win32.cpp b/Source/Processes/Process.Win32.cpp index d3b4b84f..d7933872 100644 --- a/Source/Processes/Process.Win32.cpp +++ b/Source/Processes/Process.Win32.cpp @@ -14,7 +14,7 @@ namespace Aurora::Processes { - static HANDLE gLeaderJob; + static HANDLE gLeaderJob = INVALID_HANDLE_VALUE; void InitWin32() { @@ -33,8 +33,10 @@ namespace Aurora::Processes } } - - // TODO: where the hell is my release + void DeinitWin32() + { + AuWin32CloseHandle(gLeaderJob); + } class ProcessImpl : public IProcess { @@ -47,6 +49,8 @@ namespace Aurora::Processes bool TryKill() override; bool HasExited(); + AuUInt GetProcessId() override; + bool Terminate() override; AuSPtr AsWaitable() override; AuSInt GetExitCode() override; @@ -118,6 +122,16 @@ namespace Aurora::Processes ShutdownPipes(); } + AuUInt ProcessImpl::GetProcessId() + { + if (this->process_ == INVALID_HANDLE_VALUE) + { + return {}; + } + + return ::GetProcessId(this->process_); + } + static BOOL TermWinHandleWin32Thread(HWND handle, LPARAM a) { SendMessageA(handle, WM_CLOSE, 0, 0); @@ -135,7 +149,7 @@ namespace Aurora::Processes return false; } - h = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, GetProcessId(this->process_)); + h = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, GetProcessId()); if (h == INVALID_HANDLE_VALUE) { return false; diff --git a/Source/Processes/Process.Win32.hpp b/Source/Processes/Process.Win32.hpp index 900c28aa..447784a4 100644 --- a/Source/Processes/Process.Win32.hpp +++ b/Source/Processes/Process.Win32.hpp @@ -10,4 +10,5 @@ namespace Aurora::Processes { void InitWin32(); + void DeinitWin32(); } \ No newline at end of file diff --git a/Source/Processes/Processes.cpp b/Source/Processes/Processes.cpp index 5e6c78eb..93734be9 100644 --- a/Source/Processes/Processes.cpp +++ b/Source/Processes/Processes.cpp @@ -23,6 +23,7 @@ namespace Aurora::Processes void Deinit() { #if defined (AURORA_PLATFORM_WIN32) + DeinitWin32(); DeinitWin32Opener(); #endif } diff --git a/Source/RuntimeInternal.hpp b/Source/RuntimeInternal.hpp index ada08e6c..480a58fe 100644 --- a/Source/RuntimeInternal.hpp +++ b/Source/RuntimeInternal.hpp @@ -7,7 +7,8 @@ ***/ #pragma once -#include +//#include +#include #if defined(AURORA_PLATFORM_WIN32) #if !defined(NOMINMAX) diff --git a/Source/SWInfo/SWInfo.cpp b/Source/SWInfo/SWInfo.cpp new file mode 100644 index 00000000..ad2cd369 --- /dev/null +++ b/Source/SWInfo/SWInfo.cpp @@ -0,0 +1,163 @@ +/*** + Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved. + + File: SWInfo.cpp + Date: 2022-1-25 + Author: Reece +***/ +#include +#include "SWInfo.hpp" + +#if defined(AURORA_PLATFORM_WIN32) + #include + + #include + + NTSYSAPI NTSTATUS RtlGetVersion( + PRTL_OSVERSIONINFOW lpVersionInformation + ); +#endif + + +namespace Aurora::SWInfo +{ + static const AuString kDefaultStr; + static const OSInformation kDefaultInfo; + static OSInformation const *gInfo = &kDefaultInfo; + + static AuString gKernelString; + static AuString gUserlandBrand; + static AuString gUserlandDesktopEnv; + static AuString gBuildString; + static OSInformation gTempInfo; + + static void Reset() + { + gInfo = &kDefaultInfo; + } + + AUKN_SYM const OSInformation & GetPlatformInfo() + { + return *gInfo; + } + +#if defined(AURORA_PLATFORM_WIN32) + + static bool IsWindowsEnterpriseBranch() + { + OSVERSIONINFOEXW osvi = {sizeof(osvi), 0, 0, 0, 0, {0}, 0, 0, VER_SUITE_ENTERPRISE, 0}; + DWORDLONG const dwlConditionMask = VerSetConditionMask(0, VER_SUITENAME, VER_EQUAL); + + return !VerifyVersionInfoW(&osvi, VER_SUITENAME, dwlConditionMask); + } + + auline bool Win32ReadRegistry(HKEY hKey, const wchar_t *key, AuString &strValue) + { + DWORD dwBufferSize {}; + + if (RegQueryValueExW(hKey, key, 0, NULL, NULL, &dwBufferSize) != ERROR_SUCCESS) + { + SysPushErrorUnavailableError("Couldn't access registery key"); + return false; + } + + std::wstring in; + + if (!AuTryResize(in, dwBufferSize)) + { + return false; + } + + if (RegQueryValueExW(hKey, key, 0, NULL, reinterpret_cast(in.data()), &dwBufferSize) != ERROR_SUCCESS) + { + SysPushErrorUnavailableError("Couldn't access registery key"); + return false; + } + + strValue = Locale::ConvertFromWChar(in.data(), in.size()); + return strValue.size() == in.size(); + } + +#endif + + void InitSwInfo() + { + Reset(); + + gTempInfo = AuMove(OSInformation(&gKernelString, &gUserlandBrand, &gUserlandDesktopEnv, &gBuildString, Aurora::Build::EPlatform::eEnumInvalid)); + + #if defined(AURORA_IS_MODERNNT_DERIVED) + OSVERSIONINFOEX info {}; + info.dwOSVersionInfoSize = sizeof(info); + + + #if defined(AURORA_PLATFORM_WIN32) + gTempInfo.bIsServer = IsWindowsServer(); + gTempInfo.bIsEnterprise = IsWindowsEnterpriseBranch(); + #else + gTempInfo.bIsServer = false; + gTempInfo.bIsEnterprise = false; + #endif + + gUserlandDesktopEnv = "Desktop Window Manager"; + + if (GetVersionExA(reinterpret_cast(&info))) + { + gTempInfo.uKernelPatch = info.dwBuildNumber; + gTempInfo.uKernelMinor = info.dwMinorVersion; + gTempInfo.uKernelMajor = info.dwMajorVersion; + + gTempInfo.uUserlandMajor = gTempInfo.uKernelMajor; + gTempInfo.uUserlandMinor = info.wServicePackMajor; + gTempInfo.uUserlandPatch = info.wServicePackMinor; + } + + #if defined(AURORA_PLATFORM_WIN32) + { + RTL_OSVERSIONINFOEXW ovi {}; + ovi.dwOSVersionInfoSize = sizeof(ovi); + + NTSTATUS(CALLBACK *pRtlGetVersion) (PRTL_OSVERSIONINFOW lpVersionInformation); + pRtlGetVersion = (decltype(pRtlGetVersion))GetProcAddress(LoadLibrary(TEXT("Ntdll.dll")), "RtlGetVersion"); + + if (pRtlGetVersion && pRtlGetVersion(reinterpret_cast(&ovi)) == 0) + { + gTempInfo.uKernelPatch = ovi.dwBuildNumber; + gTempInfo.uKernelMinor = ovi.dwMinorVersion; + gTempInfo.uKernelMajor = ovi.dwMajorVersion; + + gTempInfo.uUserlandMajor = gTempInfo.uKernelMajor; + gTempInfo.uUserlandMinor = ovi.wServicePackMajor; + gTempInfo.uUserlandPatch = ovi.wServicePackMinor; + } + } + + HKEY hKey; + if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", 0, KEY_READ, &hKey) == ERROR_SUCCESS) + { + if (!Win32ReadRegistry(hKey, L"BuildLabEx", gBuildString)) + { + Win32ReadRegistry(hKey, L"BuildLab", gBuildString); + } + Win32ReadRegistry(hKey, L"ProductName", gUserlandBrand); + RegCloseKey(hKey); + } + #endif + + if (gKernelString.empty()) + { + gKernelString = fmt::format("Microsoft NT {}.{}.{}", gTempInfo.uKernelMajor, gTempInfo.uKernelMinor, gTempInfo.uKernelPatch); + } + + if (gUserlandBrand.empty()) + { + gUserlandBrand = fmt::format("NT Userland {}.{}.{}", gTempInfo.uUserlandMajor, gTempInfo.uUserlandMinor, gTempInfo.uUserlandPatch); + } + + #endif + + gTempInfo.ePlatform = Build::kCurrentPlatform; + + gInfo = &gTempInfo; + } +} \ No newline at end of file diff --git a/Source/SWInfo/SWInfo.hpp b/Source/SWInfo/SWInfo.hpp new file mode 100644 index 00000000..4bf27630 --- /dev/null +++ b/Source/SWInfo/SWInfo.hpp @@ -0,0 +1,13 @@ +/*** + Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved. + + File: SWInfo.hpp + Date: 2022-1-25 + Author: Reece +***/ +#pragma once + +namespace Aurora::SWInfo +{ + void InitSwInfo(); +} \ No newline at end of file