Skip to content

Commit 819b155

Browse files
[libc] skip test and return ENOSYS when processm_release unavailable (#117951)
1 parent c8cd497 commit 819b155

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

libc/src/sys/mman/linux/process_mrelease.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
namespace LIBC_NAMESPACE_DECL {
2020

2121
LLVM_LIBC_FUNCTION(int, process_mrelease, (int pidfd, unsigned int flags)) {
22+
#ifdef SYS_process_mrelease
2223
long ret =
2324
LIBC_NAMESPACE::syscall_impl<int>(SYS_process_mrelease, pidfd, flags);
2425

@@ -28,6 +29,13 @@ LLVM_LIBC_FUNCTION(int, process_mrelease, (int pidfd, unsigned int flags)) {
2829
}
2930

3031
return 0;
32+
#else
33+
// The system call is not available.
34+
(void)pidfd;
35+
(void)flags;
36+
libc_errno = ENOSYS;
37+
return -1;
38+
#endif
3139
}
3240

3341
} // namespace LIBC_NAMESPACE_DECL

libc/test/src/sys/mman/linux/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ add_libc_unittest(
197197
libc.src.signal.kill
198198
libc.include.signal
199199
libc.src.stdlib.exit
200+
libc.src.signal.raise
200201
libc.src.__support.OSUtil.osutil
201202
libc.src.__support.threads.sleep
202203
libc.test.UnitTest.ErrnoSetterMatcher

libc/test/src/sys/mman/linux/process_mrelease_test.cpp

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
10-
#include "src/__support/threads/sleep.h"
1110
#include "src/errno/libc_errno.h"
1211
#include "src/signal/kill.h"
12+
#include "src/signal/raise.h"
1313
#include "src/stdlib/exit.h"
1414
#include "src/sys/mman/process_mrelease.h"
1515
#include "src/unistd/close.h"
@@ -18,7 +18,7 @@
1818
#include "test/UnitTest/LibcTest.h"
1919

2020
#include <sys/syscall.h>
21-
21+
#if defined(SYS_process_mrelease) && defined(SYS_pidfd_open)
2222
using namespace LIBC_NAMESPACE::testing::ErrnoSetterMatcher;
2323

2424
int pidfd_open(pid_t pid, unsigned int flags) {
@@ -30,13 +30,11 @@ TEST(LlvmLibcProcessMReleaseTest, NoError) {
3030
EXPECT_GE(child_pid, 0);
3131

3232
if (child_pid == 0) {
33-
// Child process: wait a bit then exit gracefully.
34-
LIBC_NAMESPACE::sleep_briefly();
35-
LIBC_NAMESPACE::exit(0);
33+
// pause the child process
34+
LIBC_NAMESPACE::raise(SIGSTOP);
3635
} else {
3736
// Parent process: wait a bit and then kill the child.
3837
// Give child process some time to start.
39-
LIBC_NAMESPACE::sleep_briefly();
4038
int pidfd = pidfd_open(child_pid, 0);
4139
EXPECT_GE(pidfd, 0);
4240

@@ -54,12 +52,9 @@ TEST(LlvmLibcProcessMReleaseTest, ErrorNotKilled) {
5452
EXPECT_GE(child_pid, 0);
5553

5654
if (child_pid == 0) {
57-
// Child process: wait a bit then exit gracefully.
58-
LIBC_NAMESPACE::sleep_briefly();
59-
LIBC_NAMESPACE::exit(0);
55+
// pause the child process
56+
LIBC_NAMESPACE::raise(SIGSTOP);
6057
} else {
61-
// Give child process some time to start.
62-
LIBC_NAMESPACE::sleep_briefly();
6358
int pidfd = pidfd_open(child_pid, 0);
6459
EXPECT_GE(pidfd, 0);
6560

@@ -72,3 +67,4 @@ TEST(LlvmLibcProcessMReleaseTest, ErrorNotKilled) {
7267
TEST(LlvmLibcProcessMReleaseTest, ErrorNonExistingPidfd) {
7368
EXPECT_THAT(LIBC_NAMESPACE::process_mrelease(-1, 0), Fails(EBADF));
7469
}
70+
#endif

0 commit comments

Comments
 (0)