3 Commits

Author SHA1 Message Date
389fa61fba Merge pull request 'Fixed gitea workflow.' (#18) from NetChannels into main
Some checks failed
Build & Release / Windows-AMD64-Build (push) Failing after 21s
Build & Release / Linux-AARCH64-Build (push) Successful in 43m31s
Build & Release / Linux-AMD64-Build (push) Successful in 15m15s
Reviewed-on: #18
2025-03-25 18:43:47 -07:00
a67197766e Merge pull request 'Fixed gitea workflow.' (#17) from NetChannels into main
Some checks failed
Build & Release / Windows-AMD64-Build (push) Failing after 25s
Build & Release / Linux-AMD64-Build (push) Failing after 11m42s
Build & Release / Linux-AARCH64-Build (push) Successful in 43m39s
Reviewed-on: #17
2025-03-25 18:37:27 -07:00
ae414c5c99 Merge pull request 'Added CPU::GetCacheLineSize() definition for Windows.' (#16) from NetChannels into main
Reviewed-on: #16
2025-03-25 16:50:40 -07:00
27 changed files with 379 additions and 1896 deletions

View File

@@ -22,9 +22,10 @@ jobs:
- name: Building/Compiling/Installing Project - name: Building/Compiling/Installing Project
run: | run: |
cd ${{ gitea.workspace }} cd ${{ gitea.workspace }}
vcpkg install
mkdir build mkdir build
cd build cd build
cmake -A x64 -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE="$env:VCPKG_ROOT\scripts\buildsystems\vcpkg.cmake" .. cmake -A x64 -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=$env:VCPKG_ROOT\scripts\buildsystems\vcpkg.cmake ..
cmake --build . --config Release cmake --build . --config Release
cmake --install . cmake --install .
@@ -35,8 +36,6 @@ jobs:
mv build/Release/EHS_Dyn.dll bin mv build/Release/EHS_Dyn.dll bin
mv build/Release/StrToHash.exe bin mv build/Release/StrToHash.exe bin
mv build/Release/zlib1.dll bin mv build/Release/zlib1.dll bin
mv build/Release/libcrypto-3-x64.dll bin
mv build/Release/libssl-3-x64.dll bin
mkdir lib mkdir lib
mv build/Release/EHS_Stc.lib lib mv build/Release/EHS_Stc.lib lib
mv build/Release/EHS_Dyn.lib lib mv build/Release/EHS_Dyn.lib lib
@@ -57,7 +56,6 @@ jobs:
files: |- files: |-
ehs-windows-amd64.zip ehs-windows-amd64.zip
api_key: '${{secrets.RELEASE_TOKEN}}' api_key: '${{secrets.RELEASE_TOKEN}}'
pre_release: false
Linux-AMD64-Build: Linux-AMD64-Build:
runs-on: linux-x86_64 runs-on: linux-x86_64
@@ -103,7 +101,6 @@ jobs:
files: |- files: |-
ehs-linux-amd64.zip ehs-linux-amd64.zip
api_key: '${{secrets.RELEASE_TOKEN}}' api_key: '${{secrets.RELEASE_TOKEN}}'
pre_release: false
Linux-AARCH64-Build: Linux-AARCH64-Build:
runs-on: linux-aarch64 runs-on: linux-aarch64
@@ -148,4 +145,3 @@ jobs:
files: |- files: |-
ehs-linux-aarch64.zip ehs-linux-aarch64.zip
api_key: '${{secrets.RELEASE_TOKEN}}' api_key: '${{secrets.RELEASE_TOKEN}}'
pre_release: false

View File

@@ -97,8 +97,6 @@ set(EHS_SOURCES
include/ehs/system/OS.h include/ehs/system/OS.h
include/ehs/system/Semaphore.h include/ehs/system/Semaphore.h
include/ehs/system/System.h include/ehs/system/System.h
include/ehs/system/AVX2.h
include/ehs/system/AVX512.h
src/json/Json.cpp include/ehs/json/Json.h src/json/Json.cpp include/ehs/json/Json.h
src/json/JsonBase.cpp include/ehs/json/JsonBase.h src/json/JsonBase.cpp include/ehs/json/JsonBase.h
@@ -196,8 +194,11 @@ set(EHS_SOURCES
src/io/socket/ehc/NetClientCh.cpp src/io/socket/ehc/NetClientCh.cpp
src/io/socket/ehc/NetServerCh.cpp src/io/socket/ehc/NetServerCh.cpp
src/io/socket/ehc/NetUtils.cpp src/io/socket/ehc/NetUtils.cpp
include/ehs/io/socket/BaseICMP.h src/io/socket/BaseICMP.cpp src/io/socket/BaseICMP.cpp
include/ehs/io/socket/ICMP_LNX.h
src/io/socket/ICMP_LNX.cpp
include/ehs/io/socket/ICMP.h include/ehs/io/socket/ICMP.h
src/io/socket/ICMP_LNX.cpp
) )
if (IS_OS_WINDOWS) if (IS_OS_WINDOWS)
@@ -216,10 +217,7 @@ if (IS_OS_WINDOWS)
src/io/COM.cpp include/ehs/io/COM.h src/io/COM.cpp include/ehs/io/COM.h
src/system/CPU_MSVC_AMD64.asm src/HRNG_MSVC.asm src/Math_MSVC_AMD64.asm src/system/CPU_MSVC_AMD64.asm src/HRNG_MSVC.asm src/Math_MSVC_AMD64.asm
src/io/Directory_W32.cpp include/ehs/io/Directory_W32.h src/io/Directory_W32.cpp include/ehs/io/Directory_W32.h
include/ehs/io/socket/ICMP_W32.h src/io/socket/ICMP_W32.cpp
src/system/AVX2_MSVC_AMD64.asm src/system/AVX512_MSVC_AMD64.asm
) )
elseif (IS_OS_LINUX) elseif (IS_OS_LINUX)
list(APPEND EHS_SOURCES list(APPEND EHS_SOURCES
src/io/socket/UDP_BSD.cpp include/ehs/io/socket/UDP_BSD.h src/io/socket/UDP_BSD.cpp include/ehs/io/socket/UDP_BSD.h
@@ -236,7 +234,6 @@ elseif (IS_OS_LINUX)
src/system/User.cpp include/ehs/system/User.h src/system/User.cpp include/ehs/system/User.h
src/io/Directory_LNX.cpp include/ehs/io/Directory_LNX.h src/io/Directory_LNX.cpp include/ehs/io/Directory_LNX.h
src/io/Usb_LNX.cpp include/ehs/io/Usb_LNX.h src/io/Usb_LNX.cpp include/ehs/io/Usb_LNX.h
include/ehs/io/socket/ICMP_LNX.h src/io/socket/ICMP_LNX.cpp
) )
#set(LINUX_WINDOW_SYSTEM "Wayland" CACHE STRING "Linux Window System") #set(LINUX_WINDOW_SYSTEM "Wayland" CACHE STRING "Linux Window System")
@@ -255,9 +252,9 @@ elseif (IS_OS_LINUX)
endif () endif ()
if (IS_ARCH_AMD64) if (IS_ARCH_AMD64)
list(APPEND EHS_SOURCES src/system/CPU_GCC_AMD64.asm src/HRNG_GCC.asm src/Math_GCC_AMD64.asm src/system/AVX2_GCC_AMD64.asm src/system/AVX512_GCC_AMD64.asm) list(APPEND EHS_SOURCES src/system/CPU_GCC_AMD64.asm src/HRNG_GCC.asm src/Math_GCC_AMD64.asm)
elseif (IS_ARCH_ARM64) elseif (IS_ARCH_ARM64)
list(APPEND EHS_SOURCES src/system/CPU_ARM64.cpp src/HRNG_ARM64.cpp src/Math_GCC_ARM64.s src/system/AVX2_AARCH64.cpp src/system/AVX512_AARCH64.cpp) list(APPEND EHS_SOURCES src/system/CPU_ARM64.cpp src/HRNG_ARM64.cpp src/Math_GCC_ARM64.s)
endif () endif ()
endif() endif()
@@ -265,7 +262,8 @@ endif()
#message("${CMAKE_CXX_FLAGS}") #message("${CMAKE_CXX_FLAGS}")
add_library(EHS_Stc STATIC ${EHS_SOURCES}) add_library(EHS_Stc STATIC ${EHS_SOURCES})
add_library(EHS_Dyn SHARED ${EHS_SOURCES}) add_library(EHS_Dyn SHARED ${EHS_SOURCES}
include/ehs/io/socket/BaseICMP.h)
add_executable(StrToHash src/StrToHash.cpp) add_executable(StrToHash src/StrToHash.cpp)
target_compile_definitions(EHS_Dyn PRIVATE EHS_LIB_EXPORT) target_compile_definitions(EHS_Dyn PRIVATE EHS_LIB_EXPORT)
@@ -315,7 +313,7 @@ target_link_libraries(EHS_Dyn OpenSSL::SSL OpenSSL::Crypto ZLIB::ZLIB)
target_link_libraries(StrToHash OpenSSL::SSL OpenSSL::Crypto ZLIB::ZLIB) target_link_libraries(StrToHash OpenSSL::SSL OpenSSL::Crypto ZLIB::ZLIB)
if (IS_OS_WINDOWS) if (IS_OS_WINDOWS)
target_link_libraries(EHS_Dyn avrt ws2_32 IPHLPAPI) target_link_libraries(EHS_Dyn avrt ws2_32)
target_link_libraries(StrToHash ws2_32 avrt EHS_Stc) target_link_libraries(StrToHash ws2_32 avrt EHS_Stc)
elseif (IS_OS_LINUX) elseif (IS_OS_LINUX)
if (LINUX_WINDOW_SYSTEM STREQUAL "Wayland") if (LINUX_WINDOW_SYSTEM STREQUAL "Wayland")

View File

@@ -22,7 +22,6 @@ This project does not fully follow the C++ standard.
- Semaphores - Semaphores
- CPU information and features at runtime - CPU information and features at runtime
- HTTP(S) Socket Layer - HTTP(S) Socket Layer
- ICMP & ICMPv6 Socket
- TCP Socket - TCP Socket
- UDP Socket - UDP Socket
- COM (Serial) IO - COM (Serial) IO

View File

@@ -134,17 +134,17 @@ namespace ehs
#ifndef EHS_LOG_INT #ifndef EHS_LOG_INT
#ifdef EHS_DEBUG #ifdef EHS_DEBUG
#define EHS_LOG_INT(type, code, msg) ehs::Log::Raise(ehs::Log(type, {ehs::GetAcronym_8(), EHS_FILE, EHS_FUNC, ehs::Str_8::FromNum((ehs::UInt_32)EHS_LINE)}, code, msg)) #define EHS_LOG_INT(type, code, msg) ehs::Log::Raise({type, {ehs::GetAcronym_8(), EHS_FILE, EHS_FUNC, ehs::Str_8::FromNum((ehs::UInt_32)EHS_LINE)}, code, msg})
#else #else
#define EHS_LOG_INT(type, code, msg) ehs::Log::Raise(ehs::Log(type, {ehs::GetAcronym_8(), EHS_FUNC}, code, msg)) #define EHS_LOG_INT(type, code, msg) ehs::Log::Raise({type, {ehs::GetAcronym_8(), EHS_FUNC}, code, msg})
#endif #endif
#endif #endif
#ifndef EHS_LOG #ifndef EHS_LOG
#ifdef EHS_DEBUG #ifdef EHS_DEBUG
#define EHS_LOG(type, code, msg) ehs::Log::Raise(ehs::Log(type, {ehs::GetAppName_8(), EHS_FILE, EHS_FUNC, ehs::Str_8::FromNum((ehs::UInt_32)EHS_LINE)}, code, msg)) #define EHS_LOG(type, code, msg) ehs::Log::Raise({type, {ehs::GetAppName_8(), EHS_FILE, EHS_FUNC, ehs::Str_8::FromNum((ehs::UInt_32)EHS_LINE)}, code, msg})
#else #else
#define EHS_LOG(type, code, msg) ehs::Log::Raise(ehs::Log(type, {ehs::GetAppName_8(), EHS_FUNC}, code, msg)) #define EHS_LOG(type, code, msg) ehs::Log::Raise({type, {ehs::GetAppName_8(), EHS_FUNC}, code, msg})
#endif #endif
#endif #endif

View File

@@ -48,11 +48,8 @@ namespace ehs
/// @param [in] str The C-style string. /// @param [in] str The C-style string.
/// @param [in] size The size of the given C-style string. /// @param [in] size The size of the given C-style string.
Str(const T* const str, const N size) Str(const T* const str, const N size)
: size(size), data(nullptr) : size((size) ? size : Len(str)), data(nullptr)
{ {
if (!size)
return;
data = new T[this->size + 1]; data = new T[this->size + 1];
Util::Copy(data, str, Size(true)); Util::Copy(data, str, Size(true));
@@ -917,10 +914,10 @@ namespace ehs
} }
/// Splits a string into a Vector with the given separator. /// Splits a string into a Vector with the given separator.
/// @param [in] delimeter The given string as the separator. /// @param [in] ide The given string as the separator.
/// @param [in] max The max amount of times to split the string. /// @param [in] max The max amount of times to split the string.
/// @returns The resulting string object. /// @returns The resulting string object.
Vector<Str<T, N>, N> Split(const Str<T, N>& delimeter, const N max = 0) const Vector<Str<T, N>, N> Split(const Str<T, N>& ide, const N max = 0) const
{ {
Vector<Str<T, N>, N> result(0, 5); Vector<Str<T, N>, N> result(0, 5);
@@ -928,9 +925,9 @@ namespace ehs
for (N i = 0, c = 0; i < size; ++i) for (N i = 0, c = 0; i < size; ++i)
{ {
if (data[i] == delimeter[c]) if (data[i] == ide[c])
{ {
if (++c == delimeter.Size()) if (++c == ide.Size())
{ {
N r = i - (c - 1) - b; N r = i - (c - 1) - b;
if (!r) if (!r)
@@ -958,17 +955,17 @@ namespace ehs
} }
/// Removes all instances of the ide. /// Removes all instances of the ide.
/// @param [in] delimeter The string to look for. /// @param [in] ide The string to look for.
/// @returns The resulting string object. /// @returns The resulting string object.
Str<T, N> RemoveAll(const Str<T, N>& delimeter) const Str<T, N> RemoveAll(const Str<T, N>& ide) const
{ {
Str<T, N> result(size); Str<T, N> result(size);
for (N i = 0, b = 0, c = 0; i < size; ++i) for (N i = 0, b = 0, c = 0; i < size; ++i)
{ {
if (data[i] == delimeter[c]) if (data[i] == ide[c])
{ {
if (++c == delimeter.Size()) if (++c == ide.Size())
c = 0; c = 0;
} }
else else
@@ -987,18 +984,18 @@ namespace ehs
} }
/// Replaces all instances of ide with the replacer. /// Replaces all instances of ide with the replacer.
/// @param [in] delimeter The string to look for. /// @param [in] ide The string to look for.
/// @param [in] replacer The string placed. /// @param [in] replacer The string placed.
/// @returns The resulting string object. /// @returns The resulting string object.
Str ReplaceAll(const Str& delimeter, const Str& replacer) const Str ReplaceAll(const Str& ide, const Str& replacer) const
{ {
Str<T, N> result; Str<T, N> result;
for (N i = 0, b = 0; i < size; ++i) for (N i = 0, b = 0; i < size; ++i)
{ {
if (data[i] == delimeter[b]) if (data[i] == ide[b])
{ {
if (++b == delimeter.Size()) if (++b == ide.Size())
{ {
result.Push(replacer); result.Push(replacer);
b = 0; b = 0;
@@ -1014,20 +1011,20 @@ namespace ehs
} }
/// Finds the first instance of the given string object. /// Finds the first instance of the given string object.
/// @param [in] delimeter The string to look for. /// @param [in] ide The string to look for.
/// @param [out] index The index of the string found. Can be a nullptr. /// @param [out] index The index of the string found. Can be a nullptr.
/// @param [in] pattern The search pattern for optimization. /// @param [in] pattern The search pattern for optimization.
/// @param [in] result What index to return where the first instance is found. /// @param [in] result What index to return where the first instance is found.
/// @returns The index where the instance was found with the result varying from the result parameter. /// @returns The index where the instance was found with the result varying from the result parameter.
bool Find(const Str<T, N> &delimeter, N* const index = nullptr, const SearchPattern pattern = SearchPattern::LEFT_RIGHT, const IndexResult result = IndexResult::BEGINNING) const bool Find(const Str<T, N> &ide, N* const index = nullptr, const SearchPattern pattern = SearchPattern::LEFT_RIGHT, const IndexResult result = IndexResult::BEGINNING) const
{ {
if (pattern == SearchPattern::LEFT_RIGHT) if (pattern == SearchPattern::LEFT_RIGHT)
{ {
for (N i = 0, c = 0; i < size; ++i) for (N i = 0, c = 0; i < size; ++i)
{ {
if (data[i] == delimeter[c]) if (data[i] == ide[c])
{ {
if (++c == delimeter.Size()) if (++c == ide.Size())
{ {
if (result == IndexResult::BEGINNING) if (result == IndexResult::BEGINNING)
{ {
@@ -1049,16 +1046,16 @@ namespace ehs
} }
else if (pattern == SearchPattern::RIGHT_LEFT) else if (pattern == SearchPattern::RIGHT_LEFT)
{ {
for (N i = size, c = delimeter.Size(); i > 0; --i) for (N i = size, c = ide.Size(); i > 0; --i)
{ {
if (data[i - 1] == delimeter[c - 1]) if (data[i - 1] == ide[c - 1])
{ {
if (--c == 0) if (--c == 0)
{ {
if (result == IndexResult::BEGINNING) if (result == IndexResult::BEGINNING)
{ {
if (index) if (index)
*index = i - (delimeter.Size() - 1); *index = i - (ide.Size() - 1);
return true; return true;
} }
@@ -1078,18 +1075,18 @@ namespace ehs
} }
/// Checks if the current string contains the given ide. /// Checks if the current string contains the given ide.
/// @param [in] delimeter The given ide to check for. /// @param [in] ide The given ide to check for.
/// @param [in] pattern The search pattern to use. /// @param [in] pattern The search pattern to use.
/// @returns True if the current string does contain the ide. /// @returns True if the current string does contain the ide.
bool Contains(const Str<T, N>& delimeter, const SearchPattern pattern = SearchPattern::LEFT_RIGHT) const bool Contains(const Str<T, N>& ide, const SearchPattern pattern = SearchPattern::LEFT_RIGHT) const
{ {
if (pattern == SearchPattern::LEFT_RIGHT) if (pattern == SearchPattern::LEFT_RIGHT)
{ {
for (N i = 0, c = 0; i < size; ++i) for (N i = 0, c = 0; i < size; ++i)
{ {
if (data[i] == delimeter[c]) if (data[i] == ide[c])
{ {
if (++c == delimeter.Size()) if (++c == ide.Size())
{ {
return true; return true;
} }
@@ -1098,9 +1095,9 @@ namespace ehs
} }
else if (pattern == SearchPattern::RIGHT_LEFT) else if (pattern == SearchPattern::RIGHT_LEFT)
{ {
for (N i = size, c = delimeter.Size(); i > 0; --i) for (N i = size, c = ide.Size(); i > 0; --i)
{ {
if (data[i - 1] == delimeter[c - 1]) if (data[i - 1] == ide[c - 1])
{ {
if (--c == 0) if (--c == 0)
{ {
@@ -1113,54 +1110,6 @@ namespace ehs
return false; return false;
} }
Vector<Str> ParseArgs() const
{
Vector<Str> args;
T *quoteStart = nullptr;
T *spaceStart = nullptr;
for (T *i = data; i <= data + size; ++i)
{
if (*i == '\"' && !spaceStart)
{
if (quoteStart)
{
args.Push(Str(quoteStart, i - quoteStart));
quoteStart = nullptr;
}
else
{
if (i + 1 < &data[size - 1])
quoteStart = i + 1;
else
args.Push({});
}
}
else if (*i == ' ' && !quoteStart)
{
if (spaceStart)
{
args.Push(Str(spaceStart, i - spaceStart));
spaceStart = i + 1;
}
else
{
if (i + 1 < &data[size - 1])
spaceStart = i + 1;
else
args.Push({});
}
}
}
if (quoteStart)
args.Push(Str(quoteStart, &data[size - 1] - (quoteStart - 1)));
else if (spaceStart)
args.Push(Str(spaceStart, &data[size - 1] - (spaceStart - 1)));
return args;
}
/// Checks if the string represents a number. Must not have any alphabetical characters. /// Checks if the string represents a number. Must not have any alphabetical characters.
/// @returns The result. /// @returns The result.
bool IsNum() const bool IsNum() const

View File

@@ -392,7 +392,7 @@ namespace ehs
{ {
if (stride) if (stride)
{ {
rawSize = (this->size + size) / stride * stride; rawSize = (this->size + size()) / stride * stride;
if ((this->size + size) % stride) if ((this->size + size) % stride)
rawSize += stride; rawSize += stride;
} }
@@ -403,7 +403,7 @@ namespace ehs
T* result = new T[rawSize]; T* result = new T[rawSize];
for (N i = 0; i < this->size; ++i) for (N i = 0; i < size; ++i)
result[i] = std::move(data[i]); result[i] = std::move(data[i]);
delete[] data; delete[] data;

View File

@@ -25,8 +25,6 @@ namespace ehs
IP version; IP version;
public: public:
virtual ~BaseICMP() = default;
BaseICMP(); BaseICMP();
BaseICMP(IP version); BaseICMP(IP version);
@@ -39,30 +37,17 @@ namespace ehs
BaseICMP &operator=(const BaseICMP &icmp); BaseICMP &operator=(const BaseICMP &icmp);
virtual void Release(); virtual UInt_64 Send(const Str_8 &address, ICMP_Header header, const Byte *data, UInt_64 size);
UInt_64 Send(const Str_8 &address, ICMP_Header header, const Byte *data, UInt_64 size); virtual UInt_64 Receive(Str_8 &address, ICMP_Header header, Serializer<UInt_64> &data);
UInt_64 Receive(Str_8 &address, ICMP_Header &header, Serializer<UInt_64> &data);
void SendEchoRequest(const Str_8 &address, ICMP_EchoRequest er, const Byte *data, UInt_64 size); void SendEchoRequest(const Str_8 &address, ICMP_EchoRequest er, const Byte *data, UInt_64 size);
virtual void SetReceiveTimeout(UInt_64 timeout); virtual void SetReceiveTimeout(UInt_64 timeout);
IP GetVersion() const;
virtual bool IsValid() const; virtual bool IsValid() const;
protected: protected:
static UInt_16 ComputeChecksumV4(UInt_16 *buffer, Size length); static UInt_16 ComputeChecksum(UInt_16 *buffer, Size length);
private:
virtual UInt_64 SendV6(const Str_8 &address, ICMP_Header header, const Byte *data, UInt_64 size);
virtual UInt_64 SendV4(const Str_8 &address, ICMP_Header header, const Byte *data, UInt_64 size);
virtual UInt_64 ReceiveV6(Str_8 &address, ICMP_Header &header, Serializer<UInt_64> &data) const;
virtual UInt_64 ReceiveV4(Str_8 &address, ICMP_Header &header, Serializer<UInt_64> &data) const;
}; };
} }

View File

@@ -1,9 +1,7 @@
#pragma once #pragma once
#include "ehs/system/OS.h"
#ifdef EHS_OS_WINDOWS #ifdef EHS_OS_WINDOWS
#include "ICMP_W32.h" #include "BaseICMP.h"
#else #else
#include "ICMP_LNX.h" #include "ICMP_LNX.h"
#endif #endif

View File

@@ -2,26 +2,14 @@
#include "BaseICMP.h" #include "BaseICMP.h"
#include <netinet/in.h>
namespace ehs namespace ehs
{ {
struct PseudoICMPv6_Header class ICMP : public BaseICMP
{
sockaddr_in6 src;
sockaddr_in6 dst;
UInt_32 length;
};
class ICMP final : public BaseICMP
{ {
private: private:
Int_32 hdl; Int_32 hdl;
sockaddr_in6 src;
public: public:
~ICMP() override;
ICMP(); ICMP();
ICMP(IP version); ICMP(IP version);
@@ -34,27 +22,12 @@ namespace ehs
ICMP &operator=(const ICMP &icmp); ICMP &operator=(const ICMP &icmp);
void Release() override; UInt_64 Send(const Str_8 &address, ICMP_Header header, const Byte *data, UInt_64 size) override;
UInt_64 Receive(Str_8 &address, ICMP_Header header, Serializer<UInt_64> &data) override;
void SetReceiveTimeout(UInt_64 timeout) override; void SetReceiveTimeout(UInt_64 timeout) override;
bool IsValid() const override; bool IsValid() const override;
private:
static bool IsLinkLocal(const in6_addr &addr);
static sockaddr_in6 RetrieveSrcAddress();
static UInt_32 CalculatePseudoHeaderChecksum(const PseudoICMPv6_Header &header);
UInt_16 ComputeChecksumV6(UInt_16* buffer, Size length, const sockaddr_in6& dst);
UInt_64 SendV6(const Str_8 &address, ICMP_Header header, const Byte *data, UInt_64 size) override;
UInt_64 SendV4(const Str_8 &address, ICMP_Header header, const Byte *data, UInt_64 size) override;
UInt_64 ReceiveV6(Str_8 &address, ICMP_Header &header, Serializer<UInt_64> &data) const override;
UInt_64 ReceiveV4(Str_8 &address, ICMP_Header &header, Serializer<UInt_64> &data) const override;
}; };
} }

View File

@@ -1,63 +0,0 @@
#pragma once
#include "BaseICMP.h"
#include "ehs/System/OS.h"
#include <winsock2.h>
#include <WS2tcpip.h>
#include <iphlpapi.h>
namespace ehs
{
struct PseudoICMPv6_Header
{
sockaddr_in6 src;
sockaddr_in6 dst;
UInt_32 length;
};
class ICMP : public BaseICMP
{
private:
Socket hdl;
sockaddr_in6 src;
public:
~ICMP() override;
ICMP();
ICMP(IP version);
ICMP(ICMP &&icmp) noexcept;
ICMP(const ICMP &icmp);
ICMP &operator=(ICMP &&icmp) noexcept;
ICMP &operator=(const ICMP &icmp);
void Release() override;
void SetReceiveTimeout(UInt_64 timeout) override;
bool IsValid() const override;
private:
static bool IsLinkLocal(const in6_addr &addr);
static sockaddr_in6 RetrieveSrcAddress();
static UInt_32 CalculatePseudoHeaderChecksum(const PseudoICMPv6_Header &header);
UInt_16 ComputeChecksumV6(UInt_16* buffer, Size length, const sockaddr_in6& dst);
UInt_64 SendV6(const Str_8 &address, ICMP_Header header, const Byte *data, UInt_64 size) override;
UInt_64 SendV4(const Str_8 &address, ICMP_Header header, const Byte *data, UInt_64 size) override;
UInt_64 ReceiveV6(Str_8 &address, ICMP_Header &header, Serializer<UInt_64> &data) const override;
UInt_64 ReceiveV4(Str_8 &address, ICMP_Header &header, Serializer<UInt_64> &data) const override;
};
}

View File

@@ -1,36 +0,0 @@
#pragma once
#include "ehs/Types.h"
namespace ehs
{
class AVX2
{
public:
/// Compares two unaligned 4 element vectors using 64-bit integers.
/// @param [in] a First vector.
/// @param [in] b Second vector.
/// @returns True if all 4 elements are equal. False otherwise.
static bool CompareUnaligned(const UInt_64 *a, const UInt_64 *b);
/// Compares two unaligned 4 element vectors using 64-bit integers.
/// @param [in] a First vector.
/// @param [in] b Second vector.
/// @returns True if all 4 elements are equal. False otherwise.
static bool CompareUnaligned(const SInt_64 *a, const SInt_64 *b);
/// Compares two aligned 4 element vectors using 64-bit integers.
/// @param [in] a First vector.
/// @param [in] b Second vector.
/// @returns True if all 4 elements are equal. False otherwise.
/// @note The parameters "a", and "b" must have alignas(32).
static bool CompareAligned(const UInt_64 *a, const UInt_64 *b);
/// Compares two aligned 4 element vectors using 64-bit integers.
/// @param [in] a First vector.
/// @param [in] b Second vector.
/// @returns True if all 4 elements are equal. False otherwise.
/// @note The parameters "a", and "b" must have alignas(32).
static bool CompareAligned(const SInt_64 *a, const SInt_64 *b);
};
}

View File

@@ -1,36 +0,0 @@
#pragma once
#include "ehs/Types.h"
namespace ehs
{
class AVX512
{
public:
/// Compares two unaligned 8 element vectors using 64-bit integers.
/// @param [in] a First vector.
/// @param [in] b Second vector.
/// @returns True if all 8 elements are equal. False otherwise.
static bool CompareUnaligned(const UInt_64 *a, const UInt_64 *b);
/// Compares two unaligned 8 element vectors using 64-bit integers.
/// @param [in] a First vector.
/// @param [in] b Second vector.
/// @returns True if all 8 elements are equal. False otherwise.
static bool CompareUnaligned(const SInt_64 *a, const SInt_64 *b);
/// Compares two aligned 8 element vectors using 64-bit integers.
/// @param [in] a First vector.
/// @param [in] b Second vector.
/// @returns True if all 8 elements are equal. False otherwise.
/// @note The parameters "a", and "b" must have alignas(32).
static bool CompareAligned(const UInt_64 *a, const UInt_64 *b);
/// Compares two aligned 8 element vectors using 64-bit integers.
/// @param [in] a First vector.
/// @param [in] b Second vector.
/// @returns True if all 8 elements are equal. False otherwise.
/// @note The parameters "a", and "b" must have alignas(32).
static bool CompareAligned(const SInt_64 *a, const SInt_64 *b);
};
}

View File

@@ -38,70 +38,6 @@ namespace ehs
#endif #endif
public: public:
static const bool hasFPU;
static const bool hasVME;
static const bool hasDE;
static const bool hasPSE;
static const bool hasTSC;
static const bool hasMSR;
static const bool hasPAE;
static const bool hasMCE;
static const bool hasCX8;
static const bool hasAPIC;
static const bool hasSEP;
static const bool hasMTRR;
static const bool hasPGE;
static const bool hasMCA;
static const bool hasCMOV;
static const bool hasPSE_36;
static const bool hasPSN;
static const bool hasCLFSH;
static const bool hasDS;
static const bool hasACPI;
static const bool hasMMX;
static const bool hasFXSR;
static const bool hasSSE;
static const bool hasSSE2;
static const bool hasSS;
static const bool hasHTT;
static const bool hasTM;
static const bool hasIA64;
static const bool hasPBE;
static const bool hasSSE3;
static const bool hasPCLMULQDQ;
static const bool hasDTES64;
static const bool hasMONITOR;
static const bool hasVMX;
static const bool hasSMX;
static const bool hasEST;
static const bool hasTM2;
static const bool hasSSSE3;
static const bool hasCNXT_ID;
static const bool hasSDBG;
static const bool hasFMA;
static const bool hasCX16;
static const bool hasXTPR;
static const bool hasPDCM;
static const bool hasPCID;
static const bool hasDCA;
static const bool hasSSE4_1;
static const bool hasSSE4_2;
static const bool hasX2APIC;
static const bool hasMOVBE;
static const bool hasPOPCNT;
static const bool hasTSC_DEADLINE;
static const bool hasAES;
static const bool hasXSAVE;
static const bool hasOSXSAVE;
static const bool hasAVX;
static const bool hasF16C;
static const bool hasRDRND;
static const bool hasHYPERVISOR;
static const bool hasAVX2;
static const bool hasAVX512F;
static const bool hasRDSEED;
static const bool hasADX;
static Architecture GetArchitecture(); static Architecture GetArchitecture();
static UInt_8 PointerSize(); static UInt_8 PointerSize();
@@ -132,155 +68,153 @@ namespace ehs
static UInt_8 GetExtFamilyId(); 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. /// Retrieves the CPU brand as a null-terminated ASCII string.
/// @param[out] input A 48 byte character array representing the brand. /// @param[out] input A 48 byte character array representing the brand.
static void GetBrand(Char_8* input); static void GetBrand(Char_8* input);
static UInt_8 GetCacheLineSize(); static UInt_8 GetCacheLineSize();
static UInt_32 GetFeatureBits_1();
static UInt_32 GetFeatureBits_2();
static UInt_32 GetExtFeatureBits_1();
static UInt_32 GetExtFeatureBits_2();
static UInt_32 GetExtFeatureBits_3();
private:
static bool RetrieveFPU();
static bool RetrieveVME();
static bool RetrieveDE();
static bool RetrievePSE();
static bool RetrieveTSC();
static bool RetrieveMSR();
static bool RetrievePAE();
static bool RetrieveMCE();
static bool RetrieveCX8();
static bool RetrieveAPIC();
static bool RetrieveSEP();
static bool RetrieveMTRR();
static bool RetrievePGE();
static bool RetrieveMCA();
static bool RetrieveCMOV();
static bool RetrievePAT();
static bool RetrievePSE_36();
static bool RetrievePSN();
static bool RetrieveCLFSH();
static bool RetrieveDS();
static bool RetrieveACPI();
static bool RetrieveMMX();
static bool RetrieveFXSR();
static bool RetrieveSSE();
static bool RetrieveSSE2();
static bool RetrieveSS();
static bool RetrieveHTT();
static bool RetrieveTM();
static bool RetrieveIA64();
static bool RetrievePBE();
static bool RetrieveSSE3();
static bool RetrievePCLMULQDQ();
static bool RetrieveDTES64();
static bool RetrieveMONITOR();
static bool RetrieveDS_CPL();
static bool RetrieveVMX();
static bool RetrieveSMX();
static bool RetrieveEST();
static bool RetrieveTM2();
static bool RetrieveSSSE3();
static bool RetrieveCNXT_ID();
static bool RetrieveSDBG();
static bool RetrieveFMA();
static bool RetrieveCX16();
static bool RetrieveXTPR();
static bool RetrievePDCM();
static bool RetrievePCID();
static bool RetrieveDCA();
static bool RetrieveSSE4_1();
static bool RetrieveSSE4_2();
static bool RetrieveX2APIC();
static bool RetrieveMOVBE();
static bool RetrievePOPCNT();
static bool RetrieveTSC_DEADLINE();
static bool RetrieveAES();
static bool RetrieveXSAVE();
static bool RetrieveOSXSAVE();
static bool RetrieveAVX();
static bool RetrieveF16C();
static bool RetrieveRDRND();
static bool RetrieveHYPERVISOR();
static bool RetrieveAVX2();
static bool RetrieveAVX512F();
static bool RetrieveRDSEED();
static bool RetrieveADX();
//static Str_8 ToStr(); //static Str_8 ToStr();
private:
static UInt_64 RetrieveTSC_Freq(); static UInt_64 RetrieveTSC_Freq();
static UInt_64 CalculateTSC_Freq(); static UInt_64 CalculateTSC_Freq();

View File

@@ -36,9 +36,9 @@ namespace ehs
double Math::Sqrt(const double from) double Math::Sqrt(const double from)
{ {
#if defined(EHS_ARCH_X64) #if defined(EHS_ARCH_X64)
if (CPU::hasAVX) if (CPU::HasAVX())
return Sqrt_AVX(from); return Sqrt_AVX(from);
else if (CPU::hasSSE) else if (CPU::HasSSE())
return Sqrt_SSE2(from); return Sqrt_SSE2(from);
double temp = 0.0; double temp = 0.0;
@@ -59,9 +59,9 @@ namespace ehs
float Math::Sqrt(const float from) float Math::Sqrt(const float from)
{ {
#if defined(EHS_ARCH_X64) #if defined(EHS_ARCH_X64)
if (CPU::hasAVX) if (CPU::HasAVX())
return Sqrt_AVX(from); return Sqrt_AVX(from);
else if (CPU::hasSSE) else if (CPU::HasSSE())
return Sqrt_SSE(from); return Sqrt_SSE(from);
float temp = 0.0f; float temp = 0.0f;

View File

@@ -1,9 +1,5 @@
#include "ehs/Util.h" #include "ehs/Util.h"
#include "ehs/system/CPU.h"
#include "ehs/system/AVX2.h"
#include "ehs/system/AVX512.h"
namespace ehs namespace ehs
{ {
bool Util::Compare(const void* const a, const void* const b, const UInt_64 size) bool Util::Compare(const void* const a, const void* const b, const UInt_64 size)

View File

@@ -693,7 +693,7 @@ namespace ehs
Vector<Str_32> Console::GetArgs_32(const UInt_64 bufferSize) Vector<Str_32> Console::GetArgs_32(const UInt_64 bufferSize)
{ {
#if defined(EHS_OS_WINDOWS) #if defined(EHS_OS_WINDOWS)
return UTF::To_32(GetCommandLineW()).ParseArgs(); return UTF::To_32(GetCommandLineW()).Split(U" ");
#elif defined(EHS_OS_LINUX) #elif defined(EHS_OS_LINUX)
File cmdFile("/proc/self/cmdline", Mode::READ, Disposition::OPEN); File cmdFile("/proc/self/cmdline", Mode::READ, Disposition::OPEN);
Array<Byte> data = cmdFile.ReadArray(bufferSize); Array<Byte> data = cmdFile.ReadArray(bufferSize);
@@ -725,7 +725,7 @@ namespace ehs
Vector<Str_16> Console::GetArgs_16(const UInt_64 bufferSize) Vector<Str_16> Console::GetArgs_16(const UInt_64 bufferSize)
{ {
#if defined(EHS_OS_WINDOWS) #if defined(EHS_OS_WINDOWS)
return Str_16(GetCommandLineW()).ParseArgs(); return Str_16(GetCommandLineW()).Split(L" ");
#elif defined(EHS_OS_LINUX) #elif defined(EHS_OS_LINUX)
File cmdFile("/proc/self/cmdline", Mode::READ, Disposition::OPEN); File cmdFile("/proc/self/cmdline", Mode::READ, Disposition::OPEN);
Array<Byte> data = cmdFile.ReadArray(bufferSize); Array<Byte> data = cmdFile.ReadArray(bufferSize);
@@ -755,7 +755,7 @@ namespace ehs
Vector<Str_8> Console::GetArgs_8(const UInt_64 bufferSize) Vector<Str_8> Console::GetArgs_8(const UInt_64 bufferSize)
{ {
#if defined(EHS_OS_WINDOWS) #if defined(EHS_OS_WINDOWS)
return UTF::To_8(GetCommandLineW()).ParseArgs(); return UTF::To_8(GetCommandLineW()).Split(" ");
#elif defined(EHS_OS_LINUX) #elif defined(EHS_OS_LINUX)
File cmdFile("/proc/self/cmdline", Mode::READ, Disposition::OPEN); File cmdFile("/proc/self/cmdline", Mode::READ, Disposition::OPEN);
Array<Byte> data = cmdFile.ReadArray(bufferSize); Array<Byte> data = cmdFile.ReadArray(bufferSize);

View File

@@ -1,6 +1,8 @@
#include "ehs/io/socket/BaseICMP.h" #include "ehs/io/socket/BaseICMP.h"
#include "ehs/Serializer.h" #include "ehs/Serializer.h"
#include <netinet/ip.h>
namespace ehs namespace ehs
{ {
@@ -45,24 +47,14 @@ namespace ehs
return *this; return *this;
} }
void BaseICMP::Release()
{
}
UInt_64 BaseICMP::Send(const Str_8 &address, ICMP_Header header, const Byte *data, UInt_64 size) UInt_64 BaseICMP::Send(const Str_8 &address, ICMP_Header header, const Byte *data, UInt_64 size)
{ {
if (GetVersion() == IP::V6) return 0;
return SendV6(address, header, data, size);
return SendV4(address, header, data, size);
} }
UInt_64 BaseICMP::Receive(Str_8 &address, ICMP_Header &header, Serializer<UInt_64> &data) UInt_64 BaseICMP::Receive(Str_8 &address, ICMP_Header header, Serializer<UInt_64> &data)
{ {
if (GetVersion() == IP::V6) return 0;
return ReceiveV6(address, header, data);
return ReceiveV4(address, header, data);
} }
void BaseICMP::SendEchoRequest(const Str_8 &address, ICMP_EchoRequest er, const Byte *data, UInt_64 size) void BaseICMP::SendEchoRequest(const Str_8 &address, ICMP_EchoRequest er, const Byte *data, UInt_64 size)
@@ -75,7 +67,7 @@ namespace ehs
} }
ICMP_Header header = { ICMP_Header header = {
version == IP::V6 ? (UInt_8)128 : (UInt_8)8, 8,
0, 0,
0 0
}; };
@@ -95,17 +87,12 @@ namespace ehs
{ {
} }
IP BaseICMP::GetVersion() const
{
return version;
}
bool BaseICMP::IsValid() const bool BaseICMP::IsValid() const
{ {
return false; return false;
} }
UInt_16 BaseICMP::ComputeChecksumV4(UInt_16 *buffer, Size length) UInt_16 BaseICMP::ComputeChecksum(UInt_16 *buffer, Size length)
{ {
Size sum = 0; Size sum = 0;
while (length > 1) while (length > 1)
@@ -122,24 +109,4 @@ namespace ehs
return (UInt_16)~sum; return (UInt_16)~sum;
} }
UInt_64 BaseICMP::SendV6(const Str_8 &address, ICMP_Header header, const Byte *data, UInt_64 size)
{
return 0;
}
UInt_64 BaseICMP::SendV4(const Str_8 &address, ICMP_Header header, const Byte *data, UInt_64 size)
{
return 0;
}
UInt_64 BaseICMP::ReceiveV6(Str_8 &address, ICMP_Header &header, Serializer<UInt_64> &data) const
{
return 0;
}
UInt_64 BaseICMP::ReceiveV4(Str_8 &address, ICMP_Header &header, Serializer<UInt_64> &data) const
{
return 0;
}
} }

View File

@@ -5,30 +5,18 @@
#include <arpa/inet.h> #include <arpa/inet.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <netinet/ip.h> #include <netinet/ip.h>
#include <ifaddrs.h>
#include <unistd.h>
namespace ehs namespace ehs
{ {
ICMP::~ICMP()
{
if (close(hdl) == -1)
EHS_LOG_INT(LogType::ERR, 0, "Failed to close socket.");
}
ICMP::ICMP() ICMP::ICMP()
: hdl(EHS_INVALID_SOCKET), src{} : hdl(EHS_INVALID_SOCKET)
{ {
} }
ICMP::ICMP(const IP version) ICMP::ICMP(const IP version)
: BaseICMP(version), src{} : BaseICMP(version)
{ {
if (version == IP::V6)
hdl = socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6);
else
hdl = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP); hdl = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP);
if (hdl < 0) if (hdl < 0)
{ {
EHS_LOG_INT(LogType::ERR, 0, "Failed to create ICMP socket with error #" + Str_8::FromNum(errno) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to create ICMP socket with error #" + Str_8::FromNum(errno) + ".");
@@ -39,14 +27,13 @@ namespace ehs
} }
ICMP::ICMP(ICMP &&icmp) noexcept ICMP::ICMP(ICMP &&icmp) noexcept
: BaseICMP((BaseICMP &&)icmp), hdl(icmp.hdl), src(icmp.src) : BaseICMP((BaseICMP &&)icmp), hdl(icmp.hdl)
{ {
icmp.hdl = EHS_INVALID_SOCKET; icmp.hdl = EHS_INVALID_SOCKET;
icmp.src = {};
} }
ICMP::ICMP(const ICMP &icmp) ICMP::ICMP(const ICMP &icmp)
: BaseICMP(icmp), hdl(icmp.hdl), src{} : BaseICMP(icmp), hdl(icmp.hdl)
{ {
} }
@@ -58,10 +45,8 @@ namespace ehs
BaseICMP::operator=((BaseICMP &&)icmp); BaseICMP::operator=((BaseICMP &&)icmp);
hdl = icmp.hdl; hdl = icmp.hdl;
src = icmp.src;
icmp.hdl = EHS_INVALID_SOCKET; icmp.hdl = EHS_INVALID_SOCKET;
icmp.src = {};
return *this; return *this;
} }
@@ -74,136 +59,11 @@ namespace ehs
BaseICMP::operator=(icmp); BaseICMP::operator=(icmp);
hdl = icmp.hdl; hdl = icmp.hdl;
src = {};
return *this; return *this;
} }
void ICMP::Release() UInt_64 ICMP::Send(const Str_8 &address, ICMP_Header header, const Byte *data, const UInt_64 size)
{
if (close(hdl) == -1)
{
EHS_LOG_INT(LogType::ERR, 0, "Failed to close socket.");
return;
}
hdl = EHS_INVALID_SOCKET;
EHS_LOG_SUCCESS();
}
void ICMP::SetReceiveTimeout(const UInt_64 timeout)
{
timeval result = {};
result.tv_sec = (long)timeout;
result.tv_usec = 0;
if (setsockopt(hdl, SOL_SOCKET, SO_RCVTIMEO, &result, sizeof(result)) < 0)
{
EHS_LOG_INT(LogType::WARN, 0, "Failed to set receive timeout with error #" + Str_8::FromNum(errno) + ".");
return;
}
EHS_LOG_SUCCESS();
}
bool ICMP::IsValid() const
{
return hdl != EHS_INVALID_SOCKET;
}
bool ICMP::IsLinkLocal(const in6_addr &addr)
{
return addr.s6_addr[0] == 0xfe && (addr.s6_addr[1] & 0xc0) == 0x80;
}
sockaddr_in6 ICMP::RetrieveSrcAddress()
{
ifaddrs *ifaddr;
sockaddr_in6 addr = {};
if (getifaddrs(&ifaddr) == -1)
{
EHS_LOG_INT(LogType::ERR, 0, "Failed to retrieve public address with error #" + Str_8::FromNum(errno) + ".");
return addr;
}
for (ifaddrs *ifa = ifaddr; ifa; ifa = ifa->ifa_next)
{
if (ifa->ifa_addr == nullptr || ifa->ifa_addr->sa_family != AF_INET6)
continue;
addr = *(sockaddr_in6 *)ifa->ifa_addr;
if (!addr.sin6_addr.s6_addr32[0] || IsLinkLocal(addr.sin6_addr))
continue;
break;
}
freeifaddrs(ifaddr);
EHS_LOG_SUCCESS();
return addr;
}
UInt_32 ICMP::CalculatePseudoHeaderChecksum(const PseudoICMPv6_Header &header)
{
UInt_32 checksum = 0;
for (UInt_8 i = 0; i < 16; ++i)
checksum += header.src.sin6_addr.s6_addr[i];
for (UInt_8 i = 0; i < 16; ++i)
checksum += header.dst.sin6_addr.s6_addr[i];
checksum += 58;
checksum += htons(header.length);
checksum = (checksum >> 16) + (checksum & 0xFFFF);
checksum += (checksum >> 16);
return checksum;
}
UInt_16 ICMP::ComputeChecksumV6(UInt_16 *buffer, Size length, const sockaddr_in6 &dst)
{
UInt_32 checksum = 0;
if (!src.sin6_addr.s6_addr32[0])
{
src = RetrieveSrcAddress();
if (!src.sin6_addr.s6_addr32[0])
{
EHS_LOG_INT(LogType::ERR, 0, "Could not retrieve a suitable global address.");
return checksum;
}
}
checksum += CalculatePseudoHeaderChecksum({src, dst, (UInt_32)length});
while (length > 1)
{
checksum += *buffer++;
length -= sizeof(UInt_16);
}
if (length == 1)
checksum += *(UInt_8 *)buffer;
// Carry over any overflow from the 16-bit result
checksum = (checksum >> 16) + (checksum & 0xFFFF);
checksum += (checksum >> 16);
// Return the 16-bit complement
return ~checksum;
}
UInt_64 ICMP::SendV6(const Str_8 &address, ICMP_Header header, const Byte *data, UInt_64 size)
{ {
if (!IsValid()) if (!IsValid())
{ {
@@ -222,17 +82,17 @@ namespace ehs
payload.SetOffset(payload.GetOffset() + size); payload.SetOffset(payload.GetOffset() + size);
sockaddr_in6 dst = {}; header.checksum = ComputeChecksum((UInt_16 *)&payload[0], payload.Size());
dst.sin6_family = AF_INET6;
inet_pton(AF_INET6, address, &(dst.sin6_addr));
header.checksum = ComputeChecksumV6((UInt_16 *)&payload[0], payload.Size(), dst);
payload.SetOffset(0); payload.SetOffset(0);
payload.Write(header); payload.Write(header);
payload.SetOffset(payload.Size()); payload.SetOffset(payload.Size());
SInt_64 sent = sendto(hdl, payload, payload.Size(), 0, (sockaddr *)&dst, sizeof(sockaddr_in6)); sockaddr_in dst_addr = {};
dst_addr.sin_family = AF_INET;
inet_pton(AF_INET, address, &(dst_addr.sin_addr));
SInt_64 sent = sendto(hdl, payload, payload.Size(), 0, (sockaddr *)&dst_addr, sizeof(dst_addr));
if (sent < 0) if (sent < 0)
{ {
EHS_LOG_INT(LogType::ERR, 0, "Failed to send packet with error #" + Str_8::FromNum(errno) + "."); EHS_LOG_INT(LogType::ERR, 0, "Failed to send packet with error #" + Str_8::FromNum(errno) + ".");
@@ -245,96 +105,7 @@ namespace ehs
return sent; return sent;
} }
UInt_64 ICMP::SendV4(const Str_8 &address, ICMP_Header header, const Byte *data, UInt_64 size) UInt_64 ICMP::Receive(Str_8 &address, ICMP_Header header, Serializer<UInt_64> &data)
{
if (!IsValid())
{
EHS_LOG_INT(LogType::WARN, 0, "Socket is not initialized.");
return 0;
}
header.checksum = 0;
Serializer<UInt_64> payload(Endianness::LE);
payload.Write(header);
payload.Resize(payload.Size() + size);
Util::Copy(&payload[payload.GetOffset()], data, size);
payload.SetOffset(payload.GetOffset() + size);
header.checksum = ComputeChecksumV4((UInt_16 *)&payload[0], payload.Size());
payload.SetOffset(0);
payload.Write(header);
payload.SetOffset(payload.Size());
sockaddr_in dst = {};
dst.sin_family = AF_INET;
inet_pton(AF_INET, address, &(dst.sin_addr));
SInt_64 sent = sendto(hdl, payload, payload.Size(), 0, (sockaddr *)&dst, sizeof(sockaddr_in));
if (sent < 0)
{
EHS_LOG_INT(LogType::ERR, 0, "Failed to send packet with error #" + Str_8::FromNum(errno) + ".");
return 0;
}
EHS_LOG_SUCCESS();
return sent;
}
UInt_64 ICMP::ReceiveV6(Str_8 &address, ICMP_Header &header, Serializer<UInt_64> &data) const
{
if (!IsValid())
{
EHS_LOG_INT(LogType::WARN, 0, "Socket is not initialized.");
return 0;
}
Serializer<UInt_64> payload(Endianness::LE);
payload.Resize(1500);
sockaddr_in6 remote = {};
socklen_t from_len = sizeof(remote);
SInt_64 recv = recvfrom(hdl, payload, 1500, 0, (sockaddr *)&remote, &from_len);
if (recv < 0)
{
int code = errno;
if (code == EAGAIN)
EHS_LOG_SUCCESS();
else
EHS_LOG_INT(LogType::ERR, 0, "Failed to receive packet with error #" + Str_8::FromNum(code) + ".");
return 0;
}
payload.Resize(recv);
char tmpAddr[INET6_ADDRSTRLEN];
if (!inet_ntop(remote.sin6_family, &remote.sin6_addr, tmpAddr, INET6_ADDRSTRLEN))
{
EHS_LOG_INT(LogType::ERR, 1, "Failed to convert IPv6 address with error #" + Str_8::FromNum(errno) + ".");
return recv;
}
address = tmpAddr;
header = payload.Read<ICMP_Header>();
data = Serializer<UInt_64>(payload.GetEndianness(), &payload[payload.GetOffset()], payload.Size() - payload.GetOffset());
EHS_LOG_SUCCESS();
return recv;
}
UInt_64 ICMP::ReceiveV4(Str_8 &address, ICMP_Header &header, Serializer<UInt_64> &data) const
{ {
if (!IsValid()) if (!IsValid())
{ {
@@ -381,4 +152,25 @@ namespace ehs
return recv; return recv;
} }
void ICMP::SetReceiveTimeout(UInt_64 timeout)
{
timeval result = {};
result.tv_sec = (long)timeout;
result.tv_usec = 0;
if (setsockopt(hdl, SOL_SOCKET, SO_RCVTIMEO, &result, sizeof(result)) < 0)
{
EHS_LOG_INT(LogType::WARN, 0, "Failed to set receive timeout with error #" + Str_8::FromNum(errno) + ".");
return;
}
EHS_LOG_SUCCESS();
}
bool ICMP::IsValid() const
{
return hdl != EHS_INVALID_SOCKET;
}
} }

View File

@@ -1,391 +0,0 @@
#include "ehs/io/socket/ICMP_W32.h"
struct iphdr
{
u_char ip_hl:4, ip_v:4;
u_char ip_tos;
u_short ip_len;
u_short ip_id;
u_short ip_off;
u_char ip_ttl;
u_char ip_p;
u_short ip_sum;
in_addr ip_src, ip_dst;
};
namespace ehs
{
ICMP::~ICMP()
{
if (closesocket(hdl) == -1)
EHS_LOG_INT(LogType::ERR, 0, "Failed to close socket.");
}
ICMP::ICMP()
: hdl(EHS_INVALID_SOCKET)
{
}
ICMP::ICMP(const IP version)
: BaseICMP(version)
{
hdl = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP);
if (hdl < 0)
{
EHS_LOG_INT(LogType::ERR, 0, "Failed to create ICMP socket with error #" + Str_8::FromNum(errno) + ".");
return;
}
EHS_LOG_SUCCESS();
}
ICMP::ICMP(ICMP &&icmp) noexcept
: BaseICMP((BaseICMP &&)icmp), hdl(icmp.hdl)
{
icmp.hdl = EHS_INVALID_SOCKET;
}
ICMP::ICMP(const ICMP &icmp)
: BaseICMP(icmp), hdl(icmp.hdl)
{
}
ICMP & ICMP::operator=(ICMP &&icmp) noexcept
{
if (this == &icmp)
return *this;
BaseICMP::operator=((BaseICMP &&)icmp);
hdl = icmp.hdl;
icmp.hdl = EHS_INVALID_SOCKET;
return *this;
}
ICMP & ICMP::operator=(const ICMP &icmp)
{
if (this == &icmp)
return *this;
BaseICMP::operator=(icmp);
hdl = icmp.hdl;
return *this;
}
void ICMP::Release()
{
if (closesocket(hdl) == -1)
{
EHS_LOG_INT(LogType::ERR, 0, "Failed to close socket.");
return;
}
hdl = EHS_INVALID_SOCKET;
EHS_LOG_SUCCESS();
}
void ICMP::SetReceiveTimeout(UInt_64 timeout)
{
timeval result = {};
result.tv_sec = (long)timeout;
result.tv_usec = 0;
if (setsockopt(hdl, SOL_SOCKET, SO_RCVTIMEO, (const char *)&result, sizeof(result)) < 0)
{
EHS_LOG_INT(LogType::WARN, 0, "Failed to set receive timeout with error #" + Str_8::FromNum(errno) + ".");
return;
}
EHS_LOG_SUCCESS();
}
bool ICMP::IsValid() const
{
return hdl != EHS_INVALID_SOCKET;
}
bool ICMP::IsLinkLocal(const in6_addr &addr)
{
return addr.s6_addr[0] == 0xfe && (addr.s6_addr[1] & 0xc0) == 0x80;
}
sockaddr_in6 ICMP::RetrieveSrcAddress()
{
sockaddr_in6 addr = {};
UInt_32 outBufLen = 15000;
Array<Byte> buffer(outBufLen);
PIP_ADAPTER_ADDRESSES pAdapterAddresses = (PIP_ADAPTER_ADDRESSES)&buffer[0];
if (GetAdaptersAddresses(AF_INET6, GAA_FLAG_INCLUDE_PREFIX, nullptr, pAdapterAddresses, (PULONG)&outBufLen) == ERROR_BUFFER_OVERFLOW)
{
buffer.Resize(outBufLen);
pAdapterAddresses = (PIP_ADAPTER_ADDRESSES)&buffer[0];
}
if (GetAdaptersAddresses(AF_INET6, GAA_FLAG_INCLUDE_PREFIX, nullptr, pAdapterAddresses, (PULONG)&outBufLen) == NO_ERROR)
{
for (PIP_ADAPTER_ADDRESSES adapter = pAdapterAddresses; adapter != nullptr; adapter = adapter->Next)
{
for (PIP_ADAPTER_UNICAST_ADDRESS addrInfo = adapter->FirstUnicastAddress; addrInfo != nullptr; addrInfo = addrInfo->Next)
{
SOCKADDR *sa = addrInfo->Address.lpSockaddr;
if (sa->sa_family != AF_INET6)
continue;
sockaddr_in6 *ipv6Addr = (sockaddr_in6 *)sa;
// Skip link-local addresses
if (IN6_IS_ADDR_LINKLOCAL(&ipv6Addr->sin6_addr))
continue;
addr = *ipv6Addr;
return addr; // Return the first suitable address
}
}
}
EHS_LOG_SUCCESS();
return addr; // Return an empty sockaddr_in6 if no valid address was found
}
UInt_32 ICMP::CalculatePseudoHeaderChecksum(const PseudoICMPv6_Header &header)
{
UInt_32 checksum = 0;
for (UInt_8 i = 0; i < 16; ++i)
checksum += header.src.sin6_addr.s6_addr[i];
for (UInt_8 i = 0; i < 16; ++i)
checksum += header.dst.sin6_addr.s6_addr[i];
checksum += 58;
checksum += htons(header.length);
checksum = (checksum >> 16) + (checksum & 0xFFFF);
checksum += (checksum >> 16);
return checksum;
}
UInt_16 ICMP::ComputeChecksumV6(UInt_16 *buffer, Size length, const sockaddr_in6 &dst)
{
UInt_32 checksum = 0;
if (!src.sin6_addr.u.Word[0])
{
src = RetrieveSrcAddress();
if (!src.sin6_addr.u.Word[0])
{
EHS_LOG_INT(LogType::ERR, 0, "Could not retrieve a suitable global address.");
return checksum;
}
}
checksum += CalculatePseudoHeaderChecksum({src, dst, (UInt_32)length});
while (length > 1)
{
checksum += *buffer++;
length -= sizeof(UInt_16);
}
if (length == 1)
checksum += *(UInt_8 *)buffer;
// Carry over any overflow from the 16-bit result
checksum = (checksum >> 16) + (checksum & 0xFFFF);
checksum += (checksum >> 16);
// Return the 16-bit complement
return ~checksum;
}
UInt_64 ICMP::SendV6(const Str_8 &address, ICMP_Header header, const Byte *data, UInt_64 size)
{
if (!IsValid())
{
EHS_LOG_INT(LogType::WARN, 0, "Socket is not initialized.");
return 0;
}
header.checksum = 0;
Serializer<UInt_64> payload(Endianness::LE);
payload.Write(header);
payload.Resize(payload.Size() + size);
Util::Copy(&payload[payload.GetOffset()], data, size);
payload.SetOffset(payload.GetOffset() + size);
sockaddr_in6 dst = {};
dst.sin6_family = AF_INET6;
inet_pton(AF_INET6, address, &(dst.sin6_addr));
header.checksum = ComputeChecksumV6((UInt_16 *)&payload[0], payload.Size(), dst);
payload.SetOffset(0);
payload.Write(header);
payload.SetOffset(payload.Size());
SInt_64 sent = sendto(hdl, (const char *)&payload[0], payload.Size(), 0, (sockaddr *)&dst, sizeof(sockaddr_in6));
if (sent < 0)
{
EHS_LOG_INT(LogType::ERR, 0, "Failed to send packet with error #" + Str_8::FromNum(errno) + ".");
return 0;
}
EHS_LOG_SUCCESS();
return sent;
}
UInt_64 ICMP::SendV4(const Str_8 &address, ICMP_Header header, const Byte *data, UInt_64 size)
{
if (!IsValid())
{
EHS_LOG_INT(LogType::WARN, 0, "Socket is not initialized.");
return 0;
}
header.checksum = 0;
Serializer<UInt_64> payload(Endianness::LE);
payload.Write(header);
payload.Resize(payload.Size() + size);
Util::Copy(&payload[payload.GetOffset()], data, size);
payload.SetOffset(payload.GetOffset() + size);
header.checksum = ComputeChecksumV4((UInt_16 *)&payload[0], payload.Size());
payload.SetOffset(0);
payload.Write(header);
payload.SetOffset(payload.Size());
sockaddr_in dst_addr = {};
dst_addr.sin_family = AF_INET;
inet_pton(AF_INET, address, &(dst_addr.sin_addr));
SInt_64 sent = sendto(hdl, (const char *)&payload[0], payload.Size(), 0, (sockaddr *)&dst_addr, sizeof(dst_addr));
if (sent < 0)
{
EHS_LOG_INT(LogType::ERR, 0, "Failed to send packet with error #" + Str_8::FromNum(errno) + ".");
return 0;
}
EHS_LOG_SUCCESS();
return sent;
}
UInt_64 ICMP::ReceiveV6(Str_8 &address, ICMP_Header &header, Serializer<UInt_64> &data) const
{
if (!IsValid())
{
EHS_LOG_INT(LogType::WARN, 0, "Socket is not initialized.");
return 0;
}
Serializer<UInt_64> payload(Endianness::LE);
payload.Resize(1500);
sockaddr_in6 remote = {};
socklen_t from_len = sizeof(remote);
SInt_64 recv = recvfrom(hdl, (char *)&payload[0], 1500, 0, (sockaddr *)&remote, &from_len);
if (recv < 0)
{
int code = errno;
if (code == EAGAIN)
EHS_LOG_SUCCESS();
else
EHS_LOG_INT(LogType::ERR, 0, "Failed to receive packet with error #" + Str_8::FromNum(code) + ".");
return 0;
}
payload.Resize(recv);
char tmpAddr[INET6_ADDRSTRLEN];
if (!inet_ntop(remote.sin6_family, &remote.sin6_addr, tmpAddr, INET6_ADDRSTRLEN))
{
EHS_LOG_INT(LogType::ERR, 1, "Failed to convert IPv6 address with error #" + Str_8::FromNum(errno) + ".");
return recv;
}
address = tmpAddr;
header = payload.Read<ICMP_Header>();
data = Serializer<UInt_64>(payload.GetEndianness(), &payload[payload.GetOffset()], payload.Size() - payload.GetOffset());
EHS_LOG_SUCCESS();
return recv;
}
UInt_64 ICMP::ReceiveV4(Str_8 &address, ICMP_Header &header, Serializer<UInt_64> &data) const
{
if (!IsValid())
{
EHS_LOG_INT(LogType::WARN, 0, "Socket is not initialized.");
return 0;
}
Serializer<UInt_64> payload(Endianness::LE);
payload.Resize(1500);
sockaddr_in remote = {};
socklen_t from_len = sizeof(remote);
SInt_64 recv = recvfrom(hdl, (char *)&payload[0], 1500, 0, (sockaddr *)&remote, &from_len);
if (recv < 0)
{
int code = errno;
if (code == EAGAIN)
EHS_LOG_SUCCESS();
else
EHS_LOG_INT(LogType::ERR, 0, "Failed to receive packet with error #" + Str_8::FromNum(code) + ".");
return 0;
}
payload.Resize(recv);
char tmpAddr[INET_ADDRSTRLEN];
if (!inet_ntop(remote.sin_family, &remote.sin_addr, tmpAddr, INET_ADDRSTRLEN))
{
EHS_LOG_INT(LogType::ERR, 1, "Failed to convert IPv4 address with error #" + Str_8::FromNum(errno) + ".");
return recv;
}
address = tmpAddr;
iphdr ipHeader = payload.Read<iphdr>();
header = payload.Read<ICMP_Header>();
data = Serializer<UInt_64>(payload.GetEndianness(), &payload[payload.GetOffset()], payload.Size() - payload.GetOffset());
EHS_LOG_SUCCESS();
return recv;
}
}

View File

@@ -1,24 +0,0 @@
#include "ehs/system/AVX2.h"
namespace ehs
{
bool AVX2::CompareUnaligned(const UInt_64* a, const UInt_64* b)
{
return false;
}
bool AVX2::CompareUnaligned(const SInt_64* a, const SInt_64* b)
{
return false;
}
bool AVX2::CompareAligned(const UInt_64* a, const UInt_64* b)
{
return false;
}
bool AVX2::CompareAligned(const SInt_64* a, const SInt_64* b)
{
return false;
}
}

View File

@@ -1,49 +0,0 @@
global _ZN3ehs4AVX216CompareUnalignedEPKmS2_
global _ZN3ehs4AVX216CompareUnalignedEPKlS2_
global _ZN3ehs4AVX214CompareAlignedEPKmS2_
global _ZN3ehs4AVX214CompareAlignedEPKlS2_
section .text
_ZN3ehs4AVX216CompareUnalignedEPKmS2_:
VMOVDQU YMM0, [RDI]
VMOVDQU YMM1, [RSI]
VPCMPEQQ YMM2, YMM0, YMM1
VPMOVMSKB EAX, YMM2
CMP EAX, 0xFFFFFFFF
SETE AL
RET
_ZN3ehs4AVX216CompareUnalignedEPKlS2_:
VMOVDQU YMM0, [RDI]
VMOVDQU YMM1, [RSI]
VPCMPEQQ YMM2, YMM0, YMM1
VPMOVMSKB EAX, YMM2
CMP EAX, 0xFFFFFFFF
SETE AL
RET
_ZN3ehs4AVX214CompareAlignedEPKmS2_:
VMOVDQA YMM0, [RDI]
VMOVDQA YMM1, [RSI]
VPCMPEQQ YMM2, YMM0, YMM1
VPMOVMSKB EAX, YMM2
CMP EAX, 0xFFFFFFFF
SETE AL
RET
_ZN3ehs4AVX214CompareAlignedEPKlS2_:
VMOVDQA YMM0, [RDI]
VMOVDQA YMM1, [RSI]
VPCMPEQQ YMM2, YMM0, YMM1
VPMOVMSKB EAX, YMM2
CMP EAX, 0xFFFFFFFF
SETE AL
RET

View File

@@ -1,49 +0,0 @@
global ?CompareUnaligned@AVX2@ehs@@SA_NPEBK0@Z
global ?CompareUnaligned@AVX2@ehs@@SA_NPEBJ0@Z
global ?CompareAligned@AVX2@ehs@@SA_NPEBK0@Z
global ?CompareAligned@AVX2@ehs@@SA_NPEBJ0@Z
section .text
?CompareUnaligned@AVX2@ehs@@SA_NPEBK0@Z:
VMOVDQU YMM0, [RCX]
VMOVDQU YMM1, [RDX]
VPCMPEQQ YMM2, YMM0, YMM1
VPMOVMSKB EAX, YMM2
CMP EAX, 0xFFFFFFFF
SETE AL
RET
?CompareUnaligned@AVX2@ehs@@SA_NPEBJ0@Z:
VMOVDQU YMM0, [RCX]
VMOVDQU YMM1, [RDX]
VPCMPEQQ YMM2, YMM0, YMM1
VPMOVMSKB EAX, YMM2
CMP EAX, 0xFFFFFFFF
SETE AL
RET
?CompareAligned@AVX2@ehs@@SA_NPEBK0@Z:
VMOVDQA YMM0, [RCX]
VMOVDQA YMM1, [RDX]
VPCMPEQQ YMM2, YMM0, YMM1
VPMOVMSKB EAX, YMM2
CMP EAX, 0xFFFFFFFF
SETE AL
RET
?CompareAligned@AVX2@ehs@@SA_NPEBJ0@Z:
VMOVDQA YMM0, [RCX]
VMOVDQA YMM1, [RDX]
VPCMPEQQ YMM2, YMM0, YMM1
VPMOVMSKB EAX, YMM2
CMP EAX, 0xFFFFFFFF
SETE AL
RET

View File

@@ -1,24 +0,0 @@
#include "ehs/system/AVX512.h"
namespace ehs
{
bool AVX512::CompareUnaligned(const UInt_64* a, const UInt_64* b)
{
return false;
}
bool AVX512::CompareUnaligned(const SInt_64* a, const SInt_64* b)
{
return false;
}
bool AVX512::CompareAligned(const UInt_64* a, const UInt_64* b)
{
return false;
}
bool AVX512::CompareAligned(const SInt_64* a, const SInt_64* b)
{
return false;
}
}

View File

@@ -1,49 +0,0 @@
global _ZN3ehs6AVX51216CompareUnalignedEPKmS2_
global _ZN3ehs6AVX51216CompareUnalignedEPKlS2_
global _ZN3ehs6AVX51214CompareAlignedEPKmS2_
global _ZN3ehs6AVX51214CompareAlignedEPKlS2_
section .text
_ZN3ehs6AVX51216CompareUnalignedEPKmS2_:
VMOVDQU64 ZMM0, [RDI]
VMOVDQU64 ZMM1, [RSI]
VPCMPEQQ K1, ZMM0, ZMM1
KORTESTQ K1, K1
SETC AL
RET
_ZN3ehs6AVX51216CompareUnalignedEPKlS2_:
VMOVDQU64 ZMM0, [RDI]
VMOVDQU64 ZMM1, [RSI]
VPCMPEQQ K1, ZMM0, ZMM1
KORTESTQ K1, K1
SETC AL
RET
_ZN3ehs6AVX51214CompareAlignedEPKmS2_:
VMOVDQA64 ZMM0, [RDI]
VMOVDQA64 ZMM1, [RSI]
VPCMPEQQ K1, ZMM0, ZMM1
KORTESTQ K1, K1
SETC AL
RET
_ZN3ehs6AVX51214CompareAlignedEPKlS2_:
VMOVDQA64 ZMM0, [RDI]
VMOVDQA64 ZMM1, [RSI]
VPCMPEQQ K1, ZMM0, ZMM1
KORTESTQ K1, K1
SETC AL
RET

View File

@@ -1,49 +0,0 @@
global ?CompareUnaligned@AVX512@ehs@@SA_NPEBK0@Z
global ?CompareUnaligned@AVX512@ehs@@SA_NPEBJ0@Z
global ?CompareAligned@AVX512@ehs@@SA_NPEBK0@Z
global ?CompareAligned@AVX512@ehs@@SA_NPEBJ0@Z
section .text
?CompareUnaligned@AVX512@ehs@@SA_NPEBK0@Z:
VMOVDQU64 ZMM0, [RCX]
VMOVDQU64 ZMM1, [RDX]
VPCMPEQQ K1, ZMM0, ZMM1
KORTESTQ K1, K1
SETC AL
RET
?CompareUnaligned@AVX512@ehs@@SA_NPEBJ0@Z:
VMOVDQU64 ZMM0, [RCX]
VMOVDQU64 ZMM1, [RDX]
VPCMPEQQ K1, ZMM0, ZMM1
KORTESTQ K1, K1
SETC AL
RET
?CompareAligned@AVX512@ehs@@SA_NPEBK0@Z:
VMOVDQA64 ZMM0, [RCX]
VMOVDQA64 ZMM1, [RDX]
VPCMPEQQ K1, ZMM0, ZMM1
KORTESTQ K1, K1
SETC AL
RET
?CompareAligned@AVX512@ehs@@SA_NPEBJ0@Z:
VMOVDQA64 ZMM0, [RCX]
VMOVDQA64 ZMM1, [RDX]
VPCMPEQQ K1, ZMM0, ZMM1
KORTESTQ K1, K1
SETC AL
RET

View File

@@ -10,70 +10,6 @@ namespace ehs
UInt_64 CPU::TSC_Freq = 0; UInt_64 CPU::TSC_Freq = 0;
#endif #endif
const bool CPU::hasFPU = RetrieveFPU();
const bool CPU::hasVME = RetrieveVME();
const bool CPU::hasDE = RetrieveDE();
const bool CPU::hasPSE = RetrievePSE();
const bool CPU::hasTSC = RetrieveTSC();
const bool CPU::hasMSR = RetrieveMSR();
const bool CPU::hasPAE = RetrievePAE();
const bool CPU::hasMCE = RetrieveMCE();
const bool CPU::hasCX8 = RetrieveCX8();
const bool CPU::hasAPIC = RetrieveAPIC();
const bool CPU::hasSEP = RetrieveSEP();
const bool CPU::hasMTRR = RetrieveMTRR();
const bool CPU::hasPGE = RetrievePGE();
const bool CPU::hasMCA = RetrieveMCA();
const bool CPU::hasCMOV = RetrieveCMOV();
const bool CPU::hasPSE_36 = RetrievePSE_36();
const bool CPU::hasPSN = RetrievePSN();
const bool CPU::hasCLFSH = RetrieveCLFSH();
const bool CPU::hasDS = RetrieveDS();
const bool CPU::hasACPI = RetrieveACPI();
const bool CPU::hasMMX = RetrieveMMX();
const bool CPU::hasFXSR = RetrieveFXSR();
const bool CPU::hasSSE = RetrieveSSE();
const bool CPU::hasSSE2 = RetrieveSSE2();
const bool CPU::hasSS = RetrieveSS();
const bool CPU::hasHTT = RetrieveHTT();
const bool CPU::hasTM = RetrieveTM();
const bool CPU::hasIA64 = RetrieveIA64();
const bool CPU::hasPBE = RetrievePBE();
const bool CPU::hasSSE3 = RetrieveSSE3();
const bool CPU::hasPCLMULQDQ = RetrievePCLMULQDQ();
const bool CPU::hasDTES64 = RetrieveDTES64();
const bool CPU::hasMONITOR = RetrieveMONITOR();
const bool CPU::hasVMX = RetrieveVMX();
const bool CPU::hasSMX = RetrieveSMX();
const bool CPU::hasEST = RetrieveEST();
const bool CPU::hasTM2 = RetrieveTM2();
const bool CPU::hasSSSE3 = RetrieveSSSE3();
const bool CPU::hasCNXT_ID = RetrieveCNXT_ID();
const bool CPU::hasSDBG = RetrieveSDBG();
const bool CPU::hasFMA = RetrieveFMA();
const bool CPU::hasCX16 = RetrieveCX16();
const bool CPU::hasXTPR = RetrieveXTPR();
const bool CPU::hasPDCM = RetrievePDCM();
const bool CPU::hasPCID = RetrievePCID();
const bool CPU::hasDCA = RetrieveDCA();
const bool CPU::hasSSE4_1 = RetrieveSSE4_1();
const bool CPU::hasSSE4_2 = RetrieveSSE4_2();
const bool CPU::hasX2APIC = RetrieveX2APIC();
const bool CPU::hasMOVBE = RetrieveMOVBE();
const bool CPU::hasPOPCNT = RetrievePOPCNT();
const bool CPU::hasTSC_DEADLINE = RetrieveTSC_DEADLINE();
const bool CPU::hasAES = RetrieveAES();
const bool CPU::hasXSAVE = RetrieveXSAVE();
const bool CPU::hasOSXSAVE = RetrieveOSXSAVE();
const bool CPU::hasAVX = RetrieveAVX();
const bool CPU::hasF16C = RetrieveF16C();
const bool CPU::hasRDRND = RetrieveRDRND();
const bool CPU::hasHYPERVISOR = RetrieveHYPERVISOR();
const bool CPU::hasAVX2 = RetrieveAVX2();
const bool CPU::hasAVX512F = RetrieveAVX512F();
const bool CPU::hasRDSEED = RetrieveRDSEED();
const bool CPU::hasADX = RetrieveADX();
Architecture CPU::GetArchitecture() Architecture CPU::GetArchitecture()
{ {
#if defined(EHS_ARCH_X64) #if defined(EHS_ARCH_X64)
@@ -183,589 +119,324 @@ namespace ehs
return (UInt_8)(GetInfoBits() >> 20); return (UInt_8)(GetInfoBits() >> 20);
} }
bool CPU::RetrieveFPU() bool CPU::HasFPU()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_1() & 0b00000000000000000000000000000001; return GetFeatureBits_1() & 0b00000000000000000000000000000001;
#else
return false;
#endif
} }
bool CPU::RetrieveVME() bool CPU::HasVME()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_1() & 0b00000000000000000000000000000010; return GetFeatureBits_1() & 0b00000000000000000000000000000010;
#else
return false;
#endif
} }
bool CPU::RetrieveDE() bool CPU::HasDE()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_1() & 0b00000000000000000000000000000100; return GetFeatureBits_1() & 0b00000000000000000000000000000100;
#else
return false;
#endif
} }
bool CPU::RetrievePSE() bool CPU::HasPSE()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_1() & 0b00000000000000000000000000001000; return GetFeatureBits_1() & 0b00000000000000000000000000001000;
#else
return false;
#endif
} }
bool CPU::RetrieveTSC() bool CPU::HasTSC()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_1() & 0b00000000000000000000000000010000; return GetFeatureBits_1() & 0b00000000000000000000000000010000;
#else
return false;
#endif
} }
bool CPU::RetrieveMSR() bool CPU::HasMSR()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_1() & 0b00000000000000000000000000100000; return GetFeatureBits_1() & 0b00000000000000000000000000100000;
#else
return false;
#endif
} }
bool CPU::RetrievePAE() bool CPU::HasPAE()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_1() & 0b00000000000000000000000001000000; return GetFeatureBits_1() & 0b00000000000000000000000001000000;
#else
return false;
#endif
} }
bool CPU::RetrieveMCE() bool CPU::HasMCE()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_1() & 0b00000000000000000000000010000000; return GetFeatureBits_1() & 0b00000000000000000000000010000000;
#else
return false;
#endif
} }
bool CPU::RetrieveCX8() bool CPU::HasCX8()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_1() & 0b00000000000000000000000100000000; return GetFeatureBits_1() & 0b00000000000000000000000100000000;
#else
return false;
#endif
} }
bool CPU::RetrieveAPIC() bool CPU::HasAPIC()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_1() & 0b00000000000000000000001000000000; return GetFeatureBits_1() & 0b00000000000000000000001000000000;
#else
return false;
#endif
} }
bool CPU::RetrieveSEP() bool CPU::HasSEP()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_1() & 0b00000000000000000000100000000000; return GetFeatureBits_1() & 0b00000000000000000000100000000000;
#else
return false;
#endif
} }
bool CPU::RetrieveMTRR() bool CPU::HasMTRR()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_1() & 0b00000000000000000001000000000000; return GetFeatureBits_1() & 0b00000000000000000001000000000000;
#else
return false;
#endif
} }
bool CPU::RetrievePGE() bool CPU::HasPGE()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_1() & 0b00000000000000000010000000000000; return GetFeatureBits_1() & 0b00000000000000000010000000000000;
#else
return false;
#endif
} }
bool CPU::RetrieveMCA() bool CPU::HasMCA()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_1() & 0b00000000000000000100000000000000; return GetFeatureBits_1() & 0b00000000000000000100000000000000;
#else
return false;
#endif
} }
bool CPU::RetrieveCMOV() bool CPU::HasCMOV()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_1() & 0b00000000000000001000000000000000; return GetFeatureBits_1() & 0b00000000000000001000000000000000;
#else
return false;
#endif
} }
bool CPU::RetrievePAT() bool CPU::HasPAT()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_1() & 0b00000000000000010000000000000000; return GetFeatureBits_1() & 0b00000000000000010000000000000000;
#else
return false;
#endif
} }
bool CPU::RetrievePSE_36() bool CPU::HasPSE_36()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_1() & 0b00000000000000100000000000000000; return GetFeatureBits_1() & 0b00000000000000100000000000000000;
#else
return false;
#endif
} }
bool CPU::RetrievePSN() bool CPU::HasPSN()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_1() & 0b00000000000001000000000000000000; return GetFeatureBits_1() & 0b00000000000001000000000000000000;
#else
return false;
#endif
} }
bool CPU::RetrieveCLFSH() bool CPU::HasCLFSH()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_1() & 0b00000000000010000000000000000000; return GetFeatureBits_1() & 0b00000000000010000000000000000000;
#else
return false;
#endif
} }
bool CPU::RetrieveDS() bool CPU::HasDS()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_1() & 0b00000000001000000000000000000000; return GetFeatureBits_1() & 0b00000000001000000000000000000000;
#else
return false;
#endif
} }
bool CPU::RetrieveACPI() bool CPU::HasACPI()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_1() & 0b00000000010000000000000000000000; return GetFeatureBits_1() & 0b00000000010000000000000000000000;
#else
return false;
#endif
} }
bool CPU::RetrieveMMX() bool CPU::HasMMX()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_1() & 0b00000000100000000000000000000000; return GetFeatureBits_1() & 0b00000000100000000000000000000000;
#else
return false;
#endif
} }
bool CPU::RetrieveFXSR() bool CPU::HasFXSR()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_1() & 0b00000001000000000000000000000000; return GetFeatureBits_1() & 0b00000001000000000000000000000000;
#else
return false;
#endif
} }
bool CPU::RetrieveSSE() bool CPU::HasSSE()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_1() & 0b00000010000000000000000000000000; return GetFeatureBits_1() & 0b00000010000000000000000000000000;
#else
return false;
#endif
} }
bool CPU::RetrieveSSE2() bool CPU::HasSSE2()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_1() & 0b00000100000000000000000000000000; return GetFeatureBits_1() & 0b00000100000000000000000000000000;
#else
return false;
#endif
} }
bool CPU::RetrieveSS() bool CPU::HasSS()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_1() & 0b00001000000000000000000000000000; return GetFeatureBits_1() & 0b00001000000000000000000000000000;
#else
return false;
#endif
} }
bool CPU::RetrieveHTT() bool CPU::HasHTT()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_1() & 0b00010000000000000000000000000000; return GetFeatureBits_1() & 0b00010000000000000000000000000000;
#else
return false;
#endif
} }
bool CPU::RetrieveTM() bool CPU::HasTM()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_1() & 0b00100000000000000000000000000000; return GetFeatureBits_1() & 0b00100000000000000000000000000000;
#else
return false;
#endif
} }
bool CPU::RetrieveIA64() bool CPU::HasIA64()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_1() & 0b01000000000000000000000000000000; return GetFeatureBits_1() & 0b01000000000000000000000000000000;
#else
return false;
#endif
} }
bool CPU::RetrievePBE() bool CPU::HasPBE()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_1() & 0b10000000000000000000000000000000; return GetFeatureBits_1() & 0b10000000000000000000000000000000;
#else
return false;
#endif
} }
bool CPU::RetrieveSSE3() bool CPU::HasSSE3()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_2() & 0b00000000000000000000000000000001; return GetFeatureBits_2() & 0b00000000000000000000000000000001;
#else
return false;
#endif
} }
bool CPU::RetrievePCLMULQDQ() bool CPU::HasPCLMULQDQ()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_2() & 0b00000000000000000000000000000010; return GetFeatureBits_2() & 0b00000000000000000000000000000010;
#else
return false;
#endif
} }
bool CPU::RetrieveDTES64() bool CPU::HasDTES64()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_2() & 0b00000000000000000000000000000100; return GetFeatureBits_2() & 0b00000000000000000000000000000100;
#else
return false;
#endif
} }
bool CPU::RetrieveMONITOR() bool CPU::HasMONITOR()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_2() & 0b00000000000000000000000000001000; return GetFeatureBits_2() & 0b00000000000000000000000000001000;
#else
return false;
#endif
} }
bool CPU::RetrieveDS_CPL() bool CPU::HasDS_CPL()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_2() & 0b00000000000000000000000000010000; return GetFeatureBits_2() & 0b00000000000000000000000000010000;
#else
return false;
#endif
} }
bool CPU::RetrieveVMX() bool CPU::HasVMX()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_2() & 0b00000000000000000000000000100000; return GetFeatureBits_2() & 0b00000000000000000000000000100000;
#else
return false;
#endif
} }
bool CPU::RetrieveSMX() bool CPU::HasSMX()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_2() & 0b00000000000000000000000001000000; return GetFeatureBits_2() & 0b00000000000000000000000001000000;
#else
return false;
#endif
} }
bool CPU::RetrieveEST() bool CPU::HasEST()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_2() & 0b00000000000000000000000010000000; return GetFeatureBits_2() & 0b00000000000000000000000010000000;
#else
return false;
#endif
} }
bool CPU::RetrieveTM2() bool CPU::HasTM2()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_2() & 0b00000000000000000000000100000000; return GetFeatureBits_2() & 0b00000000000000000000000100000000;
#else
return false;
#endif
} }
bool CPU::RetrieveSSSE3() bool CPU::HasSSSE3()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_2() & 0b00000000000000000000001000000000; return GetFeatureBits_2() & 0b00000000000000000000001000000000;
#else
return false;
#endif
} }
bool CPU::RetrieveCNXT_ID() bool CPU::HasCNXT_ID()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_2() & 0b00000000000000000000010000000000; return GetFeatureBits_2() & 0b00000000000000000000010000000000;
#else
return false;
#endif
} }
bool CPU::RetrieveSDBG() bool CPU::HasSDBG()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_2() & 0b00000000000000000000100000000000; return GetFeatureBits_2() & 0b00000000000000000000100000000000;
#else
return false;
#endif
} }
bool CPU::RetrieveFMA() bool CPU::HasFMA()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_2() & 0b00000000000000000001000000000000; return GetFeatureBits_2() & 0b00000000000000000001000000000000;
#else
return false;
#endif
} }
bool CPU::RetrieveCX16() bool CPU::HasCX16()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_2() & 0b00000000000000000010000000000000; return GetFeatureBits_2() & 0b00000000000000000010000000000000;
#else
return false;
#endif
} }
bool CPU::RetrieveXTPR() bool CPU::HasXTPR()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_2() & 0b00000000000000000100000000000000; return GetFeatureBits_2() & 0b00000000000000000100000000000000;
#else
return false;
#endif
} }
bool CPU::RetrievePDCM() bool CPU::HasPDCM()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_2() & 0b00000000000000001000000000000000; return GetFeatureBits_2() & 0b00000000000000001000000000000000;
#else
return false;
#endif
} }
bool CPU::RetrievePCID() bool CPU::HasPCID()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_2() & 0b00000000000000100000000000000000; return GetFeatureBits_2() & 0b00000000000000100000000000000000;
#else
return false;
#endif
} }
bool CPU::RetrieveDCA() bool CPU::HasDCA()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_2() & 0b00000000000001000000000000000000; return GetFeatureBits_2() & 0b00000000000001000000000000000000;
#else
return false;
#endif
} }
bool CPU::RetrieveSSE4_1() bool CPU::HasSSE4_1()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_2() & 0b00000000000010000000000000000000; return GetFeatureBits_2() & 0b00000000000010000000000000000000;
#else
return false;
#endif
} }
bool CPU::RetrieveSSE4_2() bool CPU::HasSSE4_2()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_2() & 0b00000000000100000000000000000000; return GetFeatureBits_2() & 0b00000000000100000000000000000000;
#else
return false;
#endif
} }
bool CPU::RetrieveX2APIC() bool CPU::HasX2APIC()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_2() & 0b00000000001000000000000000000000; return GetFeatureBits_2() & 0b00000000001000000000000000000000;
#else
return false;
#endif
} }
bool CPU::RetrieveMOVBE() bool CPU::HasMOVBE()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_2() & 0b00000000010000000000000000000000; return GetFeatureBits_2() & 0b00000000010000000000000000000000;
#else
return false;
#endif
} }
bool CPU::RetrievePOPCNT() bool CPU::HasPOPCNT()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_2() & 0b00000000100000000000000000000000; return GetFeatureBits_2() & 0b00000000100000000000000000000000;
#else
return false;
#endif
} }
bool CPU::RetrieveTSC_DEADLINE() bool CPU::HasTSC_DEADLINE()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_2() & 0b00000001000000000000000000000000; return GetFeatureBits_2() & 0b00000001000000000000000000000000;
#else
return false;
#endif
} }
bool CPU::RetrieveAES() bool CPU::HasAES()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_2() & 0b00000010000000000000000000000000; return GetFeatureBits_2() & 0b00000010000000000000000000000000;
#else
return false;
#endif
} }
bool CPU::RetrieveXSAVE() bool CPU::HasXSAVE()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_2() & 0b00000100000000000000000000000000; return GetFeatureBits_2() & 0b00000100000000000000000000000000;
#else
return false;
#endif
} }
bool CPU::RetrieveOSXSAVE() bool CPU::HasOSXSAVE()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_2() & 0b00001000000000000000000000000000; return GetFeatureBits_2() & 0b00001000000000000000000000000000;
#else
return false;
#endif
} }
bool CPU::RetrieveAVX() bool CPU::HasAVX()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_2() & 0b00010000000000000000000000000000; return GetFeatureBits_2() & 0b00010000000000000000000000000000;
#else
return false;
#endif
} }
bool CPU::RetrieveF16C() bool CPU::HasF16C()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_2() & 0b00100000000000000000000000000000; return GetFeatureBits_2() & 0b00100000000000000000000000000000;
#else
return false;
#endif
} }
bool CPU::RetrieveRDRND() bool CPU::HasRDRND()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_2() & 0b01000000000000000000000000000000; return GetFeatureBits_2() & 0b01000000000000000000000000000000;
#else
return false;
#endif
} }
bool CPU::RetrieveHYPERVISOR() bool CPU::HasHYPERVISOR()
{ {
#ifdef EHS_ARCH_X64
return GetFeatureBits_2() & 0b10000000000000000000000000000000; return GetFeatureBits_2() & 0b10000000000000000000000000000000;
#else
return false;
#endif
} }
bool CPU::RetrieveAVX2() bool CPU::HasAVX2()
{ {
#ifdef EHS_ARCH_X64
return GetExtFeatureBits_1() & 0b00000000000000000000000000100000; return GetExtFeatureBits_1() & 0b00000000000000000000000000100000;
#else
return false;
#endif
} }
bool CPU::RetrieveAVX512F() bool CPU::HasRDSEED()
{ {
#ifdef EHS_ARCH_X64
return GetExtFeatureBits_1() & 0b00000000000000010000000000000000;
#else
return false;
#endif
}
bool CPU::RetrieveRDSEED()
{
#ifdef EHS_ARCH_X64
return GetExtFeatureBits_1() & 0b00000000000001000000000000000000; return GetExtFeatureBits_1() & 0b00000000000001000000000000000000;
#else
return false;
#endif
} }
bool CPU::RetrieveADX() bool CPU::HasADX()
{ {
#ifdef EHS_ARCH_X64
return GetExtFeatureBits_1() & 0b00000000000010000000000000000000; return GetExtFeatureBits_1() & 0b00000000000010000000000000000000;
#else
return false;
#endif
} }
/* /*

View File

@@ -43,9 +43,4 @@ namespace ehs
void CPU::GetBrand(Char_8* input) void CPU::GetBrand(Char_8* input)
{ {
} }
UInt_8 CPU::GetCacheLineSize()
{
return 0;
}
} }