Skip to content

[libc] skip test and return ENOSYS when processm_release unavailable #117951

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions libc/src/sys/mman/linux/process_mrelease.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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
1 change: 1 addition & 0 deletions libc/test/src/sys/mman/linux/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 7 additions & 11 deletions libc/test/src/sys/mman/linux/process_mrelease_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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) {
Expand All @@ -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);

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

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