Skip to content

Commit

Permalink
Merge pull request #1284 from Sonicadvance1/fix_struct_match
Browse files Browse the repository at this point in the history
StructVerifier: Fix struct match and minor fixes
  • Loading branch information
Sonicadvance1 authored Oct 2, 2021
2 parents 08f5654 + 7c553f3 commit 2b757a9
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 16 deletions.
4 changes: 2 additions & 2 deletions Scripts/StructPackVerifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def HandleVarDeclElements(Arch, VarDecl, Cursor):
logging.critical ("Can't handle alias type '{0}'".format(Child.spelling))
Arch.Parsed = False
elif (Child.spelling == "fex-match"):
VarDecl.ExpectedFEXMatch = True
VarDecl.ExpectFEXMatch = True
else:
# Unknown annotation
pass
Expand Down Expand Up @@ -317,7 +317,7 @@ def HandleStructElements(Arch, Struct, Cursor):
Arch.Parsed = False

elif (Child.spelling == "fex-match"):
Struct.ExpectedFEXMatch = True
Struct.ExpectFEXMatch = True
else:
# Unknown annotation
pass
Expand Down
15 changes: 6 additions & 9 deletions Source/Tests/LinuxSyscalls/x32/EPoll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ tags: LinuxSyscalls|syscalls-x86-32
#include <unistd.h>
#include <vector>

ARG_TO_STR(FEX::HLE::x32::compat_ptr<FEX::HLE::epoll_event_x86>, "%lx")
ARG_TO_STR(FEX::HLE::x32::compat_ptr<FEX::HLE::x32::epoll_event32>, "%lx")
ARG_TO_STR(FEX::HLE::x32::compat_ptr<FEX::HLE::x32::timespec32>, "%lx")

namespace FEXCore::Core {
Expand All @@ -27,9 +27,9 @@ namespace FEXCore::Core {

namespace FEX::HLE::x32 {
void RegisterEpoll(FEX::HLE::SyscallHandler *const Handler) {
REGISTER_SYSCALL_IMPL_X32(epoll_wait, [](FEXCore::Core::CpuStateFrame *Frame, int epfd, compat_ptr<FEX::HLE::epoll_event_x86> events, int maxevents, int timeout) -> uint64_t {
REGISTER_SYSCALL_IMPL_X32(epoll_wait, [](FEXCore::Core::CpuStateFrame *Frame, int epfd, compat_ptr<FEX::HLE::x32::epoll_event32> events, int maxevents, int timeout) -> uint64_t {
std::vector<struct epoll_event> Events(std::max(0, maxevents));
uint64_t Result = ::syscall(SYS_epoll_pwait, epfd, Events.data(), maxevents, timeout, nullptr);
uint64_t Result = ::syscall(SYS_epoll_pwait, epfd, Events.data(), maxevents, timeout, nullptr, 8);

if (Result != -1) {
for (size_t i = 0; i < Result; ++i) {
Expand All @@ -39,16 +39,13 @@ namespace FEX::HLE::x32 {
SYSCALL_ERRNO();
});

REGISTER_SYSCALL_IMPL_X32(epoll_ctl, [](FEXCore::Core::CpuStateFrame *Frame, int epfd, int op, int fd, compat_ptr<FEX::HLE::epoll_event_x86> event) -> uint64_t {
REGISTER_SYSCALL_IMPL_X32(epoll_ctl, [](FEXCore::Core::CpuStateFrame *Frame, int epfd, int op, int fd, compat_ptr<FEX::HLE::x32::epoll_event32> event) -> uint64_t {
struct epoll_event Event = *event;
uint64_t Result = ::syscall(SYS_epoll_ctl, epfd, op, fd, &Event);
if (Result != -1) {
*event = Event;
}
SYSCALL_ERRNO();
});

REGISTER_SYSCALL_IMPL_X32(epoll_pwait, [](FEXCore::Core::CpuStateFrame *Frame, int epfd, compat_ptr<FEX::HLE::epoll_event_x86> events, int maxevent, int timeout, const uint64_t* sigmask, size_t sigsetsize) -> uint64_t {
REGISTER_SYSCALL_IMPL_X32(epoll_pwait, [](FEXCore::Core::CpuStateFrame *Frame, int epfd, compat_ptr<FEX::HLE::x32::epoll_event32> events, int maxevent, int timeout, const uint64_t* sigmask, size_t sigsetsize) -> uint64_t {
std::vector<struct epoll_event> Events(std::max(0, maxevent));

uint64_t Result = ::syscall(SYS_epoll_pwait,
Expand All @@ -72,7 +69,7 @@ namespace FEX::HLE::x32 {
#ifndef SYS_epoll_pwait2
#define SYS_epoll_pwait2 354
#endif
REGISTER_SYSCALL_IMPL_X32(epoll_pwait2, [](FEXCore::Core::CpuStateFrame *Frame, int epfd, compat_ptr<FEX::HLE::epoll_event_x86> events, int maxevent, compat_ptr<timespec32> timeout, const uint64_t* sigmask, size_t sigsetsize) -> uint64_t {
REGISTER_SYSCALL_IMPL_X32(epoll_pwait2, [](FEXCore::Core::CpuStateFrame *Frame, int epfd, compat_ptr<FEX::HLE::x32::epoll_event32> events, int maxevent, compat_ptr<timespec32> timeout, const uint64_t* sigmask, size_t sigsetsize) -> uint64_t {
std::vector<struct epoll_event> Events(std::max(0, maxevent));

struct timespec tp64{};
Expand Down
3 changes: 3 additions & 0 deletions Source/Tests/LinuxSyscalls/x32/Info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ namespace FEXCore::Core {
struct CpuStateFrame;
}

ARG_TO_STR(FEX::HLE::x32::compat_ptr<FEX::HLE::x32::rlimit32<true>>, "%lx")
ARG_TO_STR(FEX::HLE::x32::compat_ptr<FEX::HLE::x32::rlimit32<false>>, "%lx")

namespace FEX::HLE::x32 {
struct sysinfo32 {
int32_t uptime;
Expand Down
3 changes: 3 additions & 0 deletions Source/Tests/LinuxSyscalls/x32/Msg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ tags: LinuxSyscalls|syscalls-x86-32
#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() {
REGISTER_SYSCALL_IMPL_X32(mq_timedsend, [](FEXCore::Core::CpuStateFrame *Frame, mqd_t mqdes, const char *msg_ptr, size_t msg_len, unsigned int msg_prio, const struct timespec32 *abs_timeout) -> uint64_t {
Expand Down
2 changes: 2 additions & 0 deletions Source/Tests/LinuxSyscalls/x32/Signals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ namespace FEXCore::Core {
struct CpuStateFrame;
}

ARG_TO_STR(FEX::HLE::x32::compat_ptr<FEXCore::x86::siginfo_t>, "%lx")

namespace FEX::HLE::x32 {
void CopySigInfo(FEXCore::x86::siginfo_t *Info, siginfo_t const &Host) {
// Copy the basic things first
Expand Down
1 change: 1 addition & 0 deletions Source/Tests/LinuxSyscalls/x32/Time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ tags: LinuxSyscalls|syscalls-x86-32
#include <utime.h>

ARG_TO_STR(FEX::HLE::x32::compat_ptr<FEX::HLE::x32::timespec32>, "%lx")
ARG_TO_STR(FEX::HLE::x32::compat_ptr<FEX::HLE::x32::timex32>, "%lx")

struct timespec;
namespace FEXCore::Core {
Expand Down
2 changes: 2 additions & 0 deletions Source/Tests/LinuxSyscalls/x32/Timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ namespace FEXCore::Core {
struct CpuStateFrame;
}

ARG_TO_STR(FEX::HLE::x32::compat_ptr<FEX::HLE::x32::sigevent32>, "%lx")

namespace FEX::HLE::x32 {
void RegisterTimer() {
REGISTER_SYSCALL_IMPL_X32(timer_settime, [](FEXCore::Core::CpuStateFrame *Frame,
Expand Down
46 changes: 41 additions & 5 deletions Source/Tests/LinuxSyscalls/x32/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ using compat_long_t = int32_t;
using compat_uptr_t = uint32_t;
using compat_size_t = uint32_t;
using compat_off_t = uint32_t;
using compat_loff_t = int64_t;
using compat_pid_t = int32_t;
using compat_dev_t = uint16_t;
using compat_ino_t = uint32_t;
Expand All @@ -51,6 +50,7 @@ using compat_clock_t = int32_t;
// Can't use using with aligned attributes, clang doesn't honour it
typedef FEX_ALIGNED(4) uint64_t compat_uint64_t;
typedef FEX_ALIGNED(4) int64_t compat_int64_t;
typedef FEX_ALIGNED(4) int64_t compat_loff_t;

template<typename T>
class compat_ptr {
Expand Down Expand Up @@ -645,8 +645,8 @@ static_assert(sizeof(flock64_32) == 24, "Incorrect size");
struct
FEX_ANNOTATE("fex-match")
linux_dirent {
uint64_t d_ino;
int64_t d_off;
compat_uint64_t d_ino;
compat_int64_t d_off;
uint16_t d_reclen;
uint8_t _pad[6];
char d_name[];
Expand All @@ -673,8 +673,8 @@ static_assert(sizeof(linux_dirent_32) == 12, "Incorrect size");
struct
FEX_ANNOTATE("fex-match")
linux_dirent_64 {
uint64_t d_ino;
uint64_t d_off;
compat_uint64_t d_ino;
compat_uint64_t d_off;
uint16_t d_reclen;
uint8_t d_type;
uint8_t _pad[5];
Expand Down Expand Up @@ -1156,4 +1156,40 @@ mq_attr32 {

static_assert(std::is_trivial<mq_attr32>::value, "Needs to be trivial");
static_assert(sizeof(mq_attr32) == 32, "Incorrect size");

union
FEX_ANNOTATE("alias-x86_32-epoll_data_t")
FEX_ANNOTATE("fex-match")
epoll_data32 {
compat_ptr<void> ptr;
int fd;
uint32_t u32;
compat_uint64_t u64;
};

struct
FEX_PACKED
FEX_ANNOTATE("alias-x86_32-epoll_event")
FEX_ANNOTATE("fex-match")
epoll_event32 {
uint32_t events;
epoll_data32 data;

epoll_event32() = delete;

operator struct epoll_event() const {
epoll_event event{};
event.events = events;
event.data.u64 = data.u64;
return event;
}

epoll_event32(struct epoll_event event)
: data { event.data.u64 }{
events = event.events;
}
};
static_assert(std::is_trivial<epoll_event32>::value, "Needs to be trivial");
static_assert(sizeof(epoll_event32) == 12, "Incorrect size");

}
2 changes: 2 additions & 0 deletions Source/Tests/LinuxSyscalls/x64/Semaphore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ namespace FEXCore::Core {
struct CpuStateFrame;
}

ARG_TO_STR(FEX::HLE::x64::semun, "%lx")

namespace FEX::HLE::x64 {
void RegisterSemaphore() {
REGISTER_SYSCALL_IMPL_X64(semop, [](FEXCore::Core::CpuStateFrame *Frame, int semid, struct sembuf *sops, size_t nsops) -> uint64_t {
Expand Down

0 comments on commit 2b757a9

Please sign in to comment.