diff --git a/shared/source/os_interface/linux/sys_calls.h b/shared/source/os_interface/linux/sys_calls.h index 88ae3afa5e..e78baece5c 100644 --- a/shared/source/os_interface/linux/sys_calls.h +++ b/shared/source/os_interface/linux/sys_calls.h @@ -14,6 +14,7 @@ #include #include #include +#include namespace NEO { namespace SysCalls { @@ -56,5 +57,7 @@ int closedir(DIR *dir); off_t lseek(int fd, off_t offset, int whence) noexcept; long sysconf(int name); int mkfifo(const char *pathname, mode_t mode); +int pidfdopen(pid_t pid, unsigned int flags); +int pidfdgetfd(int pidfd, int targetfd, unsigned int flags); } // namespace SysCalls } // namespace NEO diff --git a/shared/source/os_interface/linux/sys_calls_linux.cpp b/shared/source/os_interface/linux/sys_calls_linux.cpp index 348a02926a..b32f8aecc7 100644 --- a/shared/source/os_interface/linux/sys_calls_linux.cpp +++ b/shared/source/os_interface/linux/sys_calls_linux.cpp @@ -18,10 +18,15 @@ #include #include #include +#include #include #include #include +#ifndef SYS_pidfd_getfd +#define SYS_pidfd_getfd 438 +#endif + namespace NEO { namespace SysCalls { @@ -184,6 +189,16 @@ int closedir(DIR *dir) { return ::closedir(dir); } +int pidfdopen(pid_t pid, unsigned int flags) { + long retval = ::syscall(SYS_pidfd_open, pid, flags); + return static_cast(retval); +} + +int pidfdgetfd(int pidfd, int targetfd, unsigned int flags) { + long retval = ::syscall(SYS_pidfd_getfd, pidfd, targetfd, flags); + return static_cast(retval); +} + off_t lseek(int fd, off_t offset, int whence) noexcept { return ::lseek(fd, offset, whence); } diff --git a/shared/test/common/os_interface/linux/sys_calls_linux_ult.cpp b/shared/test/common/os_interface/linux/sys_calls_linux_ult.cpp index 11f74d6d14..0be5ec1310 100644 --- a/shared/test/common/os_interface/linux/sys_calls_linux_ult.cpp +++ b/shared/test/common/os_interface/linux/sys_calls_linux_ult.cpp @@ -66,6 +66,8 @@ int flockCalled = 0; int opendirCalled = 0; int readdirCalled = 0; int closedirCalled = 0; +int pidfdopenCalled = 0; +int pidfdgetfdCalled = 0; int fsyncCalled = 0; int fsyncArgPassed = 0; int fsyncRetVal = 0; @@ -112,6 +114,8 @@ DIR *(*sysCallsOpendir)(const char *name) = nullptr; struct dirent *(*sysCallsReaddir)(DIR *dir) = nullptr; int (*sysCallsClosedir)(DIR *dir) = nullptr; int (*sysCallsGetDevicePath)(int deviceFd, char *buf, size_t &bufSize) = nullptr; +int (*sysCallsPidfdOpen)(pid_t pid, unsigned int flags) = nullptr; +int (*sysCallsPidfdGetfd)(int pidfd, int fd, unsigned int flags) = nullptr; off_t lseekReturn = 4096u; std::atomic lseekCalledCount(0); long sysconfReturn = 1ull << 30; @@ -536,5 +540,21 @@ int mkfifo(const char *pathname, mode_t mode) { return 0; } +int pidfdopen(pid_t pid, unsigned int flags) { + pidfdopenCalled++; + if (sysCallsPidfdOpen != nullptr) { + return sysCallsPidfdOpen(pid, flags); + } + return 0; +} + +int pidfdgetfd(int pid, int targetfd, unsigned int flags) { + pidfdgetfdCalled++; + if (sysCallsPidfdGetfd != nullptr) { + return sysCallsPidfdGetfd(pid, targetfd, flags); + } + return 0; +} + } // namespace SysCalls } // namespace NEO diff --git a/shared/test/common/os_interface/linux/sys_calls_linux_ult.h b/shared/test/common/os_interface/linux/sys_calls_linux_ult.h index d40ca039e7..c314dff322 100644 --- a/shared/test/common/os_interface/linux/sys_calls_linux_ult.h +++ b/shared/test/common/os_interface/linux/sys_calls_linux_ult.h @@ -13,6 +13,7 @@ #include #include #include +#include #include namespace NEO { @@ -49,6 +50,8 @@ extern struct dirent *(*sysCallsReaddir)(DIR *dir); extern int (*sysCallsClosedir)(DIR *dir); extern int (*sysCallsGetDevicePath)(int deviceFd, char *buf, size_t &bufSize); extern int (*sysCallsClose)(int fileDescriptor); +extern int (*sysCallsPidfdOpen)(pid_t pid, unsigned int flags); +extern int (*sysCallsPidfdGetfd)(int pidfd, int fd, unsigned int flags); extern bool allowFakeDevicePath; extern int flockRetVal; @@ -83,6 +86,8 @@ extern bool failFcntl; extern bool failFcntl1; extern bool failAccess; extern int setErrno; +extern int pidfdopenCalled; +extern int pidfdgetfdCalled; extern std::vector mmapVector; extern std::vector mmapCapturedExtendedPointers;