diff --git a/.gitignore b/.gitignore index b60a8411a..44b57702e 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ out/ .vscode/ .vs/ *.pyc +.cache diff --git a/FEXHeaderUtils/CMakeLists.txt b/FEXHeaderUtils/CMakeLists.txt index f647de90d..835266826 100644 --- a/FEXHeaderUtils/CMakeLists.txt +++ b/FEXHeaderUtils/CMakeLists.txt @@ -59,3 +59,16 @@ if (compiles) add_definitions(-DHAS_SYSCALL_RENAMEAT2=1) endif () +check_cxx_source_compiles( + " + #include + #include + int main() { + return ::syscall(SYS_pidfd_open, ::getpid(), 0); + }" + compiles) +if (compiles) + message(STATUS "Has pidfd_open helper") + add_definitions(-DHAS_SYSCALL_PIDFD_OPEN=1) +endif () + diff --git a/FEXHeaderUtils/FEXHeaderUtils/Syscalls.h b/FEXHeaderUtils/FEXHeaderUtils/Syscalls.h index 34455f78a..997418204 100644 --- a/FEXHeaderUtils/FEXHeaderUtils/Syscalls.h +++ b/FEXHeaderUtils/FEXHeaderUtils/Syscalls.h @@ -79,5 +79,12 @@ inline int32_t renameat2(int olddirfd, const char *oldpath, int newdirfd, const #endif } +inline int32_t pidfd_open(pid_t pid, unsigned int flags) { +#if defined(DHAS_SYSCALL_PIDFD_OPEN) && DHAS_SYSCALL_PIDFD_OPEN + return ::syscall(SYS_pidfd_open, pid_t pid, unsigned int flags); +#else + return -1; +#endif +} } diff --git a/Source/Tools/FEXServer/ProcessPipe.cpp b/Source/Tools/FEXServer/ProcessPipe.cpp index 613746909..7e916e0e1 100644 --- a/Source/Tools/FEXServer/ProcessPipe.cpp +++ b/Source/Tools/FEXServer/ProcessPipe.cpp @@ -1,3 +1,4 @@ +#include "FEXHeaderUtils/Syscalls.h" #include "Logger.h" #include "SquashFS.h" @@ -398,7 +399,7 @@ namespace ProcessPipe { break; } case FEXServerClient::PacketType::TYPE_GET_PID_FD: { - int FD = ::syscall(SYS_pidfd_open, ::getpid(), 0); + int FD = FHU::Syscalls::pidfd_open(::getpid(), 0); SendFDSuccessPacket(Socket, FD);