mirror of
https://github.com/FEX-Emu/FEX.git
synced 2026-10-07 12:00:17 +02:00
Including fallback to non-unixlib path because we need to support both. Showcases how these are going to be implemented without throwing the entire world at it right away. Next PR will be implementing the remaining four necessary unixlib handlers that we will require: - Kernel unaligned atomic control - shm_stats thing - madvise operation - prctl vma naming
52 lines
1.6 KiB
C++
52 lines
1.6 KiB
C++
// SPDX-License-Identifier: MIT
|
|
#include <cstdint>
|
|
#include <type_traits>
|
|
#include <sys/prctl.h>
|
|
|
|
#include "FEXUnixLib.h"
|
|
|
|
// Equivalent to C++23's std::to_underlying.
|
|
template<typename Enum>
|
|
[[nodiscard]]
|
|
constexpr std::underlying_type_t<Enum> ToUnderlying(Enum e) noexcept {
|
|
return static_cast<std::underlying_type_t<Enum>>(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<const FEXUnixLib_SetHardwareTSOControlArgs*>(_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));
|