mirror of
https://github.com/FEX-Emu/FEX.git
synced 2026-10-07 06:00:16 +02:00
Reimagining of #3355 without any json generators or new concepts. Fixes some mislabeling of system calls. Some getting inlined when they shouldn't be, a lot not getting inlined when they can be. This really cleans up the syscall implementation, all syscalls that can be passthrough implementations require a very small two line declaration. Additionally cleans up a bit of implementation cruft where some passthrough syscalls were using the glibc syscall handler, and some were using the glibc implementation. We have had multiple issues in the past where the glibc implementation does something subtly different than the raw syscall and breaks things. Now all passthrough handlers do a system call directly, removing at least one indirection and some ambiguity. This makes it significantly easier to add new passthrough syscalls as well. Only need to do a version check and add the three lines per syscall. Which there are new syscalls incoming that we will want to add. Tangible improvements: - Syscalls are lower overhead than ever. - When I'm adding more syscalls I have less chance of mucking it up.
93 lines
3.0 KiB
C++
93 lines
3.0 KiB
C++
// SPDX-License-Identifier: MIT
|
|
/*
|
|
$info$
|
|
tags: LinuxSyscalls|syscalls-x86-32
|
|
$end_info$
|
|
*/
|
|
|
|
#include "LinuxSyscalls/Syscalls.h"
|
|
#include "LinuxSyscalls/x32/Syscalls.h"
|
|
#include "LinuxSyscalls/x32/Types.h"
|
|
|
|
#include "LinuxSyscalls/x64/Syscalls.h"
|
|
|
|
#include <stdint.h>
|
|
#include <syscall.h>
|
|
#include <time.h>
|
|
#include <unistd.h>
|
|
|
|
ARG_TO_STR(FEX::HLE::x32::compat_ptr<FEX::HLE::x32::mq_attr32>, "%lx")
|
|
ARG_TO_STR(FEX::HLE::x32::compat_ptr<FEX::HLE::x32::sigevent32>, "%lx")
|
|
|
|
namespace FEX::HLE::x32 {
|
|
void RegisterMsg(FEX::HLE::SyscallHandler *Handler) {
|
|
REGISTER_SYSCALL_IMPL_X32(mq_timedsend, [](FEXCore::Core::CpuStateFrame *Frame, FEX::HLE::mqd_t mqdes, const char *msg_ptr, size_t msg_len, unsigned int msg_prio, const struct timespec32 *abs_timeout) -> uint64_t {
|
|
struct timespec tp64{};
|
|
struct timespec *timed_ptr{};
|
|
if (abs_timeout) {
|
|
tp64 = *abs_timeout;
|
|
timed_ptr = &tp64;
|
|
}
|
|
|
|
uint64_t Result = ::syscall(SYSCALL_DEF(mq_timedsend), mqdes, msg_ptr, msg_len, msg_prio, timed_ptr);
|
|
SYSCALL_ERRNO();
|
|
});
|
|
|
|
REGISTER_SYSCALL_IMPL_X32(mq_timedreceive, [](FEXCore::Core::CpuStateFrame *Frame, FEX::HLE::mqd_t mqdes, char *msg_ptr, size_t msg_len, unsigned int *msg_prio, const struct timespec32 *abs_timeout) -> uint64_t {
|
|
struct timespec tp64{};
|
|
struct timespec *timed_ptr{};
|
|
if (abs_timeout) {
|
|
tp64 = *abs_timeout;
|
|
timed_ptr = &tp64;
|
|
}
|
|
|
|
uint64_t Result = ::syscall(SYSCALL_DEF(mq_timedreceive), mqdes, msg_ptr, msg_len, msg_prio, timed_ptr);
|
|
SYSCALL_ERRNO();
|
|
});
|
|
|
|
REGISTER_SYSCALL_IMPL_X32(mq_open, [](FEXCore::Core::CpuStateFrame *Frame, const char *name, int oflag, mode_t mode, compat_ptr<FEX::HLE::x32::mq_attr32> attr) -> uint64_t {
|
|
mq_attr HostAttr{};
|
|
mq_attr *HostAttr_p{};
|
|
if ((oflag & O_CREAT) && attr) {
|
|
// attr is optional unless O_CREAT is set
|
|
// Then attr can be valid or nullptr
|
|
HostAttr = *attr;
|
|
HostAttr_p = &HostAttr;
|
|
}
|
|
uint64_t Result = ::syscall(SYSCALL_DEF(mq_open), name, oflag, mode, HostAttr_p);
|
|
SYSCALL_ERRNO();
|
|
});
|
|
|
|
REGISTER_SYSCALL_IMPL_X32(mq_notify, [](FEXCore::Core::CpuStateFrame *Frame, FEX::HLE::mqd_t mqdes, const compat_ptr<FEX::HLE::x32::sigevent32> sevp) -> uint64_t {
|
|
sigevent Host = *sevp;
|
|
uint64_t Result = ::syscall(SYSCALL_DEF(mq_notify), mqdes, &Host);
|
|
SYSCALL_ERRNO();
|
|
});
|
|
|
|
REGISTER_SYSCALL_IMPL_X32(mq_getsetattr, [](FEXCore::Core::CpuStateFrame *Frame, FEX::HLE::mqd_t mqdes, compat_ptr<FEX::HLE::x32::mq_attr32> newattr, compat_ptr<FEX::HLE::x32::mq_attr32> oldattr) -> uint64_t {
|
|
mq_attr HostNew{};
|
|
mq_attr *HostNew_p{};
|
|
|
|
mq_attr HostOld{};
|
|
mq_attr *HostOld_p{};
|
|
|
|
if (newattr) {
|
|
HostNew = *newattr;
|
|
HostNew_p = &HostNew;
|
|
}
|
|
|
|
if (oldattr) {
|
|
HostOld_p = &HostOld;
|
|
}
|
|
|
|
uint64_t Result = ::syscall(SYSCALL_DEF(mq_getsetattr), mqdes, HostNew_p, HostOld_p);
|
|
|
|
if (Result != 1 && oldattr) {
|
|
*oldattr = HostOld;
|
|
}
|
|
|
|
SYSCALL_ERRNO();
|
|
});
|
|
}
|
|
}
|