Merge pull request #1096 from Sonicadvance1/fix_kotor2

Fix Star Wars Knights of the Old Republic 2
This commit is contained in:
Stefanos Kornilios Mitsis Poiitidis authored and GitHub committed 2021-06-22 09:14:02 +03:00
commit 24fdbe4e6d
5 files changed
+110 -19

No files matched your search

@@ -15,7 +15,6 @@ $end_info$
#include <sys/swap.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <sys/vfs.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/xattr.h>
@@ -110,16 +109,6 @@ namespace FEX::HLE {
#endif
});
REGISTER_SYSCALL_IMPL(statfs, [](FEXCore::Core::CpuStateFrame *Frame, const char *path, struct statfs *buf) -> uint64_t {
uint64_t Result = FEX::HLE::_SyscallHandler->FM.Statfs(path, buf);
SYSCALL_ERRNO();
});
REGISTER_SYSCALL_IMPL(fstatfs, [](FEXCore::Core::CpuStateFrame *Frame, int fd, struct statfs *buf) -> uint64_t {
uint64_t Result = ::fstatfs(fd, buf);
SYSCALL_ERRNO();
});
REGISTER_SYSCALL_IMPL(truncate, [](FEXCore::Core::CpuStateFrame *Frame, const char *path, off_t length) -> uint64_t {
uint64_t Result = ::truncate(path, length);
SYSCALL_ERRNO();
+18
View File
@@ -174,6 +174,24 @@ namespace FEX::HLE::x32 {
SYSCALL_ERRNO();
});
REGISTER_SYSCALL_IMPL_X32(statfs, [](FEXCore::Core::CpuStateFrame *Frame, const char *path, statfs32_32 *buf) -> uint64_t {
struct statfs host_stat;
uint64_t Result = FEX::HLE::_SyscallHandler->FM.Statfs(path, &host_stat);
if (Result != -1) {
*buf = host_stat;
}
SYSCALL_ERRNO();
});
REGISTER_SYSCALL_IMPL_X32(fstatfs, [](FEXCore::Core::CpuStateFrame *Frame, int fd, statfs32_32 *buf) -> uint64_t {
struct statfs host_stat;
uint64_t Result = ::fstatfs(fd, &host_stat);
if (Result != -1) {
*buf = host_stat;
}
SYSCALL_ERRNO();
});
REGISTER_SYSCALL_IMPL_X32(fstatfs64, [](FEXCore::Core::CpuStateFrame *Frame, int fd, size_t sz, struct statfs64_32 *buf) -> uint64_t {
LOGMAN_THROW_A(sz == sizeof(struct statfs64_32), "This needs to match");
+25 -8
View File
@@ -28,8 +28,9 @@ namespace FEX::HLE::x32 {
uint32_t freeswap;
uint16_t procs;
uint32_t totalhigh;
uint32_t freehigh;
uint32_t mem_unit;
char _pad[12];
char _pad[8];
};
static_assert(sizeof(sysinfo32) == 64, "Needs to be 64bytes");
@@ -49,16 +50,32 @@ namespace FEX::HLE::x32 {
if (Result != -1) {
#define Copy(x) info->x = static_cast<decltype(info->x)>(std::min(Host.x, static_cast<decltype(Host.x)>(std::numeric_limits<decltype(info->x)>::max())));
Copy(uptime);
Copy(procs);
#define CopyShift(x) info->x = static_cast<decltype(info->x)>(Host.x >> ShiftAmount);
info->loads[0] = std::min(Host.loads[0], static_cast<unsigned long>(std::numeric_limits<uint32_t>::max()));
info->loads[1] = std::min(Host.loads[1], static_cast<unsigned long>(std::numeric_limits<uint32_t>::max()));
info->loads[2] = std::min(Host.loads[2], static_cast<unsigned long>(std::numeric_limits<uint32_t>::max()));
Copy(totalram);
Copy(sharedram);
Copy(bufferram);
Copy(totalswap);
Copy(freeswap);
Copy(procs);
Copy(totalhigh);
// If any result can't fit in to a uint32_t then we need to shift the mem_unit and all the members
// Set the mem_unit to the pagesize
uint32_t ShiftAmount{};
if ((Host.totalram >> 32) != 0 ||
(Host.totalswap >> 32) != 0) {
while (Host.mem_unit < 4096) {
Host.mem_unit <<= 1;
++ShiftAmount;
}
}
CopyShift(totalram);
CopyShift(sharedram);
CopyShift(bufferram);
CopyShift(totalswap);
CopyShift(freeswap);
CopyShift(totalhigh);
CopyShift(freehigh);
Copy(mem_unit);
}
SYSCALL_ERRNO();
+56
View File
@@ -471,6 +471,62 @@ statfs64_32 {
static_assert(std::is_trivial<statfs64_32>::value, "Needs to be trivial");
static_assert(sizeof(statfs64_32) == 84, "Incorrect size");
struct
FEX_ANNOTATE("alias-x86_32-statfs")
FEX_ANNOTATE("fex-match")
statfs32_32 {
int32_t f_type;
int32_t f_bsize;
int32_t f_blocks;
int32_t f_bfree;
int32_t f_bavail;
int32_t f_files;
int32_t f_ffree;
__kernel_fsid_t f_fsid;
int32_t f_namelen;
int32_t f_frsize;
int32_t f_flags;
int32_t pad[4];
statfs32_32() = delete;
statfs32_32(struct statfs host) {
#define COPY(x) x = host.x
COPY(f_type);
COPY(f_bsize);
COPY(f_blocks);
COPY(f_bfree);
COPY(f_bavail);
COPY(f_files);
COPY(f_ffree);
COPY(f_namelen);
COPY(f_frsize);
COPY(f_flags);
memcpy(&f_fsid, &host.f_fsid, sizeof(f_fsid));
#undef COPY
}
statfs32_32(struct statfs64 host) {
#define COPY(x) x = host.x
COPY(f_type);
COPY(f_bsize);
COPY(f_blocks);
COPY(f_bfree);
COPY(f_bavail);
COPY(f_files);
COPY(f_ffree);
COPY(f_namelen);
COPY(f_frsize);
COPY(f_flags);
memcpy(&f_fsid, &host.f_fsid, sizeof(f_fsid));
#undef COPY
}
};
static_assert(std::is_trivial<statfs32_32>::value, "Needs to be trivial");
static_assert(sizeof(statfs32_32) == 64, "Incorrect size");
struct
FEX_ANNOTATE("alias-x86_32-flock")
FEX_ANNOTATE("fex-match")
+11
View File
@@ -15,6 +15,7 @@ $end_info$
#include <sys/uio.h>
#include <sys/sendfile.h>
#include <sys/syscall.h>
#include <sys/vfs.h>
#include <unistd.h>
namespace FEX::HLE::x64 {
@@ -234,5 +235,15 @@ namespace FEX::HLE::x64 {
uint64_t Result = ::dup2(oldfd, newfd);
SYSCALL_ERRNO();
});
REGISTER_SYSCALL_IMPL_X64(statfs, [](FEXCore::Core::CpuStateFrame *Frame, const char *path, struct statfs *buf) -> uint64_t {
uint64_t Result = FEX::HLE::_SyscallHandler->FM.Statfs(path, buf);
SYSCALL_ERRNO();
});
REGISTER_SYSCALL_IMPL_X64(fstatfs, [](FEXCore::Core::CpuStateFrame *Frame, int fd, struct statfs *buf) -> uint64_t {
uint64_t Result = ::fstatfs(fd, buf);
SYSCALL_ERRNO();
});
}
}