Skip to content

Commit d2b482b

Browse files
authored
[libc] (reland #117503) Implement process_mrelease (#117851)
This PR implements process_mrelease. A previous PR was merged #117503, but failed on merge due to an issue in the tests. Namely the failing tests were comparing against return type as opposed to errno. This is fixed in this PR.
1 parent 65339e4 commit d2b482b

File tree

12 files changed

+188
-1
lines changed

12 files changed

+188
-1
lines changed

libc/config/linux/aarch64/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ set(TARGET_LIBC_ENTRYPOINTS
252252
libc.src.sys.mman.munlockall
253253
libc.src.sys.mman.munmap
254254
libc.src.sys.mman.remap_file_pages
255+
libc.src.sys.mman.process_mrelease
255256
libc.src.sys.mman.posix_madvise
256257
libc.src.sys.mman.shm_open
257258
libc.src.sys.mman.shm_unlink

libc/config/linux/riscv/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ set(TARGET_LIBC_ENTRYPOINTS
251251
libc.src.sys.mman.munmap
252252
libc.src.sys.mman.remap_file_pages
253253
libc.src.sys.mman.posix_madvise
254+
libc.src.sys.mman.process_mrelease
254255
libc.src.sys.mman.shm_open
255256
libc.src.sys.mman.shm_unlink
256257

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ set(TARGET_LIBC_ENTRYPOINTS
252252
libc.src.sys.mman.munmap
253253
libc.src.sys.mman.remap_file_pages
254254
libc.src.sys.mman.posix_madvise
255+
libc.src.sys.mman.process_mrelease
255256
libc.src.sys.mman.shm_open
256257
libc.src.sys.mman.shm_unlink
257258

libc/include/sys/syscall.h.def

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2349,5 +2349,12 @@
23492349
#define SYS_writev __NR_writev
23502350
#endif
23512351

2352+
#ifdef __NR_process_mrelease
2353+
#define SYS_process_mrelease __NR_process_mrelease
2354+
#endif
2355+
2356+
#ifdef __NR_pidfd_open
2357+
#define SYS_pidfd_open __NR_pidfd_open
2358+
#endif
23522359

23532360
#endif // LLVM_LIBC_SYS_SYSCALL_H

libc/newhdrgen/yaml/sys/mman.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,10 @@ functions:
132132
return_type: int
133133
arguments:
134134
- type: const char *
135+
- name: process_mrelease
136+
standards:
137+
- Linux
138+
return_type: int
139+
arguments:
140+
- type: int
141+
- type: unsigned int

libc/spec/linux.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@ def Linux : StandardSpec<"Linux"> {
112112
ArgSpec<IntType>,
113113
ArgSpec<SizeTType>,
114114
ArgSpec<IntType>,
115+
FunctionSpec<
116+
"process_mrelease",
117+
RetValSpec<IntType>,
118+
[
119+
ArgSpec<IntType>,
120+
ArgSpec<UnsignedIntType>
115121
]
116122
>,
117123
FunctionSpec<

libc/src/sys/mman/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,9 @@ add_entrypoint_object(
113113
DEPENDS
114114
.${LIBC_TARGET_OS}.mremap
115115
)
116+
117+
add_entrypoint_object(
118+
process_mrelease
119+
ALIAS
120+
DEPENDS
121+
.${LIBC_TARGET_OS}.process_mrelease)

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ add_entrypoint_object(
3636
libc.src.__support.OSUtil.osutil
3737
libc.src.errno.errno
3838
)
39-
4039
add_entrypoint_object(
4140
munmap
4241
SRCS
@@ -214,3 +213,14 @@ add_entrypoint_object(
214213
libc.src.unistd.unlink
215214
.shm_common
216215
)
216+
217+
add_entrypoint_object(
218+
process_mrelease
219+
SRCS
220+
process_mrelease.cpp
221+
HDRS
222+
../process_mrelease.h
223+
DEPENDS
224+
libc.include.sys_syscall
225+
libc.src.__support.OSUtil.osutil
226+
libc.src.errno.errno)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//===---------- Linux implementation of the mrelease function -----------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "src/sys/mman/process_mrelease.h"
10+
11+
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
12+
#include "src/__support/common.h"
13+
14+
#include "src/__support/macros/config.h"
15+
#include "src/errno/libc_errno.h"
16+
#include <linux/param.h> // For EXEC_PAGESIZE.
17+
#include <sys/syscall.h> // For syscall numbers.
18+
19+
namespace LIBC_NAMESPACE_DECL {
20+
21+
LLVM_LIBC_FUNCTION(int, process_mrelease, (int pidfd, unsigned int flags)) {
22+
long ret =
23+
LIBC_NAMESPACE::syscall_impl<int>(SYS_process_mrelease, pidfd, flags);
24+
25+
if (ret < 0) {
26+
libc_errno = static_cast<int>(-ret);
27+
return -1;
28+
}
29+
30+
return 0;
31+
}
32+
33+
} // namespace LIBC_NAMESPACE_DECL

libc/src/sys/mman/process_mrelease.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//===-- Implementation header for process_mrelease function -*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_LIBC_SRC_SYS_MMAN_PROCESS_MRELEASE_H
10+
#define LLVM_LIBC_SRC_SYS_MMAN_PROCESS_MRELEASE_H
11+
12+
#include "src/__support/macros/config.h"
13+
#include <sys/mman.h> // For size_t and off_t
14+
15+
namespace LIBC_NAMESPACE_DECL {
16+
17+
int process_mrelease(int pidfd, unsigned int flags);
18+
19+
} // namespace LIBC_NAMESPACE_DECL
20+
21+
#endif // LLVM_LIBC_SRC_SYS_MMAN_PROCESS_MRELEASE_H

0 commit comments

Comments
 (0)