[+] Added shared pointer extension, begin experimenting defining throw-on-null mechanic

[+] AuRemoveConst
[*] Support circular reference in Aurora pipelines Include, added support for early Aurora::Build AuroraEnum
[+] Added SWInfo API
[+] AU_COPY_MOVE, AU_MOVE, AU_COPY to go with AU_NO_... variants
[+] Adding GetProcessId
This commit is contained in:
Reece Wilson 2022-01-26 00:01:06 +00:00
parent a0d38ff168
commit 7eb6900e9f
27 changed files with 905 additions and 427 deletions

View File

@ -12,6 +12,8 @@ namespace Aurora::Threading::Primitives
class SpinLoop;
}
#include <Aurora/Memory/ExtendStlLikeSharedPtr.hpp>
namespace Aurora::Async
{
struct BasicWorkStdFunc;
@ -29,7 +31,7 @@ namespace Aurora::Async
/// @hideinitializer
template<typename Info_t = AVoid, typename Result_t = AVoid, typename Task_t = FTask<Info_t, Result_t>, typename Job_t = FJob<Info_t, Result_t>>
struct WorkPairImpl : IWorkItemHandler, std::enable_shared_from_this<IWorkItemHandler>
struct WorkPairImpl : IWorkItemHandler, AuEnableSharedFromThis<IWorkItemHandler>
{
WorkPairImpl() : caller_(Async::GetCurrentWorkerPId())
{}
@ -120,7 +122,6 @@ namespace Aurora::Async
}
auto pin = AuSharedFromThis();
AuFunction<void()> func = [pin]()
{
try

View File

@ -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<class TType_t, class Base_t>
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<class TType_t, class Base_t>
struct ExSharedFromThis : Base_t
{
ExSharedPtr<TType_t, AURORA_RUNTIME_AU_SHARED_PTR<TType_t>> SharedFromThis()
{
return Base_t::shared_from_this();
}
};
}

View File

@ -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;

View File

@ -17,6 +17,9 @@
#endif
#endif
#include <AuroraEnvironment.h>
#include <AuroraTypes.hpp>
#include <AuroraForEach.hpp>
#include <AuroraInterfaces.hpp>
#include <AuroraEnum.hpp>
@ -29,17 +32,21 @@
#include <functional>
#include "../AuroraTypedefs.hpp"
#define _ALLOW_AURORA_ENUM_AUENVHPP
#include <AuroraCommon.hpp>
#include "../AuroraUtils.hpp"
#if defined(_AUHAS_FMT)
#include <fmt/core.h>
#include <fmt/format.h>
#include <fmt/chrono.h>
#include <fmt/ranges.h>
#include <fmt/core.h>
#include <fmt/format.h>
#include <fmt/chrono.h>
#include <fmt/ranges.h>
#endif
#if !defined(_AUHAS_UUID)
#error Missing stduuid library
#error Missing stduuid library
#endif
#include <uuid.h>
@ -72,6 +79,7 @@
#include "Async/Async.hpp"
#include "Processes/Processes.hpp"
#include "Loop/Loop.hpp"
#include "SWInfo/SWInfo.hpp"
#include "Memory/_ByteBuffer.hpp"

View File

@ -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();
}

View File

@ -9,9 +9,8 @@
namespace Aurora::Time
{
enum ETimezoneShift
{
AUE_DEFINE(ETimezoneShift, (
eUTC,
eLocalTime
};
))
}

View File

@ -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<AuRemovePointer_t<decltype(this)>>(this->shared_from_this()))
#define AU_SHARED_FROM_THIS (AuStaticPointerCast<AuRemovePointer_t<decltype(this)>>(this->SharedFromThis()))
#endif
#if !defined(AU_WEAK_FROM_THIS)
#define AU_WEAK_FROM_THIS (AuWPtr<AuRemovePointer_t<decltype(this)>>(AuStaticPointerCast<AuRemovePointer_t<decltype(this)>>(this->shared_from_this())))
#define AU_WEAK_FROM_THIS (AuWPtr<AuRemovePointer_t<decltype(this)>>(AuStaticPointerCast<AuRemovePointer_t<decltype(this)>>(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) {}
/// @hideinitializer
#define AU_EMIT_FIRST_TYPEREDUCED_PAIR_REDUCED(variable) AuRemoveConst_t<AuRemoveReference_t<decltype(variable)>>
/// @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)

View File

@ -5,5 +5,4 @@
Date: 2021-6-9
Author: Reece
***/
#include <AuroraCommon.hpp>
#include "Aurora/Runtime.hpp"

View File

@ -158,6 +158,19 @@ constexpr AuRemoveReference_t<T> &&AuMove(T &&arg) noexcept
return static_cast<AuRemoveReference_t<T> &&>(arg);
}
template<class T> struct AuRemoveConst
{
typedef T type;
};
template<class T> struct AuRemoveConst<const T>
{
typedef T type;
};
template<class T>
using AuRemoveConst_t = typename AuRemoveConst<T>::type;
template<bool Test, class T = void>
struct AuEnableIf
{
@ -263,9 +276,6 @@ using AuBSTEx = AURORA_RUNTIME_AU_BST<T, Z, Utility>;
#define AURORA_RUNTIME_AU_SHARED_PTR std::shared_ptr
#endif
template<typename T>
using AuSPtr = AURORA_RUNTIME_AU_SHARED_PTR<T>;
#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<T>;
#define AURORA_RUNTIME_AU_UNIQUE_PTR std::unique_ptr
#endif
template<typename T, typename Deleter_t>
using AuUPtr = AURORA_RUNTIME_AU_UNIQUE_PTR<T, Deleter_t>;
#if !defined(AURORA_RUNTIME_AU_DEFAULT_DELETER)
#define AURORA_RUNTIME_AU_DEFAULT_DELETER std::default_delete
#endif
template<typename T>
using AuDefaultDeleter = AURORA_RUNTIME_AU_DEFAULT_DELETER<T>;
#include <Aurora/Memory/ExtendStlLikeSharedPtr.hpp>
template<typename T>
using AuSPtr = typename Aurora::Memory::ExSharedPtr<T, AURORA_RUNTIME_AU_SHARED_PTR<T>>;
template<typename T, typename Deleter_t>
using AuUPtr = AURORA_RUNTIME_AU_UNIQUE_PTR<T, Deleter_t>;
#if !defined(AU_AuEnableSharedFromThis)
#define AU_AuEnableSharedFromThis
template<class X>
struct AuEnableSharedFromThis : Aurora::Memory::ExSharedFromThis<X, std::enable_shared_from_this<X>>
{};
#endif
template <class T, class T2>
AuSPtr<T> AuStaticPointerCast(const AuSPtr<T2> &other) noexcept
{

View File

@ -23,7 +23,7 @@ namespace Aurora::Async
};
struct ThreadPool : public IThreadPool, public IThreadPoolInternal, std::enable_shared_from_this<ThreadPool>
struct ThreadPool : public IThreadPool, public IThreadPoolInternal, AuEnableSharedFromThis<ThreadPool>
{
ThreadPool();

View File

@ -11,7 +11,7 @@
namespace Aurora::Async
{
class WorkItem : public IWorkItem, public IAsyncRunnable, public std::enable_shared_from_this<WorkItem>
class WorkItem : public IWorkItem, public IAsyncRunnable, public AuEnableSharedFromThis<WorkItem>
{
public:
WorkItem(IThreadPoolInternal *owner, const WorkerId_t &worker_, const AuSPtr<IWorkItemHandler> &task_, bool supportsBlocking);

View File

@ -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();
}

400
Source/HWInfo/CpuId.cpp Normal file
View File

@ -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 <Source/RuntimeInternal.hpp>
#include "HWInfo.hpp"
#include "CpuId.hpp"
#if defined(AURORA_COMPILER_CLANG) || defined(AURORA_IS_POSIX_DERIVED)
#include <cpuid.h>
#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<CPUIdContext> data;
AuList<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];
AuMemset(vendor, 0, sizeof(vendor));
*reinterpret_cast<AuUInt32 *>(vendor) = cpuInfo.ebx;
*reinterpret_cast<AuUInt32 *>(vendor + 4) = cpuInfo.edx;
*reinterpret_cast<AuUInt32 *>(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
}
}

13
Source/HWInfo/CpuId.hpp Normal file
View File

@ -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();
}

View File

@ -8,6 +8,7 @@
#include <Source/RuntimeInternal.hpp>
#include "HWInfo.hpp"
#include "CpuInfo.hpp"
#include "CpuId.hpp"
#if defined(AURORA_IS_BSD_DERIVED)
#include <sys/types.h>
@ -27,391 +28,9 @@
#include <VersionHelpers.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 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<CPUIdContext> data;
AuList<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];
AuMemset(vendor, 0, sizeof(vendor));
*reinterpret_cast<AuUInt32 *>(vendor) = cpuInfo.ebx;
*reinterpret_cast<AuUInt32 *>(vendor + 4) = cpuInfo.edx;
*reinterpret_cast<AuUInt32 *>(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()
{

View File

@ -9,5 +9,7 @@
namespace Aurora::HWInfo
{
inline CpuInfo gCpuInfo;
void InitCpuInfo();
}

View File

@ -36,7 +36,7 @@ namespace Aurora::IO::FS
AuSPtr<FileHandle> handle_;
};
class NtAsyncFileTransaction : public IAsyncTransaction, std::enable_shared_from_this<NtAsyncFileTransaction>
class NtAsyncFileTransaction : public IAsyncTransaction, AuEnableSharedFromThis<NtAsyncFileTransaction>
{
public:
~NtAsyncFileTransaction();

View File

@ -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();

View File

@ -49,7 +49,7 @@ namespace Aurora::Memory
#endif
}
class InternalHeap : public Heap, std::enable_shared_from_this<InternalHeap>
class InternalHeap : public Heap, AuEnableSharedFromThis<InternalHeap>
{
public:
InternalHeap() : base_(nullptr), mutex_(nullptr), heap_(nullptr), count_(0)

View File

@ -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:

View File

@ -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 {};
}
}
}

View File

@ -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<Threading::IWaitable> 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;

View File

@ -10,4 +10,5 @@
namespace Aurora::Processes
{
void InitWin32();
void DeinitWin32();
}

View File

@ -23,6 +23,7 @@ namespace Aurora::Processes
void Deinit()
{
#if defined (AURORA_PLATFORM_WIN32)
DeinitWin32();
DeinitWin32Opener();
#endif
}

View File

@ -7,7 +7,8 @@
***/
#pragma once
#include <AuroraCommon.hpp>
//#include <AuroraCommon.hpp>
#include <AuroraEnvironment.h>
#if defined(AURORA_PLATFORM_WIN32)
#if !defined(NOMINMAX)

163
Source/SWInfo/SWInfo.cpp Normal file
View File

@ -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 <Source/RuntimeInternal.hpp>
#include "SWInfo.hpp"
#if defined(AURORA_PLATFORM_WIN32)
#include <VersionHelpers.h>
#include <winternl.h>
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<LPBYTE>(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<LPOSVERSIONINFOA>(&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<PRTL_OSVERSIONINFOW>(&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;
}
}

13
Source/SWInfo/SWInfo.hpp Normal file
View File

@ -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();
}