-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[libc] Revert #73704 and subsequent fixes #73984, #74026 #74355
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
Conversation
@llvm/pr-subscribers-libc Author: Schrodinger ZHU Yifan (SchrodingerZhu) ChangesThe test cases of mincore requires getting corrent page size from OS. As This reverts 54878b8, 985c0d1 and 418a3a4. Full diff: https://github.com/llvm/llvm-project/pull/74355.diff 11 Files Affected:
diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index ba3a7c5579648..7a60c44570c4e 100644
--- a/libc/config/linux/aarch64/entrypoints.txt
+++ b/libc/config/linux/aarch64/entrypoints.txt
@@ -136,7 +136,6 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.sys.mman.mprotect
libc.src.sys.mman.munmap
libc.src.sys.mman.posix_madvise
- libc.src.sys.mman.mincore
# sys/random.h entrypoints
libc.src.sys.random.getrandom
diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index 63c1f9227f91c..28687ef8e234e 100644
--- a/libc/config/linux/riscv/entrypoints.txt
+++ b/libc/config/linux/riscv/entrypoints.txt
@@ -142,7 +142,6 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.sys.mman.mprotect
libc.src.sys.mman.munmap
libc.src.sys.mman.posix_madvise
- libc.src.sys.mman.mincore
# sys/random.h entrypoints
libc.src.sys.random.getrandom
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index eb5457678e990..43266e0e5b66e 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -142,7 +142,6 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.sys.mman.mprotect
libc.src.sys.mman.munmap
libc.src.sys.mman.posix_madvise
- libc.src.sys.mman.mincore
# sys/random.h entrypoints
libc.src.sys.random.getrandom
diff --git a/libc/spec/linux.td b/libc/spec/linux.td
index eab0a987b920c..ba5f99c12ecd1 100644
--- a/libc/spec/linux.td
+++ b/libc/spec/linux.td
@@ -76,20 +76,7 @@ def Linux : StandardSpec<"Linux"> {
HeaderSpec SysMMan = HeaderSpec<
"sys/mman.h",
- [Macro<"MAP_ANONYMOUS">],
- [], // Types
- [], // Enumerations
- [
- FunctionSpec<
- "mincore",
- RetValSpec<IntType>,
- [
- ArgSpec<VoidPtr>,
- ArgSpec<SizeTType>,
- ArgSpec<UnsignedCharPtr>,
- ]
- >,
- ] // Functions
+ [Macro<"MAP_ANONYMOUS">]
>;
diff --git a/libc/spec/spec.td b/libc/spec/spec.td
index 818cfaee6b61c..9b689b5eb502a 100644
--- a/libc/spec/spec.td
+++ b/libc/spec/spec.td
@@ -49,7 +49,6 @@ def FloatType : NamedType<"float">;
def DoubleType : NamedType<"double">;
def LongDoubleType : NamedType<"long double">;
def CharType : NamedType<"char">;
-def UnsignedCharType : NamedType<"unsigned char">;
// TODO: Add compatibility layer to use C23 type _Float128 if possible.
def Float128Type : NamedType<"__float128">;
@@ -110,7 +109,6 @@ def IntPtr : PtrType<IntType>;
def RestrictedIntPtr : RestrictedPtrType<IntType>;
def FloatPtr : PtrType<FloatType>;
def DoublePtr : PtrType<DoubleType>;
-def UnsignedCharPtr : PtrType<UnsignedCharType>;
def SigHandlerT : NamedType<"__sighandler_t">;
diff --git a/libc/src/sys/mman/CMakeLists.txt b/libc/src/sys/mman/CMakeLists.txt
index 2d17429a26b45..e336bfd5d6dbc 100644
--- a/libc/src/sys/mman/CMakeLists.txt
+++ b/libc/src/sys/mman/CMakeLists.txt
@@ -36,10 +36,3 @@ add_entrypoint_object(
DEPENDS
.${LIBC_TARGET_OS}.posix_madvise
)
-
-add_entrypoint_object(
- mincore
- ALIAS
- DEPENDS
- .${LIBC_TARGET_OS}.mincore
-)
diff --git a/libc/src/sys/mman/linux/CMakeLists.txt b/libc/src/sys/mman/linux/CMakeLists.txt
index ce0cda7f22277..163e7dead8887 100644
--- a/libc/src/sys/mman/linux/CMakeLists.txt
+++ b/libc/src/sys/mman/linux/CMakeLists.txt
@@ -61,16 +61,3 @@ add_entrypoint_object(
libc.include.sys_syscall
libc.src.__support.OSUtil.osutil
)
-
-add_entrypoint_object(
- mincore
- SRCS
- mincore.cpp
- HDRS
- ../mincore.h
- DEPENDS
- libc.include.sys_mman
- libc.include.sys_syscall
- libc.src.__support.OSUtil.osutil
- libc.src.errno.errno
-)
diff --git a/libc/src/sys/mman/linux/mincore.cpp b/libc/src/sys/mman/linux/mincore.cpp
deleted file mode 100644
index 8220c69ef2cb7..0000000000000
--- a/libc/src/sys/mman/linux/mincore.cpp
+++ /dev/null
@@ -1,28 +0,0 @@
-//===---------- Linux implementation of the mincore 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/mincore.h"
-
-#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
-
-#include "src/errno/libc_errno.h"
-#include <sys/syscall.h> // For syscall numbers.
-
-namespace LIBC_NAMESPACE {
-
-LLVM_LIBC_FUNCTION(int, mincore, (void *addr, size_t len, unsigned char *vec)) {
- long ret = syscall_impl(SYS_mincore, reinterpret_cast<long>(addr), len,
- reinterpret_cast<long>(vec));
- if (ret < 0) {
- libc_errno = static_cast<int>(-ret);
- return -1;
- }
- return 0;
-}
-
-} // namespace LIBC_NAMESPACE
diff --git a/libc/src/sys/mman/mincore.h b/libc/src/sys/mman/mincore.h
deleted file mode 100644
index 403afaeb6af97..0000000000000
--- a/libc/src/sys/mman/mincore.h
+++ /dev/null
@@ -1,20 +0,0 @@
-//===-- Implementation header for mincore 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_MINCORE_H
-#define LLVM_LIBC_SRC_SYS_MMAN_MINCORE_H
-
-#include <sys/mman.h> // For size_t
-
-namespace LIBC_NAMESPACE {
-
-int mincore(void *addr, size_t len, unsigned char *vec);
-
-} // namespace LIBC_NAMESPACE
-
-#endif // LLVM_LIBC_SRC_SYS_MMAN_MINCORE_H
diff --git a/libc/test/src/sys/mman/linux/CMakeLists.txt b/libc/test/src/sys/mman/linux/CMakeLists.txt
index c60377eb2cc1f..66743be175fed 100644
--- a/libc/test/src/sys/mman/linux/CMakeLists.txt
+++ b/libc/test/src/sys/mman/linux/CMakeLists.txt
@@ -62,20 +62,3 @@ add_libc_unittest(
libc.src.sys.mman.posix_madvise
libc.test.UnitTest.ErrnoSetterMatcher
)
-
-add_libc_unittest(
- mincore_test
- SUITE
- libc_sys_mman_unittests
- SRCS
- mincore_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.src.sys.mman.mincore
- libc.src.unistd.sysconf
- libc.test.UnitTest.ErrnoSetterMatcher
-)
diff --git a/libc/test/src/sys/mman/linux/mincore_test.cpp b/libc/test/src/sys/mman/linux/mincore_test.cpp
deleted file mode 100644
index 1b0ed157483eb..0000000000000
--- a/libc/test/src/sys/mman/linux/mincore_test.cpp
+++ /dev/null
@@ -1,123 +0,0 @@
-//===-- Unittests for mincore ---------------------------------------------===//
-//
-// 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/errno/libc_errno.h"
-#include "src/sys/mman/madvise.h"
-#include "src/sys/mman/mincore.h"
-#include "src/sys/mman/mmap.h"
-#include "src/sys/mman/munmap.h"
-#include "src/unistd/sysconf.h"
-#include "test/UnitTest/ErrnoSetterMatcher.h"
-#include "test/UnitTest/LibcTest.h"
-#include "test/UnitTest/Test.h"
-
-#include <sys/mman.h>
-#include <unistd.h> // For sysconf.
-
-using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails;
-using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
-
-TEST(LlvmLibcMincoreTest, UnMappedMemory) {
- libc_errno = 0;
- unsigned char vec;
- int res = LIBC_NAMESPACE::mincore(nullptr, 1, &vec);
- EXPECT_THAT(res, Fails(ENOMEM, -1));
-}
-
-// It is always possible to find an aligned boundary if we allocate page sized
-// memory.
-static char *aligned_addr(void *addr, size_t alignment) {
- char *byte_addr = static_cast<char *>(addr);
- uintptr_t addr_val = reinterpret_cast<uintptr_t>(addr);
- uintptr_t offset =
- addr_val % alignment == 0 ? 0 : alignment - (addr_val % alignment);
- return byte_addr + offset;
-}
-
-TEST(LlvmLibcMincoreTest, InvalidVec) {
- size_t page_size = static_cast<size_t>(LIBC_NAMESPACE::sysconf(_SC_PAGESIZE));
- void *addr = LIBC_NAMESPACE::mmap(nullptr, page_size, PROT_READ,
- MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
- EXPECT_NE(addr, MAP_FAILED);
- char *aligned = aligned_addr(addr, page_size);
- int res = LIBC_NAMESPACE::mincore(aligned, 1, nullptr);
- EXPECT_THAT(res, Fails(EFAULT, -1));
- EXPECT_THAT(LIBC_NAMESPACE::munmap(addr, page_size), Succeeds());
-}
-
-TEST(LlvmLibcMincoreTest, UnalignedAddr) {
- size_t page_size = static_cast<size_t>(LIBC_NAMESPACE::sysconf(_SC_PAGESIZE));
- void *addr = LIBC_NAMESPACE::mmap(nullptr, page_size, PROT_READ,
- MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
- EXPECT_NE(addr, MAP_FAILED);
- char *aligned = aligned_addr(addr, page_size);
- libc_errno = 0;
- int res = LIBC_NAMESPACE::mincore(aligned + 1, 1, nullptr);
- EXPECT_THAT(res, Fails(EINVAL, -1));
- EXPECT_THAT(LIBC_NAMESPACE::munmap(addr, page_size), Succeeds());
-}
-
-TEST(LlvmLibcMincoreTest, NoError) {
- size_t page_size = static_cast<size_t>(LIBC_NAMESPACE::sysconf(_SC_PAGESIZE));
- void *addr = LIBC_NAMESPACE::mmap(nullptr, page_size, PROT_READ,
- MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
- EXPECT_NE(addr, MAP_FAILED);
- char *aligned = aligned_addr(addr, page_size);
- unsigned char vec;
- libc_errno = 0;
- int res = LIBC_NAMESPACE::mincore(aligned, 1, &vec);
- EXPECT_THAT(res, Succeeds());
- EXPECT_THAT(LIBC_NAMESPACE::munmap(addr, page_size), Succeeds());
-}
-
-TEST(LlvmLibcMincoreTest, NegativeLength) {
- size_t page_size = static_cast<size_t>(LIBC_NAMESPACE::sysconf(_SC_PAGESIZE));
- void *addr = LIBC_NAMESPACE::mmap(nullptr, page_size, PROT_READ,
- MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
- EXPECT_NE(addr, MAP_FAILED);
- char *aligned = aligned_addr(addr, page_size);
- unsigned char vec;
- libc_errno = 0;
- int res = LIBC_NAMESPACE::mincore(aligned, -1, &vec);
- EXPECT_THAT(res, Fails(ENOMEM, -1));
- EXPECT_THAT(LIBC_NAMESPACE::munmap(addr, page_size), Succeeds());
-}
-
-TEST(LlvmLibcMincoreTest, PageOut) {
- unsigned char vec;
- size_t page_size = static_cast<size_t>(LIBC_NAMESPACE::sysconf(_SC_PAGESIZE));
- // allocate 2 pages since we need to page out page_size bytes
- void *addr =
- LIBC_NAMESPACE::mmap(nullptr, 2 * page_size, PROT_READ | PROT_WRITE,
- MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
- EXPECT_NE(addr, MAP_FAILED);
- char *aligned = aligned_addr(addr, page_size);
-
- // touch the page
- {
- aligned[0] = 0;
- libc_errno = 0;
- int res = LIBC_NAMESPACE::mincore(aligned, 1, &vec);
- EXPECT_EQ(vec & 1u, 1u);
- EXPECT_THAT(res, Succeeds());
- }
-
- // page out the memory
- {
- libc_errno = 0;
- EXPECT_THAT(LIBC_NAMESPACE::madvise(aligned, page_size, MADV_DONTNEED),
- Succeeds());
-
- libc_errno = 0;
- int res = LIBC_NAMESPACE::mincore(aligned, 1, &vec);
- EXPECT_EQ(vec & 1u, 0u);
- EXPECT_THAT(res, Succeeds());
- }
-
- EXPECT_THAT(LIBC_NAMESPACE::munmap(addr, 2 * page_size), Succeeds());
-}
|
eb5e44a
to
05f7f81
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's ok, I look forward to getting this relanded (with the proper infrastructure in place landed first). Please use distinct PRs for each added entrypoint.
The test cases of mincore require getting correct page size from OS. As
sysconf
is not functioning correctly, these patches are implemented in a somewhat confusing way. We revert such patches and will reintroduce mincore after we correct sysconf.This reverts 54878b8, 985c0d1 and 418a3a4.