Adjusted workflow.
All checks were successful
Build & Release / Windows-AMD64-Build (push) Successful in 1m8s
Build & Release / Linux-AMD64-Build (push) Successful in 1m30s
Build & Release / Linux-AARCH64-Build (push) Successful in 3m21s

This commit is contained in:
2024-02-05 22:25:30 -08:00
commit bcd71cf2b5
251 changed files with 45909 additions and 0 deletions

View File

@@ -0,0 +1,11 @@
#pragma once
#if defined(_M_AMD64) || defined(_M_X64) || defined(__x86_64__)
#define EHS_LITTLE_ENDIAN
#define EHS_ARCH_X64
#elif defined(_M_ARM64) || defined(__aarch64__)
#define EHS_LITTLE_ENDIAN
#define EHS_ARCH_ARM64
#else
#error Unsupported architecture.
#endif

View File

@@ -0,0 +1,34 @@
#pragma once
#include "ehs/EHS.h"
namespace ehs
{
class BaseMutex
{
protected:
bool initialized;
bool locked;
public:
virtual ~BaseMutex();
BaseMutex();
BaseMutex(const BaseMutex& mutex);
BaseMutex& operator=(const BaseMutex& mutex);
virtual void Initialize();
virtual void UnInitialize();
bool IsInitialized() const;
virtual void Lock();
virtual void Unlock();
bool IsLocked() const;
};
}

View File

@@ -0,0 +1,35 @@
#pragma once
#include "ehs/Str.h"
namespace ehs
{
class BaseOpen
{
protected:
Str_8 filePath;
public:
BaseOpen();
BaseOpen(Str_8 filePath);
BaseOpen(BaseOpen&& bo) noexcept;
BaseOpen(const BaseOpen& bo);
BaseOpen& operator=(BaseOpen&& bo) noexcept;
BaseOpen& operator=(const BaseOpen& bo);
virtual void Initialize() = 0;
virtual void Release() = 0;
virtual void* Retrieve(Str_8 symbol) = 0;
Str_8 GetFilePath() const;
virtual bool IsInitialize() const = 0;
};
}

View File

@@ -0,0 +1,43 @@
#pragma once
#include "ehs/EHS.h"
#include "ehs/Str.h"
namespace ehs
{
class BaseSemaphore
{
private:
Str_8 name;
UInt_32 initial;
public:
BaseSemaphore();
BaseSemaphore(Str_8 name, const UInt_32 initial);
BaseSemaphore(const UInt_32 initial);
BaseSemaphore(BaseSemaphore&& sem) noexcept;
BaseSemaphore(const BaseSemaphore& sem);
BaseSemaphore& operator=(BaseSemaphore&& sem) noexcept;
BaseSemaphore& operator=(const BaseSemaphore& sem);
virtual void Initialize() = 0;
virtual void Release() = 0;
virtual void Signal(const UInt_32 inc) = 0;
virtual bool Wait(const UInt_32 timeout) = 0;
Str_8 GetName() const;
UInt_32 GetInitial() const;
virtual bool IsValid() const = 0;
};
}

View File

@@ -0,0 +1,13 @@
#pragma once
#include "ehs/EHS.h"
#include "ehs/Str.h"
namespace ehs
{
class BaseSystem
{
public:
static void OpenURI(const Str_8& uri);
};
}

220
include/ehs/system/CPU.h Normal file
View File

@@ -0,0 +1,220 @@
#pragma once
#include "ehs/Types.h"
#include "Architecture.h"
#include "OS.h"
#include "ehs/Str.h"
#include "ehs/Array.h"
namespace ehs
{
enum class Architecture : UInt_8
{
X64,
X86,
ARM64,
ARM,
UNKNOWN
};
enum class Endianness : UInt_8
{
LE,
BE
};
struct TSC
{
UInt_32 coreId = 0;
UInt_32 highCount = 0;
UInt_32 lowCount = 0;
};
class CPU
{
private:
#ifdef EHS_OS_LINUX
static UInt_64 TSC_Freq;
#endif
public:
static Architecture GetArchitecture();
static UInt_8 PointerSize();
static Endianness GetEndianness();
static void RDTSCP(TSC* tsc);
static UInt_64 GetTSC_Freq();
static UInt_64 GetTSC();
/// Retrieves the CPU manufacturer id as a non null-terminated ASCII string.
/// @param[out] input A twelve byte character array representing the manufacturer id.
static void GetManufacturer(Char_8* input);
static UInt_32 GetInfoBits();
static UInt_8 GetSteppingId();
static UInt_8 GetModelId();
static UInt_8 GetFamilyId();
static UInt_8 GetProcessorTypeId();
static UInt_8 GetExtModelId();
static UInt_8 GetExtFamilyId();
static UInt_32 GetFeatureBits_1();
static bool HasFPU();
static bool HasVME();
static bool HasDE();
static bool HasPSE();
static bool HasTSC();
static bool HasMSR();
static bool HasPAE();
static bool HasMCE();
static bool HasCX8();
static bool HasAPIC();
static bool HasSEP();
static bool HasMTRR();
static bool HasPGE();
static bool HasMCA();
static bool HasCMOV();
static bool HasPAT();
static bool HasPSE_36();
static bool HasPSN();
static bool HasCLFSH();
static bool HasDS();
static bool HasACPI();
static bool HasMMX();
static bool HasFXSR();
static bool HasSSE();
static bool HasSSE2();
static bool HasSS();
static bool HasHTT();
static bool HasTM();
static bool HasIA64();
static bool HasPBE();
static UInt_32 GetFeatureBits_2();
static bool HasSSE3();
static bool HasPCLMULQDQ();
static bool HasDTES64();
static bool HasMONITOR();
static bool HasDS_CPL();
static bool HasVMX();
static bool HasSMX();
static bool HasEST();
static bool HasTM2();
static bool HasSSSE3();
static bool HasCNXT_ID();
static bool HasSDBG();
static bool HasFMA();
static bool HasCX16();
static bool HasXTPR();
static bool HasPDCM();
static bool HasPCID();
static bool HasDCA();
static bool HasSSE4_1();
static bool HasSSE4_2();
static bool HasX2APIC();
static bool HasMOVBE();
static bool HasPOPCNT();
static bool HasTSC_DEADLINE();
static bool HasAES();
static bool HasXSAVE();
static bool HasOSXSAVE();
static bool HasAVX();
static bool HasF16C();
static bool HasRDRND();
static bool HasHYPERVISOR();
static UInt_32 GetExtFeatureBits_1();
static bool HasAVX2();
static bool HasRDSEED();
static bool HasADX();
static UInt_32 GetExtFeatureBits_2();
static UInt_32 GetExtFeatureBits_3();
/// Retrieves the CPU brand as a null-terminated ASCII string.
/// @param[out] input A 48 byte character array representing the brand.
static void GetBrand(Char_8* input);
//static Str_8 ToStr();
private:
static UInt_64 RetrieveTSC_Freq();
static UInt_64 CalculateTSC_Freq();
};
}

View File

@@ -0,0 +1,17 @@
#pragma once
#include "ehs/EHS.h"
#include "ehs/Str.h"
namespace ehs
{
class FileSystem
{
public:
static void SetWorkingDir(const Str_8& dir);
static Str_8 GetWorkingDir();
static void SetOwner(const Str_8& dir, const UInt_32 userId, const UInt_32 groupId);
};
}

View File

@@ -0,0 +1,9 @@
#pragma once
#include "ehs/EHS.h"
#if defined(EHS_OS_WINDOWS)
#include "Mutex_W32.h"
#elif defined(EHS_OS_LINUX)
#include "Mutex_PT.h"
#endif

View File

@@ -0,0 +1,32 @@
#pragma once
#include "ehs/EHS.h"
#include "BaseMutex.h"
#include <pthread.h>
namespace ehs
{
class Mutex : public BaseMutex
{
private:
pthread_mutex_t hdl;
public:
~Mutex() override;
Mutex();
Mutex(const Mutex& mutex);
Mutex& operator=(const Mutex& mutex);
void Initialize() override;
void UnInitialize() override;
void Lock() override;
void Unlock() override;
};
}

View File

@@ -0,0 +1,30 @@
#pragma once
#include "ehs/EHS.h"
#include "BaseMutex.h"
namespace ehs
{
class Mutex : public BaseMutex
{
private:
HANDLE hdl;
public:
~Mutex() override;
Mutex();
Mutex(const Mutex& mutex);
Mutex& operator=(const Mutex& mutex);
void Initialize() override;
void UnInitialize() override;
void Lock() override;
void Unlock() override;
};
}

27
include/ehs/system/OS.h Normal file
View File

@@ -0,0 +1,27 @@
#pragma once
#if defined(_WIN32) || defined(_WIN64)
#define EHS_OS_WINDOWS
#define EHS_FILE __FILE__
#define EHS_FUNC __FUNCTION__
#define EHS_LINE __LINE__
#ifndef NOMINMAX
#define NOMINMAX
#endif
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <Windows.h>
typedef void* Handle;
#elif defined(__linux__)
#define EHS_OS_LINUX
#define EHS_FILE __FILE__
#define EHS_FUNC __FUNCTION__
#define EHS_LINE __LINE__
typedef int Handle;
#endif

View File

@@ -0,0 +1,9 @@
#pragma once
#include "OS.h"
#if defined(EHS_OS_WINDOWS)
#include "Open_W32.h"
#elif defined(EHS_OS_LINUX)
#include "Open_UNX.h"
#endif

View File

@@ -0,0 +1,35 @@
#pragma once
#include "BaseOpen.h"
namespace ehs
{
class Open : public BaseOpen
{
private:
void* hdl;
public:
~Open();
Open();
Open(Str_8 filePath);
Open(Open&& o) noexcept;
Open(const Open& o);
Open& operator=(Open&& o) noexcept;
Open& operator=(const Open& o);
void Initialize() override;
void Release() override;
void* Retrieve(Str_8 symbol) override;
bool IsInitialize() const override;
};
}

View File

@@ -0,0 +1,16 @@
//
// Created by karutoh on 11/14/23.
//
#ifndef OPEN_W32_H
#define OPEN_W32_H
namespace ehs {
class Open_W32 {
};
} // lwe
#endif //OPEN_W32_H

View File

@@ -0,0 +1,7 @@
#pragma once
#ifdef EHS_OS_WINDOWS
#include "Semaphore_W32.h"
#else
#include "Semaphore_P.h"
#endif

View File

@@ -0,0 +1,44 @@
#pragma once
#include "ehs/EHS.h"
#include "ehs/Str.h"
#include "BaseSemaphore.h"
#include <semaphore.h>
namespace ehs
{
class Semaphore : public BaseSemaphore
{
private:
sem_t hdl;
bool valid;
public:
~Semaphore();
Semaphore();
Semaphore(const Str_8& name, const UInt_32 initial);
Semaphore(const UInt_32 initial);
Semaphore(Semaphore&& sem) noexcept;
Semaphore(const Semaphore& sem);
Semaphore& operator=(Semaphore&& sem) noexcept;
Semaphore& operator=(const Semaphore& sem);
void Initialize() override;
void Release() override;
bool Wait(const UInt_32 timeout) override;
void Signal(const UInt_32 inc) override;
bool IsValid() const override;
};
}

View File

@@ -0,0 +1,41 @@
#pragma once
#include "ehs/EHS.h"
#include "ehs/Str.h"
#include "BaseSemaphore.h"
namespace ehs
{
class Semaphore : public BaseSemaphore
{
private:
HANDLE hdl;
public:
~Semaphore();
Semaphore();
Semaphore(Str_8 name, const UInt_32 initial);
Semaphore(const UInt_32 initial);
Semaphore(Semaphore&& sem) noexcept;
Semaphore(const Semaphore& sem);
Semaphore& operator=(Semaphore&& sem) noexcept;
Semaphore& operator=(const Semaphore& sem);
void Initialize() override;
void Release() override;
void Signal(const UInt_32 inc) override;
bool Wait(const UInt_32 timeout) override;
bool IsValid() const override;
};
}

View File

@@ -0,0 +1,9 @@
#pragma once
#include "ehs/EHS.h"
#if defined(EHS_OS_WINDOWS)
#include "System_W32.h"
#elif defined(EHS_OS_LINUX)
#include "System_LNX.h"
#endif

View File

@@ -0,0 +1,13 @@
#pragma once
#include "ehs/EHS.h"
#include "BaseSystem.h"
namespace ehs
{
class System : public BaseSystem
{
public:
static void OpenURI(const Str_8& uri);
};
}

View File

@@ -0,0 +1,12 @@
#pragma once
#include "BaseSystem.h"
namespace ehs
{
class System : public BaseSystem
{
public:
static void OpenURI(const Str_8& uri);
};
}

148
include/ehs/system/Thread.h Normal file
View File

@@ -0,0 +1,148 @@
#pragma once
#include "ehs/EHS.h"
#include "ehs/Serializer.h"
#include "ehs/Array.h"
#include "ehs/Log.h"
#include "ehs/Str.h"
#ifdef EHS_OS_WINDOWS
#include <processthreadsapi.h>
#endif
namespace ehs
{
#if defined(EHS_OS_WINDOWS)
#define EHS_INVALID_THREAD nullptr
typedef void* THandle;
#elif defined(EHS_OS_LINUX)
#define EHS_INVALID_THREAD 0
typedef UInt_64 THandle;
#endif
class Thread
{
private:
static UInt_32 mainId;
#ifdef EHS_OS_WINDOWS
static Handle mainTaskHdl;
static UInt_32 mainTaskIndex;
#endif
UInt_64 stackSize;
THandle hdl;
UInt_32 id;
#ifdef EHS_OS_WINDOWS
Handle taskHdl;
UInt_32 taskIndex;
#endif
public:
/// Frees any native handles.
~Thread();
/// Default members initialization.
Thread(const UInt_64 stackSize = 0);
/// Copies some members from the given thread object.
/// @param [in] thread The thread object to copy from.
Thread(const Thread& thread);
/// Copies some members from the given thread object.
/// @param [in] thread The thread object to copy from.
/// @returns The thread that has been assigned to.
Thread& operator=(const Thread& thread);
/// Creates a thread handle and starts it with the given method.
/// @param cb The function to run on the thread.
/// @param args Raw data to send over to the thread.
void Start(UInt_32 (*cb)(void*), void* args);
/// Blocks the calling thread until the referenced thread is finished.
/// @param timeout The time to wait for before moving on.
/// @note Pass "EHS_INFINITE" to wait until the thread is finished.
bool Join(const unsigned int timeout = EHS_INFINITE);
/// Detaches the referenced thread, removing ownership.
void Detach();
/// Retrieves the given stack size available to the referenced thread.
/// @returns The stack size.
UInt_64 GetStackSize() const;
/// Retrieves the native thread handle.
/// @returns The native handle.
THandle GetHandle() const;
/// Retrieves the thread's id.
/// @returns The id.
UInt_32 GetId() const;
/// Checks whether or not the calling thread is the referenced thread.
/// @returns The result.
bool IsCurrent() const;
bool IsValid() const;
#ifdef EHS_OS_WINDOWS
/// Adjusts the thread's performance based on the type of task provided, that's going to be executed.
/// @param[in] task A task name from the provided list in the registry.
/// @note A list of tasks are in the registry at HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Multimedia\SystemProfile\Tasks.
void SetTaskType_32(const Str_32& task);
/// Adjusts the thread's performance based on the type of task provided, that's going to be executed.
/// @param[in] task A task name from the provided list in the registry.
/// @note A list of tasks are in the registry at HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Multimedia\SystemProfile\Tasks.
void SetTaskType_16(const Str_16& task);
/// Adjusts the thread's performance based on the type of task provided, that's going to be executed.
/// @param[in] task A task name from the provided list in the registry.
/// @note A list of tasks are in the registry at HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Multimedia\SystemProfile\Tasks.
void SetTaskType_8(const Str_8& task);
void RevertTaskType();
#endif
/// Gets the main thread id.
static UInt_32 GetMainId();
/// Retrieves the calling thread's id.
/// @returns The id.
static UInt_64 GetCurrentId();
#ifdef EHS_OS_WINDOWS
/// Adjusts the main thread's performance based on the type of task provided, that's going to be executed.
/// @param[in] task A task name from the provided list in the registry.
/// @note A list of tasks are in the registry at HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Multimedia\SystemProfile\Tasks.
static void SetMainTaskType_32(const Str_32& task);
/// Adjusts the main thread's performance based on the type of task provided, that's going to be executed.
/// @param[in] task A task name from the provided list in the registry.
/// @note A list of tasks are in the registry at HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Multimedia\SystemProfile\Tasks.
static void SetMainTaskType_16(const Str_16& task);
/// Adjusts the main thread's performance based on the type of task provided, that's going to be executed.
/// @param[in] task A task name from the provided list in the registry.
/// @note A list of tasks are in the registry at HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Multimedia\SystemProfile\Tasks.
static void SetMainTaskType_8(const Str_8& task);
static void RevertMainTaskType();
#endif
/// Causes the calling thread to wait until the given time using a while loop and the CPU clock.
/// @param seconds The time in seconds to wait for.
/// @returns The total elapsed time slept for due to this not being a 100% accurate.
/// @warning Use "SleepFor" instead unless accuracy is required because this does not do other tasks while sleeping.
static float HardSleepFor(const float seconds);
/// Causes the calling thread to wait until the given time using native sleep calls.
/// @param miliseconds The time in miliseconds to wait for.
/// @warning This is not at all accurate.
static void SleepFor(const UInt_32 miliseconds);
private:
static void* Redirect(void* args);
};
}

15
include/ehs/system/User.h Normal file
View File

@@ -0,0 +1,15 @@
#pragma once
#include "ehs/EHS.h"
#include "ehs/Str.h"
namespace ehs
{
class User
{
public:
static void GetId(UInt_32* const real, UInt_32* const effective, UInt_32* const saved);
static Str_8 GetName();
};
}