Skip to content

Commit

Permalink
Merge pull request #3944 from Sonicadvance1/minor_syscall_changes
Browse files Browse the repository at this point in the history
LinuxSyscalls: Some minor cleanups
  • Loading branch information
Sonicadvance1 authored Aug 15, 2024
2 parents 86e5e1a + 924723d commit 27cd399
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 60 deletions.
7 changes: 6 additions & 1 deletion Source/Tools/LinuxEmulation/LinuxSyscalls/Syscalls.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ desc: Glue logic, STRACE magic
#endif

#include "LinuxSyscalls/x64/SyscallsEnum.h"
#include "LinuxSyscalls/x32/SyscallsEnum.h"

#define CONCAT_(a, b) a##b
#define CONCAT(a, b) CONCAT_(a, b)
Expand Down Expand Up @@ -255,7 +256,11 @@ class SyscallHandler : public FEXCore::HLE::SyscallHandler, FEXCore::HLE::Source
protected:
SyscallHandler(FEXCore::Context::Context* _CTX, FEX::HLE::SignalDelegator* _SignalDelegation);

fextl::vector<SyscallFunctionDefinition> Definitions {};
fextl::vector<SyscallFunctionDefinition> Definitions {std::max<std::size_t>(FEX::HLE::x64::SYSCALL_x64_MAX, FEX::HLE::x32::SYSCALL_x86_MAX),
{
.NumArgs = 255,
.Ptr = reinterpret_cast<void*>(&UnimplementedSyscall),
}};
std::mutex MMapMutex;

// BRK management
Expand Down
16 changes: 1 addition & 15 deletions Source/Tools/LinuxEmulation/LinuxSyscalls/x32/Syscalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,6 @@ x32SyscallHandler::x32SyscallHandler(FEXCore::Context::Context* ctx, FEX::HLE::S
}

void x32SyscallHandler::RegisterSyscallHandlers() {
auto cvt = [](auto in) {
union {
decltype(in) val;
void* raw;
} raw;
raw.val = in;
return raw.raw;
};

Definitions.resize(FEX::HLE::x32::SYSCALL_x86_MAX, SyscallFunctionDefinition {
.NumArgs = 255,
.Ptr = cvt(&UnimplementedSyscall),
});

FEX::HLE::RegisterEpoll(this);
FEX::HLE::RegisterFD(this);
FEX::HLE::RegisterFS(this);
Expand Down Expand Up @@ -98,7 +84,7 @@ void x32SyscallHandler::RegisterSyscallHandlers() {

#if PRINT_MISSING_SYSCALLS
for (auto& Syscall : SyscallNames) {
if (Definitions[Syscall.first].Ptr == cvt(&UnimplementedSyscall)) {
if (Definitions[Syscall.first].Ptr == reinterpret_cast<void*>(&UnimplementedSyscall)) {
LogMan::Msg::DFmt("Unimplemented syscall: {}: {}", Syscall.first, Syscall.second);
}
}
Expand Down
11 changes: 1 addition & 10 deletions Source/Tools/LinuxEmulation/LinuxSyscalls/x32/Syscalls.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class SignalDelegator;
}

namespace FEX::HLE::x32 {
#include "SyscallsEnum.h"

class x32SyscallHandler final : public FEX::HLE::SyscallHandler {
public:
Expand All @@ -50,15 +49,7 @@ class x32SyscallHandler final : public FEX::HLE::SyscallHandler {
void* SyscallHandler, int ArgumentCount) override {
auto& Def = Definitions.at(SyscallNumber);
#if defined(ASSERTIONS_ENABLED) && ASSERTIONS_ENABLED
auto cvt = [](auto in) {
union {
decltype(in) val;
void* raw;
} raw;
raw.val = in;
return raw.raw;
};
LOGMAN_THROW_A_FMT(Def.Ptr == cvt(&UnimplementedSyscall), "Oops overwriting sysall problem, {}", SyscallNumber);
LOGMAN_THROW_A_FMT(Def.Ptr == reinterpret_cast<void*>(&UnimplementedSyscall), "Oops overwriting sysall problem, {}", SyscallNumber);
#endif
Def.Ptr = SyscallHandler;
Def.NumArgs = ArgumentCount;
Expand Down
2 changes: 2 additions & 0 deletions Source/Tools/LinuxEmulation/LinuxSyscalls/x32/SyscallsEnum.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ tags: LinuxSyscalls|syscalls-x86-32
*/
#pragma once

namespace FEX::HLE::x32 {
///< Enum containing all 32bit x86 linux syscalls for the guest kernel version
enum Syscalls_x86 {
SYSCALL_x86_restart_syscall = 0,
Expand Down Expand Up @@ -481,3 +482,4 @@ enum Syscalls_x86 {
SYSCALL_x86_mseal = 462,
SYSCALL_x86_MAX = 512,
};
} // namespace FEX::HLE::x32
33 changes: 8 additions & 25 deletions Source/Tools/LinuxEmulation/LinuxSyscalls/x64/Syscalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,6 @@ x64SyscallHandler::x64SyscallHandler(FEXCore::Context::Context* ctx, FEX::HLE::S
}

void x64SyscallHandler::RegisterSyscallHandlers() {
auto cvt = [](auto in) {
union {
decltype(in) val;
void* raw;
} raw;
raw.val = in;
return raw.raw;
};

Definitions.resize(FEX::HLE::x64::SYSCALL_x64_MAX, SyscallFunctionDefinition {
.NumArgs = 255,
.Ptr = cvt(&UnimplementedSyscall),
});

FEX::HLE::RegisterEpoll(this);
FEX::HLE::RegisterFD(this);
FEX::HLE::RegisterFS(this);
Expand Down Expand Up @@ -75,22 +61,19 @@ void x64SyscallHandler::RegisterSyscallHandlers() {
// Fill the gap to ensure that FEX doesn't assert
constexpr int SYSCALL_GAP_BEGIN = 335;
constexpr int SYSCALL_GAP_END = 424;
for (int SyscallNumber = SYSCALL_GAP_BEGIN; SyscallNumber < SYSCALL_GAP_END; ++SyscallNumber) {
auto& Def = Definitions.at(SyscallNumber);
Def.Ptr = cvt(&UnimplementedSyscallSafe);
Def.NumArgs = 0;
Def.Flags = FEXCore::IR::SyscallFlags::DEFAULT;
// This will allow our syscall optimization code to make this code more optimal
// Unlikely to hit a hot path though
Def.HostSyscallNumber = SYSCALL_DEF(MAX);

const SyscallFunctionDefinition InvalidSyscall {
.NumArgs = 0, .Flags = FEXCore::IR::SyscallFlags::DEFAULT, .Ptr = reinterpret_cast<void*>(&UnimplementedSyscall),
.HostSyscallNumber = SYSCALL_DEF(MAX),
#ifdef DEBUG_STRACE
Def.StraceFmt = "Invalid";
.StraceFmt = "Invalid";
#endif
}
};
std::fill(Definitions.begin() + SYSCALL_GAP_BEGIN, Definitions.begin() + SYSCALL_GAP_END, InvalidSyscall);

#if PRINT_MISSING_SYSCALLS
for (auto& Syscall : SyscallNames) {
if (Definitions[Syscall.first].Ptr == cvt(&UnimplementedSyscall)) {
if (Definitions[Syscall.first].Ptr == reinterpret_cast<void*>(&UnimplementedSyscall)) {
LogMan::Msg::DFmt("Unimplemented syscall: {}", Syscall.second);
}
}
Expand Down
10 changes: 1 addition & 9 deletions Source/Tools/LinuxEmulation/LinuxSyscalls/x64/Syscalls.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,7 @@ class x64SyscallHandler final : public FEX::HLE::SyscallHandler {
void* SyscallHandler, int ArgumentCount) override {
auto& Def = Definitions.at(SyscallNumber);
#if defined(ASSERTIONS_ENABLED) && ASSERTIONS_ENABLED
auto cvt = [](auto in) {
union {
decltype(in) val;
void* raw;
} raw;
raw.val = in;
return raw.raw;
};
LOGMAN_THROW_A_FMT(Def.Ptr == cvt(&UnimplementedSyscall), "Oops overwriting sysall problem, {}", SyscallNumber);
LOGMAN_THROW_A_FMT(Def.Ptr == reinterpret_cast<void*>(&UnimplementedSyscall), "Oops overwriting sysall problem, {}", SyscallNumber);
#endif
Def.Ptr = SyscallHandler;
Def.NumArgs = ArgumentCount;
Expand Down

0 comments on commit 27cd399

Please sign in to comment.