Files
FEX-Emu--FEX/Source/Tests/LinuxSyscalls/Syscalls/Sched.cpp
T
Ryan Houdek 37983006f0 Moves FEXCore's SignalDelegator and SyscallHandler to the frontend
Sadly these things can't be split without breaking functionality so it
turns in to a bit of a mess.

SyscallHandler is very much something that is a Linux only construct and
shouldn't be in FEXCore itself. Lets the frontend register a
Syscallhandler with FEXCore. FEXCore itself is then aware of the current
syscall ABI and handles the ABI in an optimal fashion.
So it is not a 100% clean break otherwise we would lose performance.

The SignalDelegator then needs to move to the frontend since the
SyscallHandler requires it for signal based syscalls.
The CPU backend signal handling still needs to happen in FEXCore because
it is a very tight coupling with the CPU backend.
Once we need to support more Signal handling we can give the backends
cleaner support to select which specific OS handler to handle.
2020-12-13 22:38:04 -08:00

94 lines
3.6 KiB
C++

#include "Tests/LinuxSyscalls/Syscalls.h"
#include "Tests/LinuxSyscalls/x64/Syscalls.h"
#include "Tests/LinuxSyscalls/x32/Syscalls.h"
#include <stdint.h>
#include <sched.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/syscall.h>
#include <unistd.h>
namespace FEX::HLE {
void RegisterSched() {
REGISTER_SYSCALL_IMPL(sched_yield, [](FEXCore::Core::InternalThreadState *Thread) -> uint64_t {
uint64_t Result = ::sched_yield();
SYSCALL_ERRNO();
});
REGISTER_SYSCALL_IMPL(getpriority, [](FEXCore::Core::InternalThreadState *Thread, int which, int who) -> uint64_t {
uint64_t Result = ::syscall(SYS_getpriority, which, who);
SYSCALL_ERRNO();
});
REGISTER_SYSCALL_IMPL(setpriority, [](FEXCore::Core::InternalThreadState *Thread, int which, int who, int prio) -> uint64_t {
uint64_t Result = ::setpriority(which, who, prio);
SYSCALL_ERRNO();
});
REGISTER_SYSCALL_IMPL(sched_setparam, [](FEXCore::Core::InternalThreadState *Thread, pid_t pid, const struct sched_param *param) -> uint64_t {
uint64_t Result = ::sched_setparam(pid, param);
SYSCALL_ERRNO();
});
REGISTER_SYSCALL_IMPL(sched_getparam, [](FEXCore::Core::InternalThreadState *Thread, pid_t pid, struct sched_param *param) -> uint64_t {
uint64_t Result = ::sched_getparam(pid, param);
SYSCALL_ERRNO();
});
REGISTER_SYSCALL_IMPL(sched_setscheduler, [](FEXCore::Core::InternalThreadState *Thread, pid_t pid, int policy, const struct sched_param *param) -> uint64_t {
uint64_t Result = ::sched_setscheduler(pid, policy, param);
SYSCALL_ERRNO();
});
REGISTER_SYSCALL_IMPL(sched_getscheduler, [](FEXCore::Core::InternalThreadState *Thread, pid_t pid) -> uint64_t {
uint64_t Result = ::sched_getscheduler(pid);
SYSCALL_ERRNO();
});
REGISTER_SYSCALL_IMPL(sched_get_priority_max, [](FEXCore::Core::InternalThreadState *Thread, int policy) -> uint64_t {
uint64_t Result = ::sched_get_priority_max(policy);
SYSCALL_ERRNO();
});
REGISTER_SYSCALL_IMPL(sched_get_priority_min, [](FEXCore::Core::InternalThreadState *Thread, int policy) -> uint64_t {
uint64_t Result = ::sched_get_priority_min(policy);
SYSCALL_ERRNO();
});
REGISTER_SYSCALL_IMPL(sched_setaffinity, [](FEXCore::Core::InternalThreadState *Thread, pid_t pid, size_t cpusetsize, const unsigned long *mask) -> uint64_t {
return 0;
});
REGISTER_SYSCALL_IMPL(sched_getaffinity, [](FEXCore::Core::InternalThreadState *Thread, pid_t pid, size_t cpusetsize, unsigned char *mask) -> uint64_t {
uint64_t Cores = FEX::HLE::_SyscallHandler->ThreadsConfig();
uint64_t Bytes = ((Cores+7) / 8);
// If we don't have at least one byte in the resulting structure
// then we need to return -EINVAL
if (cpusetsize < Bytes) {
return -EINVAL;
}
memset(mask, 0, Bytes);
for (uint64_t i = 0; i < Cores; ++i) {
mask[i / 8] |= (1 << (i % 8));
}
// Returns the number of bytes written in to mask
return Bytes;
});
REGISTER_SYSCALL_IMPL(sched_setattr, [](FEXCore::Core::InternalThreadState *Thread, pid_t pid, struct sched_attr *attr, unsigned int flags) -> uint64_t {
uint64_t Result = ::syscall(SYS_sched_setattr, pid, attr, flags);
SYSCALL_ERRNO();
});
REGISTER_SYSCALL_IMPL(sched_getattr, [](FEXCore::Core::InternalThreadState *Thread, pid_t pid, struct sched_attr *attr, unsigned int size, unsigned int flags) -> uint64_t {
uint64_t Result = ::syscall(SYS_sched_getattr, pid, attr, size, flags);
SYSCALL_ERRNO();
});
}
}