// SPDX-License-Identifier: MIT #include #include #include #include "FEXUnixLib.h" // Equivalent to C++23's std::to_underlying. template [[nodiscard]] constexpr std::underlying_type_t ToUnderlying(Enum e) noexcept { return static_cast>(e); } using NTSTATUS = int32_t; using unixlib_entry_t = NTSTATUS (*)(void*); constexpr NTSTATUS STATUS_SUCCESS = 0; constexpr NTSTATUS STATUS_NOT_SUPPORTED = 0xC00000BB; constexpr NTSTATUS STATUS_INTERNAL_ERROR = 0xC00000E5; #ifndef PR_GET_MEM_MODEL #define PR_GET_MEM_MODEL 0x6d4d444c #endif #ifndef PR_SET_MEM_MODEL #define PR_SET_MEM_MODEL 0x4d4d444c #endif #ifndef PR_SET_MEM_MODEL_DEFAULT #define PR_SET_MEM_MODEL_DEFAULT 0 #endif #ifndef PR_SET_MEM_MODEL_TSO #define PR_SET_MEM_MODEL_TSO 1 #endif static NTSTATUS FEXUnixLib_SetHardwareTSOControlHandler(void* _Args) { auto Args = reinterpret_cast(_Args); if (Args->Enable) { int ret = prctl(PR_GET_MEM_MODEL, 0, 0, 0, 0); if (ret == PR_SET_MEM_MODEL_DEFAULT) { return prctl(PR_SET_MEM_MODEL, PR_SET_MEM_MODEL_TSO, 0, 0, 0) ? STATUS_NOT_SUPPORTED : STATUS_SUCCESS; } return ret == PR_SET_MEM_MODEL_TSO ? STATUS_SUCCESS : STATUS_NOT_SUPPORTED; } prctl(PR_SET_MEM_MODEL, PR_SET_MEM_MODEL_DEFAULT, 0, 0, 0); return STATUS_SUCCESS; } extern "C" const unixlib_entry_t __wine_unix_call_funcs[] = {FEXUnixLib_SetHardwareTSOControlHandler}; static_assert(sizeof(__wine_unix_call_funcs) / sizeof(__wine_unix_call_funcs[0]) == ToUnderlying(FEXUnixLibFunctions::MAX));