From e448ccf2753f339e87ad349f59fe917da4e17de7 Mon Sep 17 00:00:00 2001 From: Hyper <34012267+hyperbx@users.noreply.github.com> Date: Tue, 4 Mar 2025 06:46:14 +0000 Subject: [PATCH] Added check for AVX on boot Co-Authored-By: Wiseguy <68165316+mr-wiseguy@users.noreply.github.com> --- UnleashedRecomp/CMakeLists.txt | 2 +- UnleashedRecomp/main.cpp | 26 +++++++++++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/UnleashedRecomp/CMakeLists.txt b/UnleashedRecomp/CMakeLists.txt index ce05eb10..66b60a44 100644 --- a/UnleashedRecomp/CMakeLists.txt +++ b/UnleashedRecomp/CMakeLists.txt @@ -352,7 +352,7 @@ if (WIN32) Synchronization winmm ) -endif() +endif() target_link_libraries(UnleashedRecomp PRIVATE fmt::fmt diff --git a/UnleashedRecomp/main.cpp b/UnleashedRecomp/main.cpp index d3d12381..9158abf3 100644 --- a/UnleashedRecomp/main.cpp +++ b/UnleashedRecomp/main.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -147,6 +148,29 @@ uint32_t LdrLoadModule(const std::filesystem::path &path) return entry; } +__attribute__((constructor(101), target("no-avx,no-avx2"), noinline)) +void init() +{ +#ifdef __x86_64__ + uint32_t eax, ebx, ecx, edx; + + // Execute CPUID for processor info and feature bits. + __get_cpuid(1, &eax, &ebx, &ecx, &edx); + + // Check for AVX support. + if ((ecx & (1 << 28)) == 0) + { + printf("[*] CPU does not support the AVX instruction set.\n"); + +#ifdef _WIN32 + MessageBoxA(nullptr, "Your CPU does not meet the minimum system requirements.", "Unleashed Recompiled", MB_ICONERROR); +#endif + + std::_Exit(1); + } +#endif +} + int main(int argc, char *argv[]) { #ifdef _WIN32 @@ -156,7 +180,7 @@ int main(int argc, char *argv[]) os::process::CheckConsole(); if (!os::registry::Init()) - LOGN_WARNING("OS doesn't support registry"); + LOGN_WARNING("OS does not support registry."); os::logger::Init();