Skip to content

Commit

Permalink
Add pidfd_open syscall helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
wannacu committed Jul 15, 2022
1 parent 8d60d70 commit 0dd03e9
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ out/
.vscode/
.vs/
*.pyc
.cache
13 changes: 13 additions & 0 deletions FEXHeaderUtils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,16 @@ if (compiles)
add_definitions(-DHAS_SYSCALL_RENAMEAT2=1)
endif ()

check_cxx_source_compiles(
"
#include <stdio.h>
#include <syscall.h>
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 ()

7 changes: 7 additions & 0 deletions FEXHeaderUtils/FEXHeaderUtils/Syscalls.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

}
3 changes: 2 additions & 1 deletion Source/Tools/FEXServer/ProcessPipe.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "FEXHeaderUtils/Syscalls.h"
#include "Logger.h"
#include "SquashFS.h"

Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 0dd03e9

Please sign in to comment.