[libc-commits] [libc] 819b155 - [libc] skip test and return ENOSYS when processm_release unavailable (#117951)

via libc-commits libc-commits at lists.llvm.org
Wed Nov 27 17:52:20 PST 2024


Author: Schrodinger ZHU Yifan
Date: 2024-11-27T20:52:16-05:00
New Revision: 819b155c2a18460d2f22482975d33d77bb4f8831

URL: https://github.com/llvm/llvm-project/commit/819b155c2a18460d2f22482975d33d77bb4f8831
DIFF: https://github.com/llvm/llvm-project/commit/819b155c2a18460d2f22482975d33d77bb4f8831.diff

LOG: [libc] skip test and return ENOSYS when processm_release unavailable (#117951)

Added: 
    

Modified: 
    libc/src/sys/mman/linux/process_mrelease.cpp
    libc/test/src/sys/mman/linux/CMakeLists.txt
    libc/test/src/sys/mman/linux/process_mrelease_test.cpp

Removed: 
    


################################################################################
diff  --git a/libc/src/sys/mman/linux/process_mrelease.cpp b/libc/src/sys/mman/linux/process_mrelease.cpp
index e86bbec1b1b661..7660f1e23ece2a 100644
--- a/libc/src/sys/mman/linux/process_mrelease.cpp
+++ b/libc/src/sys/mman/linux/process_mrelease.cpp
@@ -19,6 +19,7 @@
 namespace LIBC_NAMESPACE_DECL {
 
 LLVM_LIBC_FUNCTION(int, process_mrelease, (int pidfd, unsigned int flags)) {
+#ifdef SYS_process_mrelease
   long ret =
       LIBC_NAMESPACE::syscall_impl<int>(SYS_process_mrelease, pidfd, flags);
 
@@ -28,6 +29,13 @@ LLVM_LIBC_FUNCTION(int, process_mrelease, (int pidfd, unsigned int flags)) {
   }
 
   return 0;
+#else
+  // The system call is not available.
+  (void)pidfd;
+  (void)flags;
+  libc_errno = ENOSYS;
+  return -1;
+#endif
 }
 
 } // namespace LIBC_NAMESPACE_DECL

diff  --git a/libc/test/src/sys/mman/linux/CMakeLists.txt b/libc/test/src/sys/mman/linux/CMakeLists.txt
index 1a5ff3af8eb117..6362b46a6fe090 100644
--- a/libc/test/src/sys/mman/linux/CMakeLists.txt
+++ b/libc/test/src/sys/mman/linux/CMakeLists.txt
@@ -197,6 +197,7 @@ add_libc_unittest(
     libc.src.signal.kill
     libc.include.signal
     libc.src.stdlib.exit
+    libc.src.signal.raise
     libc.src.__support.OSUtil.osutil
     libc.src.__support.threads.sleep
     libc.test.UnitTest.ErrnoSetterMatcher

diff  --git a/libc/test/src/sys/mman/linux/process_mrelease_test.cpp b/libc/test/src/sys/mman/linux/process_mrelease_test.cpp
index 56a7d66ee7a5ac..71cde7a85a6711 100644
--- a/libc/test/src/sys/mman/linux/process_mrelease_test.cpp
+++ b/libc/test/src/sys/mman/linux/process_mrelease_test.cpp
@@ -7,9 +7,9 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/__support/OSUtil/syscall.h" // For internal syscall function.
-#include "src/__support/threads/sleep.h"
 #include "src/errno/libc_errno.h"
 #include "src/signal/kill.h"
+#include "src/signal/raise.h"
 #include "src/stdlib/exit.h"
 #include "src/sys/mman/process_mrelease.h"
 #include "src/unistd/close.h"
@@ -18,7 +18,7 @@
 #include "test/UnitTest/LibcTest.h"
 
 #include <sys/syscall.h>
-
+#if defined(SYS_process_mrelease) && defined(SYS_pidfd_open)
 using namespace LIBC_NAMESPACE::testing::ErrnoSetterMatcher;
 
 int pidfd_open(pid_t pid, unsigned int flags) {
@@ -30,13 +30,11 @@ TEST(LlvmLibcProcessMReleaseTest, NoError) {
   EXPECT_GE(child_pid, 0);
 
   if (child_pid == 0) {
-    // Child process: wait a bit then exit gracefully.
-    LIBC_NAMESPACE::sleep_briefly();
-    LIBC_NAMESPACE::exit(0);
+    // pause the child process
+    LIBC_NAMESPACE::raise(SIGSTOP);
   } else {
     // Parent process: wait a bit and then kill the child.
     // Give child process some time to start.
-    LIBC_NAMESPACE::sleep_briefly();
     int pidfd = pidfd_open(child_pid, 0);
     EXPECT_GE(pidfd, 0);
 
@@ -54,12 +52,9 @@ TEST(LlvmLibcProcessMReleaseTest, ErrorNotKilled) {
   EXPECT_GE(child_pid, 0);
 
   if (child_pid == 0) {
-    // Child process: wait a bit then exit gracefully.
-    LIBC_NAMESPACE::sleep_briefly();
-    LIBC_NAMESPACE::exit(0);
+    // pause the child process
+    LIBC_NAMESPACE::raise(SIGSTOP);
   } else {
-    // Give child process some time to start.
-    LIBC_NAMESPACE::sleep_briefly();
     int pidfd = pidfd_open(child_pid, 0);
     EXPECT_GE(pidfd, 0);
 
@@ -72,3 +67,4 @@ TEST(LlvmLibcProcessMReleaseTest, ErrorNotKilled) {
 TEST(LlvmLibcProcessMReleaseTest, ErrorNonExistingPidfd) {
   EXPECT_THAT(LIBC_NAMESPACE::process_mrelease(-1, 0), Fails(EBADF));
 }
+#endif


        


More information about the libc-commits mailing list