Skip to content

Commit 6c06f47

Browse files
authored
Merge pull request #5201 from Sonicadvance1/40
LinuxSyscalls/x32: Fixes fcntl assert
2 parents ed1d495 + c7df064 commit 6c06f47

File tree

1 file changed

+23
-15
lines changed
  • Source/Tools/LinuxEmulation/LinuxSyscalls/x32

1 file changed

+23
-15
lines changed

Source/Tools/LinuxEmulation/LinuxSyscalls/x32/FD.cpp

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,14 @@ uint32_t ioctl_32(FEXCore::Core::CpuStateFrame*, int fd, uint32_t cmd, uint32_t
6060
return Result;
6161
}
6262
#endif
63+
// These are redefined to be their non-64bit tagged value on x86-64
64+
constexpr int OP_GETLK64_32 = 12;
65+
constexpr int OP_SETLK64_32 = 13;
66+
constexpr int OP_SETLKW64_32 = 14;
67+
6368
auto fcntlHandler = [](FEXCore::Core::CpuStateFrame* Frame, int fd, int cmd, uint64_t arg) -> uint64_t {
6469
// fcntl64 struct directly matches the 64bit fcntl op
6570
// cmd just needs to be fixed up
66-
// These are redefined to be their non-64bit tagged value on x86-64
67-
constexpr int OP_GETLK64_32 = 12;
68-
constexpr int OP_SETLK64_32 = 13;
69-
constexpr int OP_SETLKW64_32 = 14;
7071

7172
void* lock_arg = (void*)arg;
7273
struct flock tmp {};
@@ -112,16 +113,8 @@ auto fcntlHandler = [](FEXCore::Core::CpuStateFrame* Frame, int fd, int cmd, uin
112113
}
113114

114115
case F_SETFL: lock_arg = reinterpret_cast<void*>(FEX::HLE::RemapFromX86Flags(arg)); break;
115-
// Maps directly
116-
case F_DUPFD:
117-
case F_DUPFD_CLOEXEC:
118-
case F_GETFD:
119-
case F_SETFD:
120-
case F_GETFL:
121-
case F_ADD_SEALS:
122-
case F_GET_SEALS: break;
123-
124-
default: LOGMAN_MSG_A_FMT("Unhandled fcntl64: 0x{:x}", cmd); break;
116+
// Everything else maps directly. Check `COMPAT_SYSCALL_DEFINE3(fcntl64, ...)` entrypoint in the kernel if this changes.
117+
default: break;
125118
}
126119

127120
uint64_t Result = ::fcntl(fd, cmd, lock_arg);
@@ -155,6 +148,21 @@ auto fcntlHandler = [](FEXCore::Core::CpuStateFrame* Frame, int fd, int cmd, uin
155148
SYSCALL_ERRNO();
156149
};
157150

151+
auto fcntl32Handler = [](FEXCore::Core::CpuStateFrame* Frame, int fd, int cmd, uint64_t arg) -> uint64_t {
152+
// fcntl32 handler explicitly blocks these commands.
153+
switch (cmd) {
154+
case OP_GETLK64_32:
155+
case OP_SETLK64_32:
156+
case OP_SETLKW64_32:
157+
case F_OFD_GETLK:
158+
case F_OFD_SETLK:
159+
case F_OFD_SETLKW: return -EINVAL;
160+
default: break;
161+
}
162+
163+
return fcntlHandler(Frame, fd, cmd, arg);
164+
};
165+
158166
auto selectHandler = [](FEXCore::Core::CpuStateFrame* Frame, int nfds, fd_set32* readfds, fd_set32* writefds, fd_set32* exceptfds,
159167
struct timeval32* timeout) -> uint64_t {
160168
struct timeval tp64 {};
@@ -495,7 +503,7 @@ void RegisterFD(FEX::HLE::SyscallHandler* Handler) {
495503
// - F_OFD_SETLK
496504
// - F_OFD_SETLKW
497505

498-
REGISTER_SYSCALL_IMPL_X32(fcntl, fcntlHandler);
506+
REGISTER_SYSCALL_IMPL_X32(fcntl, fcntl32Handler);
499507
REGISTER_SYSCALL_IMPL_X32(fcntl64, fcntlHandler);
500508

501509
REGISTER_SYSCALL_IMPL_X32(dup, [](FEXCore::Core::CpuStateFrame* Frame, int oldfd) -> uint64_t {

0 commit comments

Comments
 (0)