[libc-commits] [libc] Process mrelease (PR #119147)
Omar Hossam via libc-commits
libc-commits at lists.llvm.org
Sun Dec 8 12:29:53 PST 2024
https://github.com/moar55 created https://github.com/llvm/llvm-project/pull/119147
This PR implements process_mrelease syscall wrapper.
>From 4d1732071c0bc5e0d3ad5695c442ba979ff34b16 Mon Sep 17 00:00:00 2001
From: moar55 <moar.ahmed at gmail.com>
Date: Tue, 5 Nov 2024 20:57:03 +0100
Subject: [PATCH 1/9] #110124: Add support for process_mrelease syscall
---
libc/config/linux/aarch64/entrypoints.txt | 1 +
libc/config/linux/riscv/entrypoints.txt | 1 +
libc/config/linux/x86_64/entrypoints.txt | 1 +
libc/hdrgen/yaml/sys/mman.yaml | 7 +
libc/include/sys/syscall.h.def | 7 +
libc/spec/linux.td | 334 ++++++++++++++++++
libc/src/sys/mman/CMakeLists.txt | 147 ++------
libc/src/sys/mman/linux/CMakeLists.txt | 215 ++++++-----
libc/src/sys/mman/linux/process_mrelease.cpp | 33 ++
libc/src/sys/mman/process_mrelease.h | 22 ++
libc/test/src/sys/mman/linux/CMakeLists.txt | 235 ++++++------
.../sys/mman/linux/process_mrelease_test.cpp | 74 ++++
12 files changed, 748 insertions(+), 329 deletions(-)
create mode 100644 libc/spec/linux.td
create mode 100644 libc/src/sys/mman/linux/process_mrelease.cpp
create mode 100644 libc/src/sys/mman/process_mrelease.h
create mode 100644 libc/test/src/sys/mman/linux/process_mrelease_test.cpp
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index effa5b12d87ac4a..aa0b8ba0490e98b 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -252,6 +252,7 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.sys.mman.munlockall
libc.src.sys.mman.munmap
libc.src.sys.mman.remap_file_pages
+ libc.src.sys.mman.process_mrelease
libc.src.sys.mman.posix_madvise
libc.src.sys.mman.shm_open
libc.src.sys.mman.shm_unlink
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index 5a48baf104159f4..7bdb7f4d1ec61b6 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -251,6 +251,7 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.sys.mman.munmap
libc.src.sys.mman.remap_file_pages
libc.src.sys.mman.posix_madvise
+ libc.src.sys.mman.process_mrelease
libc.src.sys.mman.shm_open
libc.src.sys.mman.shm_unlink
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index 1bedc25a9d0291f..5e9cc71279ab16d 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -252,6 +252,7 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.sys.mman.munmap
libc.src.sys.mman.remap_file_pages
libc.src.sys.mman.posix_madvise
+ libc.src.sys.mman.process_mrelease
libc.src.sys.mman.shm_open
libc.src.sys.mman.shm_unlink
diff --git a/libc/hdrgen/yaml/sys/mman.yaml b/libc/hdrgen/yaml/sys/mman.yaml
index 962ca3591917f74..dd53eb60d1ec574 100644
--- a/libc/hdrgen/yaml/sys/mman.yaml
+++ b/libc/hdrgen/yaml/sys/mman.yaml
@@ -132,3 +132,10 @@ functions:
return_type: int
arguments:
- type: const char *
+ - name: process_mrelease
+ standards:
+ - Linux
+ return_type: int
+ arguments:
+ - type: int
+ - type: unsigned int
diff --git a/libc/include/sys/syscall.h.def b/libc/include/sys/syscall.h.def
index 03c19eb0885ed6a..11758ea8336ddf6 100644
--- a/libc/include/sys/syscall.h.def
+++ b/libc/include/sys/syscall.h.def
@@ -2349,5 +2349,12 @@
#define SYS_writev __NR_writev
#endif
+#ifdef __NR_process_mrelease
+#define SYS_process_mrelease __NR_process_mrelease
+#endif
+
+#ifdef __NR_pidfd_open
+#define SYS_pidfd_open __NR_pidfd_open
+#endif
#endif // LLVM_LIBC_SYS_SYSCALL_H
diff --git a/libc/spec/linux.td b/libc/spec/linux.td
new file mode 100644
index 000000000000000..99e0949a592dfa8
--- /dev/null
+++ b/libc/spec/linux.td
@@ -0,0 +1,334 @@
+def StructEpollEvent : NamedType<"struct epoll_event">;
+def StructEpollEventPtr : PtrType<StructEpollEvent>;
+
+def StructEpollData : NamedType<"struct epoll_data">;
+
+def Linux : StandardSpec<"Linux"> {
+ HeaderSpec Errno = HeaderSpec<
+ "errno.h",
+ [
+ Macro<"ENOMEDIUM">,
+ Macro<"ENOTBLK">,
+ Macro<"EMEDIUMTYPE">,
+ Macro<"EBADSLT">,
+ Macro<"ECHRNG">,
+ Macro<"ERFKILL">,
+ Macro<"EUSERS">,
+ Macro<"EBADR">,
+ Macro<"EL3HLT">,
+ Macro<"ENOTUNIQ">,
+ Macro<"EXFULL">,
+ Macro<"EHOSTDOWN">,
+ Macro<"EL3RST">,
+ Macro<"ENOPKG">,
+ Macro<"ENOCSI">,
+ Macro<"EUNATCH">,
+ Macro<"EREMCHG">,
+ Macro<"ETOOMANYREFS">,
+ Macro<"EL2HLT">,
+ Macro<"EBADFD">,
+ Macro<"EREMOTEIO">,
+ Macro<"ENAVAIL">,
+ Macro<"ELIBEXEC">,
+ Macro<"ESHUTDOWN">,
+ Macro<"ENOKEY">,
+ Macro<"ESTRPIPE">,
+ Macro<"EKEYREJECTED">,
+ Macro<"ESRMNT">,
+ Macro<"EKEYREVOKED">,
+ Macro<"EBADE">,
+ Macro<"ELIBBAD">,
+ Macro<"EISNAM">,
+ Macro<"EBFONT">,
+ Macro<"EPFNOSUPPORT">,
+ Macro<"EREMOTE">,
+ Macro<"EDEADLOCK">,
+ Macro<"ENONET">,
+ Macro<"EDOTDOT">,
+ Macro<"EKEYEXPIRED">,
+ Macro<"ELIBSCN">,
+ Macro<"ERESTART">,
+ Macro<"EBADRQC">,
+ Macro<"EUCLEAN">,
+ Macro<"ENOANO">,
+ Macro<"ELIBACC">,
+ Macro<"EHWPOISON">,
+ Macro<"ELIBMAX">,
+ Macro<"ESOCKTNOSUPPORT">,
+ Macro<"ENOTNAM">,
+ Macro<"ELNRNG">,
+ Macro<"EL2NSYNC">,
+ Macro<"EADV">,
+ Macro<"ECOMM">,
+ ]
+ >;
+
+ HeaderSpec Sched = HeaderSpec<
+ "sched.h",
+ [
+ Macro<"SCHED_OTHER">,
+ Macro<"SCHED_FIFO">,
+ Macro<"SCHED_RR">,
+ Macro<"SCHED_BATCH">,
+ Macro<"SCHED_ISO">,
+ Macro<"SCHED_IDLE">,
+ Macro<"SCHED_DEADLINE">,
+ ],
+ [], // Types
+ [], // Enumerations
+ [] // Functions
+ >;
+
+ HeaderSpec SysMMan = HeaderSpec<
+ "sys/mman.h",
+ [Macro<"MAP_ANONYMOUS">],
+ [], // Types
+ [], // Enumerations
+ [
+ FunctionSpec<
+ "mincore",
+ RetValSpec<IntType>,
+ [
+ ArgSpec<VoidPtr>,
+ ArgSpec<SizeTType>,
+ ArgSpec<UnsignedCharPtr>,
+ ]
+ >,
+ FunctionSpec<
+ "mlock2",
+ RetValSpec<IntType>,
+ [
+ ArgSpec<VoidPtr>,
+ ArgSpec<SizeTType>,
+ ArgSpec<UnsignedIntType>,
+ ]
+ >,
+ FunctionSpec<
+ "remap_file_pages",
+ RetValSpec<IntType>,
+ [
+ ArgSpec<VoidPtr>,
+ ArgSpec<SizeTType>,
+ ArgSpec<IntType>,
+ ArgSpec<SizeTType>,
+ ArgSpec<IntType>,
+ FunctionSpec<
+ "process_mrelease",
+ RetValSpec<IntType>,
+ [
+ ArgSpec<IntType>,
+ ArgSpec<UnsignedIntType>
+ ]
+ >,
+ FunctionSpec<
+ "mremap",
+ RetValSpec<VoidPtr>,
+ [
+ ArgSpec<VoidPtr>,
+ ArgSpec<SizeTType>,
+ ArgSpec<SizeTType>,
+ ArgSpec<IntType>,
+ ArgSpec<VarArgType>,
+ ]
+ >,
+ ] // Functions
+ >;
+
+
+ HeaderSpec SysPrctl = HeaderSpec<
+ "sys/prctl.h",
+ [], // Macros
+ [], // Types
+ [], // Enumerations
+ [
+ FunctionSpec<
+ "prctl",
+ RetValSpec<IntType>,
+ [
+ ArgSpec<IntType>,
+ ArgSpec<UnsignedLongType>,
+ ArgSpec<UnsignedLongType>,
+ ArgSpec<UnsignedLongType>,
+ ArgSpec<UnsignedLongType>,
+ ]
+ >,
+ ] // Functions
+ >;
+
+ HeaderSpec SysRandom = HeaderSpec<
+ "sys/random.h",
+ [
+ Macro<"GRND_RANDOM">,
+ Macro<"GRND_NONBLOCK">,
+ Macro<"GRND_INSECURE">,
+ ],
+ [SizeTType, SSizeTType], // Types
+ [], // Enumerations
+ [
+ FunctionSpec<
+ "getrandom",
+ RetValSpec<SSizeTType>,
+ [
+ ArgSpec<VoidPtr>,
+ ArgSpec<SizeTType>,
+ ArgSpec<UnsignedIntType>
+ ]
+ >,
+ ]
+ >;
+
+ HeaderSpec SysTime = HeaderSpec<
+ "sys/time.h",
+ [
+ Macro<"timeradd">,
+ Macro<"timersub">,
+ Macro<"timerclear">,
+ Macro<"timerisset">,
+ Macro<"timercmp">,
+ ],
+ [StructTimevalType], // Types
+ [], // Enumerations
+ [] // Functions
+ >;
+
+
+ HeaderSpec SysEpoll = HeaderSpec<
+ "sys/epoll.h",
+ [], // Macros
+ [
+ StructEpollEvent,
+ StructEpollData,
+ SigSetType,
+ StructTimeSpec,
+ ], // Types
+ [], // Enumerations
+ [
+ FunctionSpec<
+ "epoll_create",
+ RetValSpec<IntType>,
+ [
+ ArgSpec<IntType>
+ ]
+ >,
+ FunctionSpec<
+ "epoll_create1",
+ RetValSpec<IntType>,
+ [
+ ArgSpec<IntType>
+ ]
+ >,
+ FunctionSpec<
+ "epoll_ctl",
+ RetValSpec<IntType>,
+ [
+ ArgSpec<IntType>,
+ ArgSpec<IntType>,
+ ArgSpec<IntType>,
+ ArgSpec<StructEpollEventPtr>
+ ]
+ >,
+ FunctionSpec<
+ "epoll_wait",
+ RetValSpec<IntType>,
+ [
+ ArgSpec<IntType>,
+ ArgSpec<StructEpollEventPtr>,
+ ArgSpec<IntType>,
+ ArgSpec<IntType>
+ ]
+ >,
+ FunctionSpec<
+ "epoll_pwait",
+ RetValSpec<IntType>,
+ [
+ ArgSpec<IntType>,
+ ArgSpec<StructEpollEventPtr>,
+ ArgSpec<IntType>,
+ ArgSpec<IntType>,
+ ArgSpec<ConstSigSetPtrType>
+ ]
+ >,
+ FunctionSpec<
+ "epoll_pwait2",
+ RetValSpec<IntType>,
+ [
+ ArgSpec<IntType>,
+ ArgSpec<StructEpollEventPtr>,
+ ArgSpec<IntType>,
+ ArgSpec<ConstStructTimeSpecPtr>,
+ ArgSpec<ConstSigSetPtrType>
+ ]
+ >,
+ ] // Functions
+ >;
+
+ HeaderSpec Signal = HeaderSpec<
+ "signal.h",
+ [
+ Macro<"NSIG">,
+
+ Macro<"SIGHUP">,
+ Macro<"SIGINT">,
+ Macro<"SIGQUIT">,
+ Macro<"SIGILL">,
+ Macro<"SIGTRAP">,
+ Macro<"SIGABRT">,
+ Macro<"SIGIOT">,
+ Macro<"SIGBUS">,
+ Macro<"SIGFPE">,
+ Macro<"SIGKILL">,
+ Macro<"SIGUSR1">,
+ Macro<"SIGSEGV">,
+ Macro<"SIGUSR2">,
+ Macro<"SIGPIPE">,
+ Macro<"SIGALRM">,
+ Macro<"SIGTERM">,
+ Macro<"SIGSTKFLT">,
+ Macro<"SIGCHLD">,
+ Macro<"SIGCONT">,
+ Macro<"SIGSTOP">,
+ Macro<"SIGTSTP">,
+ Macro<"SIGTTIN">,
+ Macro<"SIGTTOU">,
+ Macro<"SIGURG">,
+ Macro<"SIGXCPU">,
+ Macro<"SIGXFSZ">,
+ Macro<"SIGVTALRM">,
+ Macro<"SIGPROF">,
+ Macro<"SIGWINCH">,
+ Macro<"SIGIO">,
+ Macro<"SIGPOLL">,
+ Macro<"SIGPWR">,
+ Macro<"SIGSYS">,
+ Macro<"SIGUNUSED">,
+ ]
+ >;
+
+
+ HeaderSpec UniStd = HeaderSpec<
+ "unistd.h",
+ [], // Macros
+ [],
+ [], // Enumerations
+ [
+ FunctionSpec<
+ "pipe2",
+ RetValSpec<IntType>,
+ [ArgSpec<IntPtr>, ArgSpec<IntType>] //TODO: make this int[2]
+ >,
+ ],
+ []
+ >;
+
+
+ let Headers = [
+ Errno,
+ SysEpoll,
+ SysMMan,
+ SysPrctl,
+ SysRandom,
+ SysTime,
+ Signal,
+ UniStd,
+ ];
+}
diff --git a/libc/src/sys/mman/CMakeLists.txt b/libc/src/sys/mman/CMakeLists.txt
index 4d4c2ad376050ec..d5059d615abc336 100644
--- a/libc/src/sys/mman/CMakeLists.txt
+++ b/libc/src/sys/mman/CMakeLists.txt
@@ -2,114 +2,39 @@ if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
endif()
-add_entrypoint_object(
- madvise
- ALIAS
- DEPENDS
- .${LIBC_TARGET_OS}.madvise
-)
-
-add_entrypoint_object(
- mmap
- ALIAS
- DEPENDS
- .${LIBC_TARGET_OS}.mmap
-)
-
-add_entrypoint_object(
- munmap
- ALIAS
- DEPENDS
- .${LIBC_TARGET_OS}.munmap
-)
-
-add_entrypoint_object(
- mprotect
- ALIAS
- DEPENDS
- .${LIBC_TARGET_OS}.mprotect
-)
-
-add_entrypoint_object(
- posix_madvise
- ALIAS
- DEPENDS
- .${LIBC_TARGET_OS}.posix_madvise
-)
-
-add_entrypoint_object(
- mincore
- ALIAS
- DEPENDS
- .${LIBC_TARGET_OS}.mincore
-)
-
-add_entrypoint_object(
- mlock
- ALIAS
- DEPENDS
- .${LIBC_TARGET_OS}.mlock
-)
-
-add_entrypoint_object(
- mlock2
- ALIAS
- DEPENDS
- .${LIBC_TARGET_OS}.mlock2
-)
-
-add_entrypoint_object(
- munlock
- ALIAS
- DEPENDS
- .${LIBC_TARGET_OS}.munlock
-)
-
-add_entrypoint_object(
- mlockall
- ALIAS
- DEPENDS
- .${LIBC_TARGET_OS}.mlockall
-)
-
-add_entrypoint_object(
- munlockall
- ALIAS
- DEPENDS
- .${LIBC_TARGET_OS}.munlockall
-)
-
-add_entrypoint_object(
- msync
- ALIAS
- DEPENDS
- .${LIBC_TARGET_OS}.msync
-)
-
-add_entrypoint_object(
- remap_file_pages
- ALIAS
- DEPENDS
- .${LIBC_TARGET_OS}.remap_file_pages
-)
-
-add_entrypoint_object(
- shm_open
- ALIAS
- DEPENDS
- .${LIBC_TARGET_OS}.shm_open
-)
-
-add_entrypoint_object(
- shm_unlink
- ALIAS
- DEPENDS
- .${LIBC_TARGET_OS}.shm_unlink
-)
-
-add_entrypoint_object(
- mremap
- ALIAS
- DEPENDS
- .${LIBC_TARGET_OS}.mremap
-)
+add_entrypoint_object(madvise ALIAS DEPENDS .${LIBC_TARGET_OS}.madvise)
+
+add_entrypoint_object(mmap ALIAS DEPENDS .${LIBC_TARGET_OS}.mmap)
+
+add_entrypoint_object(munmap ALIAS DEPENDS .${LIBC_TARGET_OS}.munmap)
+
+add_entrypoint_object(mprotect ALIAS DEPENDS .${LIBC_TARGET_OS}.mprotect)
+
+add_entrypoint_object(posix_madvise ALIAS DEPENDS
+ .${LIBC_TARGET_OS}.posix_madvise)
+
+add_entrypoint_object(mincore ALIAS DEPENDS .${LIBC_TARGET_OS}.mincore)
+
+add_entrypoint_object(mlock ALIAS DEPENDS .${LIBC_TARGET_OS}.mlock)
+
+add_entrypoint_object(mlock2 ALIAS DEPENDS .${LIBC_TARGET_OS}.mlock2)
+
+add_entrypoint_object(munlock ALIAS DEPENDS .${LIBC_TARGET_OS}.munlock)
+
+add_entrypoint_object(mlockall ALIAS DEPENDS .${LIBC_TARGET_OS}.mlockall)
+
+add_entrypoint_object(munlockall ALIAS DEPENDS .${LIBC_TARGET_OS}.munlockall)
+
+add_entrypoint_object(msync ALIAS DEPENDS .${LIBC_TARGET_OS}.msync)
+
+add_entrypoint_object(remap_file_pages ALIAS DEPENDS
+ .${LIBC_TARGET_OS}.remap_file_pages)
+
+add_entrypoint_object(shm_open ALIAS DEPENDS .${LIBC_TARGET_OS}.shm_open)
+
+add_entrypoint_object(shm_unlink ALIAS DEPENDS .${LIBC_TARGET_OS}.shm_unlink)
+
+add_entrypoint_object(mremap ALIAS DEPENDS .${LIBC_TARGET_OS}.mremap)
+
+add_entrypoint_object(process_mrelease ALIAS DEPENDS
+ .${LIBC_TARGET_OS}.process_mrelease)
diff --git a/libc/src/sys/mman/linux/CMakeLists.txt b/libc/src/sys/mman/linux/CMakeLists.txt
index 89a0ad1527a0650..7fb3ba8682e01b4 100644
--- a/libc/src/sys/mman/linux/CMakeLists.txt
+++ b/libc/src/sys/mman/linux/CMakeLists.txt
@@ -1,28 +1,26 @@
add_entrypoint_object(
madvise
SRCS
- madvise.cpp
+ madvise.cpp
HDRS
- ../madvise.h
+ ../madvise.h
DEPENDS
- libc.include.sys_mman
- libc.include.sys_syscall
- libc.src.__support.OSUtil.osutil
- libc.src.errno.errno
-)
+ libc.include.sys_mman
+ libc.include.sys_syscall
+ libc.src.__support.OSUtil.osutil
+ libc.src.errno.errno)
add_entrypoint_object(
mmap
SRCS
- mmap.cpp
+ mmap.cpp
HDRS
- ../mmap.h
+ ../mmap.h
DEPENDS
- libc.include.sys_mman
- libc.include.sys_syscall
- libc.src.__support.OSUtil.osutil
- libc.src.errno.errno
-)
+ libc.include.sys_mman
+ libc.include.sys_syscall
+ libc.src.__support.OSUtil.osutil
+ libc.src.errno.errno)
add_entrypoint_object(
mremap
@@ -40,177 +38,176 @@ add_entrypoint_object(
add_entrypoint_object(
munmap
SRCS
- munmap.cpp
+ munmap.cpp
HDRS
- ../munmap.h
+ ../munmap.h
DEPENDS
- libc.include.sys_mman
- libc.include.sys_syscall
- libc.src.__support.OSUtil.osutil
- libc.src.errno.errno
-)
+ libc.include.sys_mman
+ libc.include.sys_syscall
+ libc.src.__support.OSUtil.osutil
+ libc.src.errno.errno)
add_entrypoint_object(
mprotect
SRCS
- mprotect.cpp
+ mprotect.cpp
HDRS
- ../mprotect.h
+ ../mprotect.h
DEPENDS
- libc.include.sys_mman
- libc.include.sys_syscall
- libc.src.__support.OSUtil.osutil
- libc.src.errno.errno
-)
+ libc.include.sys_mman
+ libc.include.sys_syscall
+ libc.src.__support.OSUtil.osutil
+ libc.src.errno.errno)
add_entrypoint_object(
posix_madvise
SRCS
- posix_madvise.cpp
+ posix_madvise.cpp
HDRS
- ../posix_madvise.h
+ ../posix_madvise.h
DEPENDS
- libc.include.sys_mman
- libc.include.sys_syscall
- libc.src.__support.OSUtil.osutil
-)
+ libc.include.sys_mman
+ libc.include.sys_syscall
+ libc.src.__support.OSUtil.osutil)
add_entrypoint_object(
mincore
SRCS
- mincore.cpp
+ mincore.cpp
HDRS
- ../mincore.h
+ ../mincore.h
DEPENDS
- libc.include.sys_mman
- libc.include.sys_syscall
- libc.src.__support.OSUtil.osutil
- libc.src.errno.errno
-)
+ libc.include.sys_mman
+ libc.include.sys_syscall
+ libc.src.__support.OSUtil.osutil
+ libc.src.errno.errno)
add_entrypoint_object(
mlock
SRCS
- mlock.cpp
+ mlock.cpp
HDRS
- ../mlock.h
+ ../mlock.h
DEPENDS
- libc.include.sys_mman
- libc.include.sys_syscall
- libc.src.__support.OSUtil.osutil
- libc.src.errno.errno
-)
+ libc.include.sys_mman
+ libc.include.sys_syscall
+ libc.src.__support.OSUtil.osutil
+ libc.src.errno.errno)
add_entrypoint_object(
mlock2
SRCS
- mlock2.cpp
+ mlock2.cpp
HDRS
- ../mlock2.h
+ ../mlock2.h
DEPENDS
- libc.include.sys_mman
- libc.include.sys_syscall
- libc.src.__support.OSUtil.osutil
- libc.src.errno.errno
-)
+ libc.include.sys_mman
+ libc.include.sys_syscall
+ libc.src.__support.OSUtil.osutil
+ libc.src.errno.errno)
add_entrypoint_object(
munlock
SRCS
- munlock.cpp
+ munlock.cpp
HDRS
- ../munlock.h
+ ../munlock.h
DEPENDS
- libc.include.sys_mman
- libc.include.sys_syscall
- libc.src.__support.OSUtil.osutil
- libc.src.errno.errno
-)
+ libc.include.sys_mman
+ libc.include.sys_syscall
+ libc.src.__support.OSUtil.osutil
+ libc.src.errno.errno)
add_entrypoint_object(
mlockall
SRCS
- mlockall.cpp
+ mlockall.cpp
HDRS
- ../mlockall.h
+ ../mlockall.h
DEPENDS
- libc.include.sys_mman
- libc.include.sys_syscall
- libc.src.__support.OSUtil.osutil
- libc.src.errno.errno
-)
+ libc.include.sys_mman
+ libc.include.sys_syscall
+ libc.src.__support.OSUtil.osutil
+ libc.src.errno.errno)
add_entrypoint_object(
munlockall
SRCS
- munlockall.cpp
+ munlockall.cpp
HDRS
- ../munlockall.h
+ ../munlockall.h
DEPENDS
- libc.include.sys_mman
- libc.include.sys_syscall
- libc.src.__support.OSUtil.osutil
- libc.src.errno.errno
-)
+ libc.include.sys_mman
+ libc.include.sys_syscall
+ libc.src.__support.OSUtil.osutil
+ libc.src.errno.errno)
add_entrypoint_object(
msync
SRCS
- msync.cpp
+ msync.cpp
HDRS
- ../msync.h
+ ../msync.h
DEPENDS
- libc.include.sys_mman
- libc.include.sys_syscall
- libc.src.__support.OSUtil.osutil
- libc.src.errno.errno
-)
+ libc.include.sys_mman
+ libc.include.sys_syscall
+ libc.src.__support.OSUtil.osutil
+ libc.src.errno.errno)
add_entrypoint_object(
remap_file_pages
SRCS
- remap_file_pages.cpp
+ remap_file_pages.cpp
HDRS
- ../remap_file_pages.h
+ ../remap_file_pages.h
DEPENDS
- libc.include.sys_mman
- libc.include.sys_syscall
- libc.src.__support.OSUtil.osutil
- libc.src.errno.errno
-)
+ libc.include.sys_mman
+ libc.include.sys_syscall
+ libc.src.__support.OSUtil.osutil
+ libc.src.errno.errno)
add_header_library(
shm_common
HDRS
- shm_common.h
+ shm_common.h
DEPENDS
- libc.src.__support.CPP.array
- libc.src.__support.CPP.string_view
- libc.src.__support.CPP.optional
- libc.src.__support.common
- libc.src.errno.errno
- libc.src.string.memory_utils.inline_memcpy
-)
+ libc.src.__support.CPP.array
+ libc.src.__support.CPP.string_view
+ libc.src.__support.CPP.optional
+ libc.src.__support.common
+ libc.src.errno.errno
+ libc.src.string.memory_utils.inline_memcpy)
add_entrypoint_object(
shm_open
SRCS
- shm_open.cpp
+ shm_open.cpp
HDRS
- ../shm_open.h
+ ../shm_open.h
DEPENDS
- libc.src.fcntl.open
- libc.hdr.types.mode_t
- .shm_common
-)
+ libc.src.fcntl.open
+ libc.hdr.types.mode_t
+ .shm_common)
add_entrypoint_object(
shm_unlink
SRCS
- shm_unlink.cpp
+ shm_unlink.cpp
HDRS
- ../shm_unlink.h
+ ../shm_unlink.h
DEPENDS
- libc.src.unistd.unlink
- .shm_common
-)
+ libc.src.unistd.unlink
+ .shm_common)
+
+add_entrypoint_object(
+ process_mrelease
+ SRCS
+ process_mrelease.cpp
+ HDRS
+ ../process_mrelease.h
+ DEPENDS
+ libc.include.signal
+ libc.src.signal.kill
+ libc.include.sys_syscall
+ libc.src.__support.OSUtil.osutil
+ libc.src.errno.errno)
diff --git a/libc/src/sys/mman/linux/process_mrelease.cpp b/libc/src/sys/mman/linux/process_mrelease.cpp
new file mode 100644
index 000000000000000..d71b1289c3e9283
--- /dev/null
+++ b/libc/src/sys/mman/linux/process_mrelease.cpp
@@ -0,0 +1,33 @@
+//===---------- Linux implementation of the mrelease function -----------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/sys/mman/process_mrelease.h"
+
+#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
+#include "src/__support/common.h"
+
+#include "src/__support/macros/config.h"
+#include "src/errno/libc_errno.h"
+#include <linux/param.h> // For EXEC_PAGESIZE.
+#include <sys/syscall.h> // For syscall numbers.
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(int, process_mrelease, (int pidfd, unsigned int flags)) {
+ long ret =
+ LIBC_NAMESPACE::syscall_impl<int>(SYS_process_mrelease, pidfd, flags);
+
+ if (ret < 0) {
+ libc_errno = static_cast<int>(-ret);
+ return libc_errno;
+ }
+
+ return 0;
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/sys/mman/process_mrelease.h b/libc/src/sys/mman/process_mrelease.h
new file mode 100644
index 000000000000000..13a9ba57eae19b4
--- /dev/null
+++ b/libc/src/sys/mman/process_mrelease.h
@@ -0,0 +1,22 @@
+//===-- Implementation header for process_mrelease function -----------------*-
+// C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_SYS_MMAN_PROCESS_MRELEASE_H
+#define LLVM_LIBC_SRC_SYS_MMAN_PROCESS_MRELEASE_H
+
+#include "src/__support/macros/config.h"
+#include <sys/mman.h> // For size_t and off_t
+
+namespace LIBC_NAMESPACE_DECL {
+
+int process_mrelease(int pidfd, unsigned int flags);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_SYS_MMAN_PROCESS_MRELEASE_H
diff --git a/libc/test/src/sys/mman/linux/CMakeLists.txt b/libc/test/src/sys/mman/linux/CMakeLists.txt
index 44ed11aadfe8b74..16d83ea42743745 100644
--- a/libc/test/src/sys/mman/linux/CMakeLists.txt
+++ b/libc/test/src/sys/mman/linux/CMakeLists.txt
@@ -3,16 +3,15 @@ add_custom_target(libc_sys_mman_unittests)
add_libc_unittest(
mmap_test
SUITE
- libc_sys_mman_unittests
+ libc_sys_mman_unittests
SRCS
- mmap_test.cpp
+ mmap_test.cpp
DEPENDS
- libc.include.sys_mman
- libc.src.errno.errno
- libc.src.sys.mman.mmap
- libc.src.sys.mman.munmap
- libc.test.UnitTest.ErrnoSetterMatcher
-)
+ libc.include.sys_mman
+ libc.src.errno.errno
+ libc.src.sys.mman.mmap
+ libc.src.sys.mman.munmap
+ libc.test.UnitTest.ErrnoSetterMatcher)
add_libc_unittest(
mremap_test
@@ -30,154 +29,172 @@ add_libc_unittest(
)
if (NOT LLVM_USE_SANITIZER)
+if(NOT LLVM_USE_SANITIZER)
add_libc_unittest(
mprotect_test
SUITE
- libc_sys_mman_unittests
+ libc_sys_mman_unittests
SRCS
- mprotect_test.cpp
+ mprotect_test.cpp
DEPENDS
- libc.include.sys_mman
- libc.include.signal
- libc.src.errno.errno
- libc.src.sys.mman.mmap
- libc.src.sys.mman.munmap
- libc.src.sys.mman.mprotect
- libc.test.UnitTest.ErrnoSetterMatcher
- )
+ libc.include.sys_mman
+ libc.include.signal
+ libc.src.errno.errno
+ libc.src.sys.mman.mmap
+ libc.src.sys.mman.munmap
+ libc.src.sys.mman.mprotect
+ libc.test.UnitTest.ErrnoSetterMatcher)
endif()
add_libc_unittest(
madvise_test
SUITE
- libc_sys_mman_unittests
+ libc_sys_mman_unittests
SRCS
madvise_test.cpp
DEPENDS
- libc.include.sys_mman
- libc.src.errno.errno
- libc.src.sys.mman.mmap
- libc.src.sys.mman.munmap
- libc.src.sys.mman.madvise
- libc.test.UnitTest.ErrnoSetterMatcher
-)
-
+ libc.include.sys_mman
+ libc.src.errno.errno
+ libc.src.sys.mman.mmap
+ libc.src.sys.mman.munmap
+ libc.src.sys.mman.madvise
+ libc.test.UnitTest.ErrnoSetterMatcher)
add_libc_unittest(
posix_madvise_test
SUITE
- libc_sys_mman_unittests
+ libc_sys_mman_unittests
SRCS
posix_madvise_test.cpp
DEPENDS
- libc.include.sys_mman
- libc.src.errno.errno
- libc.src.sys.mman.mmap
- libc.src.sys.mman.munmap
- libc.src.sys.mman.posix_madvise
- libc.test.UnitTest.ErrnoSetterMatcher
-)
+ libc.include.sys_mman
+ libc.src.errno.errno
+ libc.src.sys.mman.mmap
+ libc.src.sys.mman.munmap
+ libc.src.sys.mman.posix_madvise
+ libc.test.UnitTest.ErrnoSetterMatcher)
add_libc_unittest(
mincore_test
SUITE
- libc_sys_mman_unittests
+ libc_sys_mman_unittests
SRCS
- mincore_test.cpp
+ mincore_test.cpp
DEPENDS
- libc.include.sys_mman
- libc.include.unistd
- libc.src.errno.errno
- libc.src.sys.mman.mmap
- libc.src.sys.mman.munmap
- libc.src.sys.mman.madvise
- libc.src.sys.mman.mincore
- libc.src.sys.mman.mlock
- libc.src.sys.mman.munlock
- libc.src.unistd.sysconf
- libc.test.UnitTest.ErrnoSetterMatcher
-)
+ libc.include.sys_mman
+ libc.include.unistd
+ libc.src.errno.errno
+ libc.src.sys.mman.mmap
+ libc.src.sys.mman.munmap
+ libc.src.sys.mman.madvise
+ libc.src.sys.mman.mincore
+ libc.src.sys.mman.mlock
+ libc.src.sys.mman.munlock
+ libc.src.unistd.sysconf
+ libc.test.UnitTest.ErrnoSetterMatcher)
add_libc_unittest(
mlock_test
SUITE
- libc_sys_mman_unittests
+ libc_sys_mman_unittests
SRCS
- mlock_test.cpp
+ mlock_test.cpp
DEPENDS
- libc.include.sys_mman
- libc.include.unistd
- libc.src.errno.errno
- libc.src.sys.mman.mmap
- libc.src.sys.mman.munmap
- libc.src.sys.mman.madvise
- libc.src.sys.mman.mincore
- libc.src.sys.mman.mlock
- libc.src.sys.mman.mlock2
- libc.src.sys.mman.munlock
- libc.src.sys.mman.mlockall
- libc.src.sys.mman.munlockall
- libc.src.sys.resource.getrlimit
- libc.src.__support.OSUtil.osutil
- libc.src.unistd.sysconf
- libc.test.UnitTest.ErrnoSetterMatcher
-)
+ libc.include.sys_mman
+ libc.include.unistd
+ libc.src.errno.errno
+ libc.src.sys.mman.mmap
+ libc.src.sys.mman.munmap
+ libc.src.sys.mman.madvise
+ libc.src.sys.mman.mincore
+ libc.src.sys.mman.mlock
+ libc.src.sys.mman.mlock2
+ libc.src.sys.mman.munlock
+ libc.src.sys.mman.mlockall
+ libc.src.sys.mman.munlockall
+ libc.src.sys.resource.getrlimit
+ libc.src.__support.OSUtil.osutil
+ libc.src.unistd.sysconf
+ libc.test.UnitTest.ErrnoSetterMatcher)
add_libc_unittest(
msync_test
SUITE
- libc_sys_mman_unittests
+ libc_sys_mman_unittests
SRCS
- msync_test.cpp
+ msync_test.cpp
DEPENDS
- libc.include.sys_mman
- libc.include.unistd
- libc.src.errno.errno
- libc.src.sys.mman.mmap
- libc.src.sys.mman.munmap
- libc.src.sys.mman.msync
- libc.src.sys.mman.mincore
- libc.src.sys.mman.mlock
- libc.src.sys.mman.munlock
- libc.src.unistd.sysconf
- libc.test.UnitTest.ErrnoSetterMatcher
-)
+ libc.include.sys_mman
+ libc.include.unistd
+ libc.src.errno.errno
+ libc.src.sys.mman.mmap
+ libc.src.sys.mman.munmap
+ libc.src.sys.mman.msync
+ libc.src.sys.mman.mincore
+ libc.src.sys.mman.mlock
+ libc.src.sys.mman.munlock
+ libc.src.unistd.sysconf
+ libc.test.UnitTest.ErrnoSetterMatcher)
add_libc_unittest(
remap_file_pages_test
SUITE
- libc_sys_mman_unittests
+ libc_sys_mman_unittests
SRCS
- remap_file_pages_test.cpp
+ remap_file_pages_test.cpp
DEPENDS
- libc.include.sys_mman
- libc.include.sys_stat
- libc.src.unistd.sysconf
- libc.test.UnitTest.ErrnoSetterMatcher
- libc.src.sys.mman.remap_file_pages
- libc.src.errno.errno
- libc.src.sys.mman.mmap
- libc.src.sys.mman.munmap
-)
+ libc.include.sys_mman
+ libc.include.sys_stat
+ libc.src.unistd.sysconf
+ libc.test.UnitTest.ErrnoSetterMatcher
+ libc.src.sys.mman.remap_file_pages
+ libc.src.errno.errno
+ libc.src.sys.mman.mmap
+ libc.src.sys.mman.munmap)
add_libc_unittest(
shm_test
SUITE
- libc_sys_mman_unittests
+ libc_sys_mman_unittests
SRCS
- shm_test.cpp
+ shm_test.cpp
DEPENDS
- libc.include.sys_mman
- libc.include.sys_syscall
- libc.src.errno.errno
- libc.src.fcntl.fcntl
- libc.src.sys.mman.shm_open
- libc.src.sys.mman.shm_unlink
- libc.src.sys.mman.mmap
- libc.src.sys.mman.munmap
- libc.src.unistd.ftruncate
- libc.src.unistd.close
- libc.src.__support.OSUtil.osutil
- libc.hdr.fcntl_macros
- libc.test.UnitTest.ErrnoSetterMatcher
-)
+ libc.include.sys_mman
+ libc.include.sys_syscall
+ libc.src.errno.errno
+ libc.src.fcntl.fcntl
+ libc.src.sys.mman.shm_open
+ libc.src.sys.mman.shm_unlink
+ libc.src.sys.mman.mmap
+ libc.src.sys.mman.munmap
+ libc.src.unistd.ftruncate
+ libc.src.unistd.close
+ libc.src.__support.OSUtil.osutil
+ libc.hdr.fcntl_macros
+ libc.test.UnitTest.ErrnoSetterMatcher)
+
+add_libc_unittest(
+ process_mrelease_test
+ SUITE
+ libc_sys_mman_unittests
+ SRCS
+ process_mrelease_test.cpp
+ DEPENDS
+ libc.include.sys_mman
+ libc.include.sys_syscall
+ libc.src.errno.errno
+ libc.src.fcntl.fcntl
+ libc.include.sys_wait
+ libc.src.sys.wait.waitpid
+ libc.src.sys.mman.process_mrelease
+ libc.src.sys.mman.mmap
+ libc.src.sys.mman.munmap
+ libc.src.unistd.ftruncate
+ libc.src.unistd.close
+ libc.src.__support.OSUtil.osutil
+ libc.test.UnitTest.ErrnoSetterMatcher)
+
+# add_libc_unittest( process_mrelease_test SUITE libc_sys_mman_unittests SRCS
+# process_mrelease_test.cpp DEPENDS libc.include.sys_mman
+# libc.include.sys_syscall libc.src.errno.errno
+# libc.src.sys.mman.process_mrelease 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
new file mode 100644
index 000000000000000..960e97b7aaddee7
--- /dev/null
+++ b/libc/test/src/sys/mman/linux/process_mrelease_test.cpp
@@ -0,0 +1,74 @@
+//===-- Unittests for process_mrelease
+//-------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+#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/stdlib/exit.h"
+#include "src/sys/mman/process_mrelease.h"
+#include "src/unistd/close.h"
+#include "src/unistd/fork.h"
+#include "test/UnitTest/LibcTest.h"
+
+#include <sys/syscall.h>
+
+int pidfd_open(pid_t pid, unsigned int flags) {
+ return LIBC_NAMESPACE::syscall_impl(SYS_pidfd_open, pid, flags);
+}
+
+TEST(LlvmLibcMProcessMReleaseTest, NoError) {
+ pid_t child_pid = LIBC_NAMESPACE::fork();
+
+ 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);
+ } 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);
+
+ // Send SIGKILL to child process
+ LIBC_NAMESPACE::kill(child_pid, SIGKILL);
+
+ EXPECT_EQ(LIBC_NAMESPACE::process_mrelease(pidfd, 0), 0);
+
+ LIBC_NAMESPACE::close(pidfd);
+ }
+}
+
+TEST(LlvmLibcMProcessMReleaseTest, ErrorNotKilled) {
+ pid_t child_pid = fork();
+
+ 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);
+ } else {
+ // Give child process some time to start.
+ LIBC_NAMESPACE::sleep_briefly();
+ int pidfd = pidfd_open(child_pid, 0);
+ EXPECT_GE(pidfd, 0);
+
+ ASSERT_EQ(LIBC_NAMESPACE::process_mrelease(pidfd, 0), EINVAL);
+
+ LIBC_NAMESPACE::close(pidfd);
+ }
+}
+
+TEST(LlvmLibcMProcessMReleaseTest, ErrorNonExistingPidfd) {
+
+ ASSERT_EQ(LIBC_NAMESPACE::process_mrelease(12345, 0), EBADF);
+}
>From a8f8cf593aff9d7f4e8cec29e6999aa7f1451700 Mon Sep 17 00:00:00 2001
From: moar55 <moar.ahmed at gmail.com>
Date: Sun, 24 Nov 2024 19:58:32 +0100
Subject: [PATCH 2/9] reformat
---
libc/src/sys/mman/CMakeLists.txt | 152 ++++++++---
libc/src/sys/mman/linux/CMakeLists.txt | 217 ++++++++--------
libc/test/src/sys/mman/linux/CMakeLists.txt | 241 +++++++++---------
.../sys/mman/linux/process_mrelease_test.cpp | 4 +-
4 files changed, 352 insertions(+), 262 deletions(-)
diff --git a/libc/src/sys/mman/CMakeLists.txt b/libc/src/sys/mman/CMakeLists.txt
index d5059d615abc336..7d71f14ff8837f6 100644
--- a/libc/src/sys/mman/CMakeLists.txt
+++ b/libc/src/sys/mman/CMakeLists.txt
@@ -2,39 +2,119 @@ if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
endif()
-add_entrypoint_object(madvise ALIAS DEPENDS .${LIBC_TARGET_OS}.madvise)
-
-add_entrypoint_object(mmap ALIAS DEPENDS .${LIBC_TARGET_OS}.mmap)
-
-add_entrypoint_object(munmap ALIAS DEPENDS .${LIBC_TARGET_OS}.munmap)
-
-add_entrypoint_object(mprotect ALIAS DEPENDS .${LIBC_TARGET_OS}.mprotect)
-
-add_entrypoint_object(posix_madvise ALIAS DEPENDS
- .${LIBC_TARGET_OS}.posix_madvise)
-
-add_entrypoint_object(mincore ALIAS DEPENDS .${LIBC_TARGET_OS}.mincore)
-
-add_entrypoint_object(mlock ALIAS DEPENDS .${LIBC_TARGET_OS}.mlock)
-
-add_entrypoint_object(mlock2 ALIAS DEPENDS .${LIBC_TARGET_OS}.mlock2)
-
-add_entrypoint_object(munlock ALIAS DEPENDS .${LIBC_TARGET_OS}.munlock)
-
-add_entrypoint_object(mlockall ALIAS DEPENDS .${LIBC_TARGET_OS}.mlockall)
-
-add_entrypoint_object(munlockall ALIAS DEPENDS .${LIBC_TARGET_OS}.munlockall)
-
-add_entrypoint_object(msync ALIAS DEPENDS .${LIBC_TARGET_OS}.msync)
-
-add_entrypoint_object(remap_file_pages ALIAS DEPENDS
- .${LIBC_TARGET_OS}.remap_file_pages)
-
-add_entrypoint_object(shm_open ALIAS DEPENDS .${LIBC_TARGET_OS}.shm_open)
-
-add_entrypoint_object(shm_unlink ALIAS DEPENDS .${LIBC_TARGET_OS}.shm_unlink)
-
-add_entrypoint_object(mremap ALIAS DEPENDS .${LIBC_TARGET_OS}.mremap)
-
-add_entrypoint_object(process_mrelease ALIAS DEPENDS
- .${LIBC_TARGET_OS}.process_mrelease)
+add_entrypoint_object(
+ madvise
+ ALIAS
+ DEPENDS
+ .${LIBC_TARGET_OS}.madvise
+)
+
+add_entrypoint_object(
+ mmap
+ ALIAS
+ DEPENDS
+ .${LIBC_TARGET_OS}.mmap
+)
+
+add_entrypoint_object(
+ munmap
+ ALIAS
+ DEPENDS
+ .${LIBC_TARGET_OS}.munmap
+)
+
+add_entrypoint_object(
+ mprotect
+ ALIAS
+ DEPENDS
+ .${LIBC_TARGET_OS}.mprotect
+)
+
+add_entrypoint_object(
+ posix_madvise
+ ALIAS
+ DEPENDS
+ .${LIBC_TARGET_OS}.posix_madvise
+)
+
+add_entrypoint_object(
+ mincore
+ ALIAS
+ DEPENDS
+ .${LIBC_TARGET_OS}.mincore
+)
+
+add_entrypoint_object(
+ mlock
+ ALIAS
+ DEPENDS
+ .${LIBC_TARGET_OS}.mlock
+)
+
+add_entrypoint_object(
+ mlock2
+ ALIAS
+ DEPENDS
+ .${LIBC_TARGET_OS}.mlock2
+)
+
+add_entrypoint_object(
+ munlock
+ ALIAS
+ DEPENDS
+ .${LIBC_TARGET_OS}.munlock
+)
+
+add_entrypoint_object(
+ mlockall
+ ALIAS
+ DEPENDS
+ .${LIBC_TARGET_OS}.mlockall
+)
+
+add_entrypoint_object(
+ munlockall
+ ALIAS
+ DEPENDS
+ .${LIBC_TARGET_OS}.munlockall
+)
+
+add_entrypoint_object(
+ msync
+ ALIAS
+ DEPENDS
+ .${LIBC_TARGET_OS}.msync
+)
+
+add_entrypoint_object(
+ remap_file_pages
+ ALIAS
+ DEPENDS
+ .${LIBC_TARGET_OS}.remap_file_pages
+)
+
+add_entrypoint_object(
+ shm_open
+ ALIAS
+ DEPENDS
+ .${LIBC_TARGET_OS}.shm_open
+)
+
+add_entrypoint_object(
+ shm_unlink
+ ALIAS
+ DEPENDS
+ .${LIBC_TARGET_OS}.shm_unlink
+)
+
+add_entrypoint_object(
+ mremap
+ ALIAS
+ DEPENDS
+ .${LIBC_TARGET_OS}.mremap
+)
+add_entrypoint_object(
+ process_mrelease
+ ALIAS
+ DEPENDS
+ .${LIBC_TARGET_OS}.process_mrelease)
diff --git a/libc/src/sys/mman/linux/CMakeLists.txt b/libc/src/sys/mman/linux/CMakeLists.txt
index 7fb3ba8682e01b4..23a8486a9e12dd6 100644
--- a/libc/src/sys/mman/linux/CMakeLists.txt
+++ b/libc/src/sys/mman/linux/CMakeLists.txt
@@ -1,26 +1,28 @@
add_entrypoint_object(
madvise
SRCS
- madvise.cpp
+ madvise.cpp
HDRS
- ../madvise.h
+ ../madvise.h
DEPENDS
- libc.include.sys_mman
- libc.include.sys_syscall
- libc.src.__support.OSUtil.osutil
- libc.src.errno.errno)
+ libc.include.sys_mman
+ libc.include.sys_syscall
+ libc.src.__support.OSUtil.osutil
+ libc.src.errno.errno
+)
add_entrypoint_object(
mmap
SRCS
- mmap.cpp
+ mmap.cpp
HDRS
- ../mmap.h
+ ../mmap.h
DEPENDS
- libc.include.sys_mman
- libc.include.sys_syscall
- libc.src.__support.OSUtil.osutil
- libc.src.errno.errno)
+ libc.include.sys_mman
+ libc.include.sys_syscall
+ libc.src.__support.OSUtil.osutil
+ libc.src.errno.errno
+)
add_entrypoint_object(
mremap
@@ -34,180 +36,193 @@ add_entrypoint_object(
libc.src.__support.OSUtil.osutil
libc.src.errno.errno
)
-
add_entrypoint_object(
munmap
SRCS
- munmap.cpp
+ munmap.cpp
HDRS
- ../munmap.h
+ ../munmap.h
DEPENDS
- libc.include.sys_mman
- libc.include.sys_syscall
- libc.src.__support.OSUtil.osutil
- libc.src.errno.errno)
+ libc.include.sys_mman
+ libc.include.sys_syscall
+ libc.src.__support.OSUtil.osutil
+ libc.src.errno.errno
+)
add_entrypoint_object(
mprotect
SRCS
- mprotect.cpp
+ mprotect.cpp
HDRS
- ../mprotect.h
+ ../mprotect.h
DEPENDS
- libc.include.sys_mman
- libc.include.sys_syscall
- libc.src.__support.OSUtil.osutil
- libc.src.errno.errno)
+ libc.include.sys_mman
+ libc.include.sys_syscall
+ libc.src.__support.OSUtil.osutil
+ libc.src.errno.errno
+)
add_entrypoint_object(
posix_madvise
SRCS
- posix_madvise.cpp
+ posix_madvise.cpp
HDRS
- ../posix_madvise.h
+ ../posix_madvise.h
DEPENDS
- libc.include.sys_mman
- libc.include.sys_syscall
- libc.src.__support.OSUtil.osutil)
+ libc.include.sys_mman
+ libc.include.sys_syscall
+ libc.src.__support.OSUtil.osutil
+)
add_entrypoint_object(
mincore
SRCS
- mincore.cpp
+ mincore.cpp
HDRS
- ../mincore.h
+ ../mincore.h
DEPENDS
- libc.include.sys_mman
- libc.include.sys_syscall
- libc.src.__support.OSUtil.osutil
- libc.src.errno.errno)
+ libc.include.sys_mman
+ libc.include.sys_syscall
+ libc.src.__support.OSUtil.osutil
+ libc.src.errno.errno
+)
add_entrypoint_object(
mlock
SRCS
- mlock.cpp
+ mlock.cpp
HDRS
- ../mlock.h
+ ../mlock.h
DEPENDS
- libc.include.sys_mman
- libc.include.sys_syscall
- libc.src.__support.OSUtil.osutil
- libc.src.errno.errno)
+ libc.include.sys_mman
+ libc.include.sys_syscall
+ libc.src.__support.OSUtil.osutil
+ libc.src.errno.errno
+)
add_entrypoint_object(
mlock2
SRCS
- mlock2.cpp
+ mlock2.cpp
HDRS
- ../mlock2.h
+ ../mlock2.h
DEPENDS
- libc.include.sys_mman
- libc.include.sys_syscall
- libc.src.__support.OSUtil.osutil
- libc.src.errno.errno)
+ libc.include.sys_mman
+ libc.include.sys_syscall
+ libc.src.__support.OSUtil.osutil
+ libc.src.errno.errno
+)
add_entrypoint_object(
munlock
SRCS
- munlock.cpp
+ munlock.cpp
HDRS
- ../munlock.h
+ ../munlock.h
DEPENDS
- libc.include.sys_mman
- libc.include.sys_syscall
- libc.src.__support.OSUtil.osutil
- libc.src.errno.errno)
+ libc.include.sys_mman
+ libc.include.sys_syscall
+ libc.src.__support.OSUtil.osutil
+ libc.src.errno.errno
+)
add_entrypoint_object(
mlockall
SRCS
- mlockall.cpp
+ mlockall.cpp
HDRS
- ../mlockall.h
+ ../mlockall.h
DEPENDS
- libc.include.sys_mman
- libc.include.sys_syscall
- libc.src.__support.OSUtil.osutil
- libc.src.errno.errno)
+ libc.include.sys_mman
+ libc.include.sys_syscall
+ libc.src.__support.OSUtil.osutil
+ libc.src.errno.errno
+)
add_entrypoint_object(
munlockall
SRCS
- munlockall.cpp
+ munlockall.cpp
HDRS
- ../munlockall.h
+ ../munlockall.h
DEPENDS
- libc.include.sys_mman
- libc.include.sys_syscall
- libc.src.__support.OSUtil.osutil
- libc.src.errno.errno)
+ libc.include.sys_mman
+ libc.include.sys_syscall
+ libc.src.__support.OSUtil.osutil
+ libc.src.errno.errno
+)
add_entrypoint_object(
msync
SRCS
- msync.cpp
+ msync.cpp
HDRS
- ../msync.h
+ ../msync.h
DEPENDS
- libc.include.sys_mman
- libc.include.sys_syscall
- libc.src.__support.OSUtil.osutil
- libc.src.errno.errno)
+ libc.include.sys_mman
+ libc.include.sys_syscall
+ libc.src.__support.OSUtil.osutil
+ libc.src.errno.errno
+)
add_entrypoint_object(
remap_file_pages
SRCS
- remap_file_pages.cpp
+ remap_file_pages.cpp
HDRS
- ../remap_file_pages.h
+ ../remap_file_pages.h
DEPENDS
- libc.include.sys_mman
- libc.include.sys_syscall
- libc.src.__support.OSUtil.osutil
- libc.src.errno.errno)
+ libc.include.sys_mman
+ libc.include.sys_syscall
+ libc.src.__support.OSUtil.osutil
+ libc.src.errno.errno
+)
add_header_library(
shm_common
HDRS
- shm_common.h
+ shm_common.h
DEPENDS
- libc.src.__support.CPP.array
- libc.src.__support.CPP.string_view
- libc.src.__support.CPP.optional
- libc.src.__support.common
- libc.src.errno.errno
- libc.src.string.memory_utils.inline_memcpy)
+ libc.src.__support.CPP.array
+ libc.src.__support.CPP.string_view
+ libc.src.__support.CPP.optional
+ libc.src.__support.common
+ libc.src.errno.errno
+ libc.src.string.memory_utils.inline_memcpy
+)
add_entrypoint_object(
shm_open
SRCS
- shm_open.cpp
+ shm_open.cpp
HDRS
- ../shm_open.h
+ ../shm_open.h
DEPENDS
- libc.src.fcntl.open
- libc.hdr.types.mode_t
- .shm_common)
+ libc.src.fcntl.open
+ libc.hdr.types.mode_t
+ .shm_common
+)
add_entrypoint_object(
shm_unlink
SRCS
- shm_unlink.cpp
+ shm_unlink.cpp
HDRS
- ../shm_unlink.h
+ ../shm_unlink.h
DEPENDS
- libc.src.unistd.unlink
- .shm_common)
+ libc.src.unistd.unlink
+ .shm_common
+)
add_entrypoint_object(
process_mrelease
SRCS
- process_mrelease.cpp
+ process_mrelease.cpp
HDRS
- ../process_mrelease.h
+ ../process_mrelease.h
DEPENDS
- libc.include.signal
- libc.src.signal.kill
- libc.include.sys_syscall
- libc.src.__support.OSUtil.osutil
- libc.src.errno.errno)
+ libc.include.signal
+ libc.src.signal.kill
+ libc.include.sys_syscall
+ libc.src.__support.OSUtil.osutil
+ libc.src.errno.errno)
diff --git a/libc/test/src/sys/mman/linux/CMakeLists.txt b/libc/test/src/sys/mman/linux/CMakeLists.txt
index 16d83ea42743745..87fcc8a25812b96 100644
--- a/libc/test/src/sys/mman/linux/CMakeLists.txt
+++ b/libc/test/src/sys/mman/linux/CMakeLists.txt
@@ -1,17 +1,16 @@
-add_custom_target(libc_sys_mman_unittests)
-
add_libc_unittest(
mmap_test
SUITE
- libc_sys_mman_unittests
+ libc_sys_mman_unittests
SRCS
- mmap_test.cpp
+ mmap_test.cpp
DEPENDS
- libc.include.sys_mman
- libc.src.errno.errno
- libc.src.sys.mman.mmap
- libc.src.sys.mman.munmap
- libc.test.UnitTest.ErrnoSetterMatcher)
+ libc.include.sys_mman
+ libc.src.errno.errno
+ libc.src.sys.mman.mmap
+ libc.src.sys.mman.munmap
+ libc.test.UnitTest.ErrnoSetterMatcher
+)
add_libc_unittest(
mremap_test
@@ -29,172 +28,170 @@ add_libc_unittest(
)
if (NOT LLVM_USE_SANITIZER)
-if(NOT LLVM_USE_SANITIZER)
add_libc_unittest(
mprotect_test
SUITE
- libc_sys_mman_unittests
+ libc_sys_mman_unittests
SRCS
- mprotect_test.cpp
+ mprotect_test.cpp
DEPENDS
- libc.include.sys_mman
- libc.include.signal
- libc.src.errno.errno
- libc.src.sys.mman.mmap
- libc.src.sys.mman.munmap
- libc.src.sys.mman.mprotect
- libc.test.UnitTest.ErrnoSetterMatcher)
+ libc.include.sys_mman
+ libc.include.signal
+ libc.src.errno.errno
+ libc.src.sys.mman.mmap
+ libc.src.sys.mman.munmap
+ libc.src.sys.mman.mprotect
+ libc.test.UnitTest.ErrnoSetterMatcher
+ )
endif()
add_libc_unittest(
madvise_test
SUITE
- libc_sys_mman_unittests
+ libc_sys_mman_unittests
SRCS
madvise_test.cpp
DEPENDS
- libc.include.sys_mman
- libc.src.errno.errno
- libc.src.sys.mman.mmap
- libc.src.sys.mman.munmap
- libc.src.sys.mman.madvise
- libc.test.UnitTest.ErrnoSetterMatcher)
+ libc.include.sys_mman
+ libc.src.errno.errno
+ libc.src.sys.mman.mmap
+ libc.src.sys.mman.munmap
+ libc.src.sys.mman.madvise
+ libc.test.UnitTest.ErrnoSetterMatcher
+)
+
add_libc_unittest(
posix_madvise_test
SUITE
- libc_sys_mman_unittests
+ libc_sys_mman_unittests
SRCS
posix_madvise_test.cpp
DEPENDS
- libc.include.sys_mman
- libc.src.errno.errno
- libc.src.sys.mman.mmap
- libc.src.sys.mman.munmap
- libc.src.sys.mman.posix_madvise
- libc.test.UnitTest.ErrnoSetterMatcher)
+ libc.include.sys_mman
+ libc.src.errno.errno
+ libc.src.sys.mman.mmap
+ libc.src.sys.mman.munmap
+ libc.src.sys.mman.posix_madvise
+ libc.test.UnitTest.ErrnoSetterMatcher
+)
add_libc_unittest(
mincore_test
SUITE
- libc_sys_mman_unittests
+ libc_sys_mman_unittests
SRCS
- mincore_test.cpp
+ mincore_test.cpp
DEPENDS
- libc.include.sys_mman
- libc.include.unistd
- libc.src.errno.errno
- libc.src.sys.mman.mmap
- libc.src.sys.mman.munmap
- libc.src.sys.mman.madvise
- libc.src.sys.mman.mincore
- libc.src.sys.mman.mlock
- libc.src.sys.mman.munlock
- libc.src.unistd.sysconf
- libc.test.UnitTest.ErrnoSetterMatcher)
+ libc.include.sys_mman
+ libc.include.unistd
+ libc.src.errno.errno
+ libc.src.sys.mman.mmap
+ libc.src.sys.mman.munmap
+ libc.src.sys.mman.madvise
+ libc.src.sys.mman.mincore
+ libc.src.sys.mman.mlock
+ libc.src.sys.mman.munlock
+ libc.src.unistd.sysconf
+ libc.test.UnitTest.ErrnoSetterMatcher
+)
add_libc_unittest(
mlock_test
SUITE
- libc_sys_mman_unittests
+ libc_sys_mman_unittests
SRCS
- mlock_test.cpp
+ mlock_test.cpp
DEPENDS
- libc.include.sys_mman
- libc.include.unistd
- libc.src.errno.errno
- libc.src.sys.mman.mmap
- libc.src.sys.mman.munmap
- libc.src.sys.mman.madvise
- libc.src.sys.mman.mincore
- libc.src.sys.mman.mlock
- libc.src.sys.mman.mlock2
- libc.src.sys.mman.munlock
- libc.src.sys.mman.mlockall
- libc.src.sys.mman.munlockall
- libc.src.sys.resource.getrlimit
- libc.src.__support.OSUtil.osutil
- libc.src.unistd.sysconf
- libc.test.UnitTest.ErrnoSetterMatcher)
+ libc.include.sys_mman
+ libc.include.unistd
+ libc.src.errno.errno
+ libc.src.sys.mman.mmap
+ libc.src.sys.mman.munmap
+ libc.src.sys.mman.madvise
+ libc.src.sys.mman.mincore
+ libc.src.sys.mman.mlock
+ libc.src.sys.mman.mlock2
+ libc.src.sys.mman.munlock
+ libc.src.sys.mman.mlockall
+ libc.src.sys.mman.munlockall
+ libc.src.sys.resource.getrlimit
+ libc.src.__support.OSUtil.osutil
+ libc.src.unistd.sysconf
+ libc.test.UnitTest.ErrnoSetterMatcher
+)
add_libc_unittest(
msync_test
SUITE
- libc_sys_mman_unittests
+ libc_sys_mman_unittests
SRCS
- msync_test.cpp
+ msync_test.cpp
DEPENDS
- libc.include.sys_mman
- libc.include.unistd
- libc.src.errno.errno
- libc.src.sys.mman.mmap
- libc.src.sys.mman.munmap
- libc.src.sys.mman.msync
- libc.src.sys.mman.mincore
- libc.src.sys.mman.mlock
- libc.src.sys.mman.munlock
- libc.src.unistd.sysconf
- libc.test.UnitTest.ErrnoSetterMatcher)
+ libc.include.sys_mman
+ libc.include.unistd
+ libc.src.errno.errno
+ libc.src.sys.mman.mmap
+ libc.src.sys.mman.munmap
+ libc.src.sys.mman.msync
+ libc.src.sys.mman.mincore
+ libc.src.sys.mman.mlock
+ libc.src.sys.mman.munlock
+ libc.src.unistd.sysconf
+ libc.test.UnitTest.ErrnoSetterMatcher
+)
add_libc_unittest(
remap_file_pages_test
SUITE
- libc_sys_mman_unittests
+ libc_sys_mman_unittests
SRCS
- remap_file_pages_test.cpp
+ remap_file_pages_test.cpp
DEPENDS
- libc.include.sys_mman
- libc.include.sys_stat
- libc.src.unistd.sysconf
- libc.test.UnitTest.ErrnoSetterMatcher
- libc.src.sys.mman.remap_file_pages
- libc.src.errno.errno
- libc.src.sys.mman.mmap
- libc.src.sys.mman.munmap)
+ libc.include.sys_mman
+ libc.include.sys_stat
+ libc.src.unistd.sysconf
+ libc.test.UnitTest.ErrnoSetterMatcher
+ libc.src.sys.mman.remap_file_pages
+ libc.src.errno.errno
+ libc.src.sys.mman.mmap
+ libc.src.sys.mman.munmap
+)
add_libc_unittest(
shm_test
SUITE
- libc_sys_mman_unittests
+ libc_sys_mman_unittests
SRCS
- shm_test.cpp
+ shm_test.cpp
DEPENDS
- libc.include.sys_mman
- libc.include.sys_syscall
- libc.src.errno.errno
- libc.src.fcntl.fcntl
- libc.src.sys.mman.shm_open
- libc.src.sys.mman.shm_unlink
- libc.src.sys.mman.mmap
- libc.src.sys.mman.munmap
- libc.src.unistd.ftruncate
- libc.src.unistd.close
- libc.src.__support.OSUtil.osutil
- libc.hdr.fcntl_macros
- libc.test.UnitTest.ErrnoSetterMatcher)
+ libc.include.sys_mman
+ libc.include.sys_syscall
+ libc.src.errno.errno
+ libc.src.fcntl.fcntl
+ libc.src.sys.mman.shm_open
+ libc.src.sys.mman.shm_unlink
+ libc.src.sys.mman.mmap
+ libc.src.sys.mman.munmap
+ libc.src.unistd.ftruncate
+ libc.src.unistd.close
+ libc.src.__support.OSUtil.osutil
+ libc.hdr.fcntl_macros
+ libc.test.UnitTest.ErrnoSetterMatcher
+)
add_libc_unittest(
process_mrelease_test
SUITE
- libc_sys_mman_unittests
+ libc_sys_mman_unittests
SRCS
- process_mrelease_test.cpp
+ process_mrelease_test.cpp
DEPENDS
- libc.include.sys_mman
- libc.include.sys_syscall
- libc.src.errno.errno
- libc.src.fcntl.fcntl
- libc.include.sys_wait
- libc.src.sys.wait.waitpid
- libc.src.sys.mman.process_mrelease
- libc.src.sys.mman.mmap
- libc.src.sys.mman.munmap
- libc.src.unistd.ftruncate
- libc.src.unistd.close
- libc.src.__support.OSUtil.osutil
- libc.test.UnitTest.ErrnoSetterMatcher)
-
-# add_libc_unittest( process_mrelease_test SUITE libc_sys_mman_unittests SRCS
-# process_mrelease_test.cpp DEPENDS libc.include.sys_mman
-# libc.include.sys_syscall libc.src.errno.errno
-# libc.src.sys.mman.process_mrelease libc.test.UnitTest.ErrnoSetterMatcher)
+ libc.include.sys_mman
+ libc.include.sys_syscall
+ libc.src.errno.errno
+ libc.src.sys.mman.process_mrelease
+ libc.src.unistd.close
+ libc.src.stdlib.exit
+ libc.src.__support.OSUtil.osutil
+ libc.src.__support.threads.sleep)
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 960e97b7aaddee7..aa47b1ebf9fdcfb 100644
--- a/libc/test/src/sys/mman/linux/process_mrelease_test.cpp
+++ b/libc/test/src/sys/mman/linux/process_mrelease_test.cpp
@@ -23,8 +23,7 @@ int pidfd_open(pid_t pid, unsigned int flags) {
}
TEST(LlvmLibcMProcessMReleaseTest, NoError) {
- pid_t child_pid = LIBC_NAMESPACE::fork();
-
+ pid_t child_pid = fork();
EXPECT_GE(child_pid, 0);
if (child_pid == 0) {
@@ -49,7 +48,6 @@ TEST(LlvmLibcMProcessMReleaseTest, NoError) {
TEST(LlvmLibcMProcessMReleaseTest, ErrorNotKilled) {
pid_t child_pid = fork();
-
EXPECT_GE(child_pid, 0);
if (child_pid == 0) {
>From 4f4a15966cc6cf720a862e170fbe1457c90f37e4 Mon Sep 17 00:00:00 2001
From: moar55 <moar.ahmed at gmail.com>
Date: Sun, 24 Nov 2024 20:35:31 +0100
Subject: [PATCH 3/9] fix cmakelist
---
libc/src/sys/mman/CMakeLists.txt | 1 +
libc/test/src/sys/mman/linux/CMakeLists.txt | 2 ++
2 files changed, 3 insertions(+)
diff --git a/libc/src/sys/mman/CMakeLists.txt b/libc/src/sys/mman/CMakeLists.txt
index 7d71f14ff8837f6..281efc0ffcdf200 100644
--- a/libc/src/sys/mman/CMakeLists.txt
+++ b/libc/src/sys/mman/CMakeLists.txt
@@ -113,6 +113,7 @@ add_entrypoint_object(
DEPENDS
.${LIBC_TARGET_OS}.mremap
)
+
add_entrypoint_object(
process_mrelease
ALIAS
diff --git a/libc/test/src/sys/mman/linux/CMakeLists.txt b/libc/test/src/sys/mman/linux/CMakeLists.txt
index 87fcc8a25812b96..c4e8de2b14d8044 100644
--- a/libc/test/src/sys/mman/linux/CMakeLists.txt
+++ b/libc/test/src/sys/mman/linux/CMakeLists.txt
@@ -1,3 +1,5 @@
+add_custom_target(libc_sys_mman_unittests)
+
add_libc_unittest(
mmap_test
SUITE
>From 516a48c8e4c86f155bfd2750f8f71ff2ac2cde7d Mon Sep 17 00:00:00 2001
From: moar55 <moar.ahmed at gmail.com>
Date: Mon, 25 Nov 2024 08:56:22 +0100
Subject: [PATCH 4/9] add missing target
---
libc/src/sys/mman/linux/CMakeLists.txt | 2 --
libc/test/src/sys/mman/linux/CMakeLists.txt | 2 ++
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/libc/src/sys/mman/linux/CMakeLists.txt b/libc/src/sys/mman/linux/CMakeLists.txt
index 23a8486a9e12dd6..aa2ca4b160181a5 100644
--- a/libc/src/sys/mman/linux/CMakeLists.txt
+++ b/libc/src/sys/mman/linux/CMakeLists.txt
@@ -221,8 +221,6 @@ add_entrypoint_object(
HDRS
../process_mrelease.h
DEPENDS
- libc.include.signal
- libc.src.signal.kill
libc.include.sys_syscall
libc.src.__support.OSUtil.osutil
libc.src.errno.errno)
diff --git a/libc/test/src/sys/mman/linux/CMakeLists.txt b/libc/test/src/sys/mman/linux/CMakeLists.txt
index c4e8de2b14d8044..35dcf832729be9e 100644
--- a/libc/test/src/sys/mman/linux/CMakeLists.txt
+++ b/libc/test/src/sys/mman/linux/CMakeLists.txt
@@ -194,6 +194,8 @@ add_libc_unittest(
libc.src.errno.errno
libc.src.sys.mman.process_mrelease
libc.src.unistd.close
+ libc.src.signal.kill
+ libc.include.signal
libc.src.stdlib.exit
libc.src.__support.OSUtil.osutil
libc.src.__support.threads.sleep)
>From b158341c19d5a7f5422ef8b8f97ddd23aa80067e Mon Sep 17 00:00:00 2001
From: moar55 <moar.ahmed at gmail.com>
Date: Tue, 26 Nov 2024 12:32:42 +0100
Subject: [PATCH 5/9] address comments
---
libc/src/sys/mman/linux/process_mrelease.cpp | 2 +-
libc/src/sys/mman/process_mrelease.h | 5 ++---
libc/test/src/sys/mman/linux/process_mrelease_test.cpp | 9 ++++++++-
3 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/libc/src/sys/mman/linux/process_mrelease.cpp b/libc/src/sys/mman/linux/process_mrelease.cpp
index d71b1289c3e9283..e86bbec1b1b6612 100644
--- a/libc/src/sys/mman/linux/process_mrelease.cpp
+++ b/libc/src/sys/mman/linux/process_mrelease.cpp
@@ -24,7 +24,7 @@ LLVM_LIBC_FUNCTION(int, process_mrelease, (int pidfd, unsigned int flags)) {
if (ret < 0) {
libc_errno = static_cast<int>(-ret);
- return libc_errno;
+ return -1;
}
return 0;
diff --git a/libc/src/sys/mman/process_mrelease.h b/libc/src/sys/mman/process_mrelease.h
index 13a9ba57eae19b4..ec4a6e4768bcac0 100644
--- a/libc/src/sys/mman/process_mrelease.h
+++ b/libc/src/sys/mman/process_mrelease.h
@@ -1,11 +1,10 @@
-//===-- Implementation header for process_mrelease function -----------------*-
-// C++ -*-===//
+//===-- Implementation header for process_mrelease function --------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
-//===----------------------------------------------------------------------===//
+//===-------------------------------------------------------------------------===//
#ifndef LLVM_LIBC_SRC_SYS_MMAN_PROCESS_MRELEASE_H
#define LLVM_LIBC_SRC_SYS_MMAN_PROCESS_MRELEASE_H
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 aa47b1ebf9fdcfb..1b98f74e9b63b1e 100644
--- a/libc/test/src/sys/mman/linux/process_mrelease_test.cpp
+++ b/libc/test/src/sys/mman/linux/process_mrelease_test.cpp
@@ -1,3 +1,10 @@
+//===-- Unittests for process_mrelease ------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
//===-- Unittests for process_mrelease
//-------------------------------------===//
//
@@ -68,5 +75,5 @@ TEST(LlvmLibcMProcessMReleaseTest, ErrorNotKilled) {
TEST(LlvmLibcMProcessMReleaseTest, ErrorNonExistingPidfd) {
- ASSERT_EQ(LIBC_NAMESPACE::process_mrelease(12345, 0), EBADF);
+ ASSERT_EQ(LIBC_NAMESPACE::process_mrelease(-1, 0), EBADF);
}
>From 85a334739ae8676d56b173ce18e70647bba4488a Mon Sep 17 00:00:00 2001
From: moar55 <moar.ahmed at gmail.com>
Date: Tue, 26 Nov 2024 21:39:54 +0100
Subject: [PATCH 6/9] fix license
---
libc/test/src/sys/mman/linux/process_mrelease_test.cpp | 9 +--------
1 file changed, 1 insertion(+), 8 deletions(-)
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 1b98f74e9b63b1e..3349a5ee0a548e1 100644
--- a/libc/test/src/sys/mman/linux/process_mrelease_test.cpp
+++ b/libc/test/src/sys/mman/linux/process_mrelease_test.cpp
@@ -5,14 +5,7 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
-//===-- Unittests for process_mrelease
-//-------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
+
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
#include "src/__support/threads/sleep.h"
#include "src/errno/libc_errno.h"
>From 0163886e29f515439d1c78f2cca08ba92a009553 Mon Sep 17 00:00:00 2001
From: moar55 <moar.ahmed at gmail.com>
Date: Wed, 27 Nov 2024 08:19:44 +0100
Subject: [PATCH 7/9] check against errno
---
libc/test/src/sys/mman/linux/CMakeLists.txt | 4 +++-
libc/test/src/sys/mman/linux/process_mrelease_test.cpp | 10 ++++++----
2 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/libc/test/src/sys/mman/linux/CMakeLists.txt b/libc/test/src/sys/mman/linux/CMakeLists.txt
index 35dcf832729be9e..6021ccd8c89a82a 100644
--- a/libc/test/src/sys/mman/linux/CMakeLists.txt
+++ b/libc/test/src/sys/mman/linux/CMakeLists.txt
@@ -198,4 +198,6 @@ add_libc_unittest(
libc.include.signal
libc.src.stdlib.exit
libc.src.__support.OSUtil.osutil
- libc.src.__support.threads.sleep)
+ 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 3349a5ee0a548e1..1c3c549aa9bebdc 100644
--- a/libc/test/src/sys/mman/linux/process_mrelease_test.cpp
+++ b/libc/test/src/sys/mman/linux/process_mrelease_test.cpp
@@ -14,10 +14,13 @@
#include "src/sys/mman/process_mrelease.h"
#include "src/unistd/close.h"
#include "src/unistd/fork.h"
+#include "test/UnitTest/ErrnoSetterMatcher.h"
#include "test/UnitTest/LibcTest.h"
#include <sys/syscall.h>
+using namespace LIBC_NAMESPACE::testing::ErrnoSetterMatcher;
+
int pidfd_open(pid_t pid, unsigned int flags) {
return LIBC_NAMESPACE::syscall_impl(SYS_pidfd_open, pid, flags);
}
@@ -40,7 +43,7 @@ TEST(LlvmLibcMProcessMReleaseTest, NoError) {
// Send SIGKILL to child process
LIBC_NAMESPACE::kill(child_pid, SIGKILL);
- EXPECT_EQ(LIBC_NAMESPACE::process_mrelease(pidfd, 0), 0);
+ EXPECT_THAT(LIBC_NAMESPACE::process_mrelease(pidfd, 0), Succeeds());
LIBC_NAMESPACE::close(pidfd);
}
@@ -60,13 +63,12 @@ TEST(LlvmLibcMProcessMReleaseTest, ErrorNotKilled) {
int pidfd = pidfd_open(child_pid, 0);
EXPECT_GE(pidfd, 0);
- ASSERT_EQ(LIBC_NAMESPACE::process_mrelease(pidfd, 0), EINVAL);
+ EXPECT_THAT(LIBC_NAMESPACE::process_mrelease(pidfd, 0), Fails(EINVAL));
LIBC_NAMESPACE::close(pidfd);
}
}
TEST(LlvmLibcMProcessMReleaseTest, ErrorNonExistingPidfd) {
-
- ASSERT_EQ(LIBC_NAMESPACE::process_mrelease(-1, 0), EBADF);
+ EXPECT_THAT(LIBC_NAMESPACE::process_mrelease(-1, 0), Fails(EBADF));
}
>From 30e3d6adf95ae82e53a9cebe2a41c90031338f2e Mon Sep 17 00:00:00 2001
From: moar55 <moar.ahmed at gmail.com>
Date: Wed, 27 Nov 2024 20:12:52 +0100
Subject: [PATCH 8/9] fix formatting
---
libc/src/sys/mman/process_mrelease.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/libc/src/sys/mman/process_mrelease.h b/libc/src/sys/mman/process_mrelease.h
index ec4a6e4768bcac0..6c800f2d0eab868 100644
--- a/libc/src/sys/mman/process_mrelease.h
+++ b/libc/src/sys/mman/process_mrelease.h
@@ -1,10 +1,10 @@
-//===-- Implementation header for process_mrelease function --------*- C++ -*-===//
+//===-- Implementation header for process_mrelease function -*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
-//===-------------------------------------------------------------------------===//
+//===------------------------------------------------------------------===//
#ifndef LLVM_LIBC_SRC_SYS_MMAN_PROCESS_MRELEASE_H
#define LLVM_LIBC_SRC_SYS_MMAN_PROCESS_MRELEASE_H
>From b5068a4255a34dec60b887fb060e6d0a0e166527 Mon Sep 17 00:00:00 2001
From: moar55 <moar.ahmed at gmail.com>
Date: Sun, 8 Dec 2024 21:24:19 +0100
Subject: [PATCH 9/9] [libc] Implement process_mrelease #117851
---
libc/test/src/sys/mman/linux/CMakeLists.txt | 8 +--
.../sys/mman/linux/process_mrelease_test.cpp | 59 +------------------
2 files changed, 4 insertions(+), 63 deletions(-)
diff --git a/libc/test/src/sys/mman/linux/CMakeLists.txt b/libc/test/src/sys/mman/linux/CMakeLists.txt
index 6021ccd8c89a82a..9c7c06d7c4869fa 100644
--- a/libc/test/src/sys/mman/linux/CMakeLists.txt
+++ b/libc/test/src/sys/mman/linux/CMakeLists.txt
@@ -193,11 +193,5 @@ add_libc_unittest(
libc.include.sys_syscall
libc.src.errno.errno
libc.src.sys.mman.process_mrelease
- libc.src.unistd.close
- libc.src.signal.kill
- libc.include.signal
- libc.src.stdlib.exit
- 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 1c3c549aa9bebdc..d369c92031a7f09 100644
--- a/libc/test/src/sys/mman/linux/process_mrelease_test.cpp
+++ b/libc/test/src/sys/mman/linux/process_mrelease_test.cpp
@@ -6,14 +6,7 @@
//
//===----------------------------------------------------------------------===//
-#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/stdlib/exit.h"
#include "src/sys/mman/process_mrelease.h"
-#include "src/unistd/close.h"
-#include "src/unistd/fork.h"
#include "test/UnitTest/ErrnoSetterMatcher.h"
#include "test/UnitTest/LibcTest.h"
@@ -21,54 +14,8 @@
using namespace LIBC_NAMESPACE::testing::ErrnoSetterMatcher;
-int pidfd_open(pid_t pid, unsigned int flags) {
- return LIBC_NAMESPACE::syscall_impl(SYS_pidfd_open, pid, flags);
-}
-
-TEST(LlvmLibcMProcessMReleaseTest, NoError) {
- pid_t child_pid = fork();
- 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);
- } 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);
-
- // Send SIGKILL to child process
- LIBC_NAMESPACE::kill(child_pid, SIGKILL);
-
- EXPECT_THAT(LIBC_NAMESPACE::process_mrelease(pidfd, 0), Succeeds());
-
- LIBC_NAMESPACE::close(pidfd);
- }
-}
-
-TEST(LlvmLibcMProcessMReleaseTest, ErrorNotKilled) {
- pid_t child_pid = fork();
- 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);
- } else {
- // Give child process some time to start.
- LIBC_NAMESPACE::sleep_briefly();
- int pidfd = pidfd_open(child_pid, 0);
- EXPECT_GE(pidfd, 0);
-
- EXPECT_THAT(LIBC_NAMESPACE::process_mrelease(pidfd, 0), Fails(EINVAL));
-
- LIBC_NAMESPACE::close(pidfd);
- }
-}
-
-TEST(LlvmLibcMProcessMReleaseTest, ErrorNonExistingPidfd) {
+#if defined(SYS_process_mrelease)
+TEST(LlvmLibcProcessMReleaseTest, ErrorNonExistingPidfd) {
EXPECT_THAT(LIBC_NAMESPACE::process_mrelease(-1, 0), Fails(EBADF));
}
+#endif
More information about the libc-commits
mailing list