aboutsummaryrefslogtreecommitdiff
path: root/libc
diff options
context:
space:
mode:
Diffstat (limited to 'libc')
-rw-r--r--libc/hdr/types/CMakeLists.txt13
-rw-r--r--libc/hdr/types/struct_rlimit.h22
-rw-r--r--libc/shared/math.h1
-rw-r--r--libc/shared/math/exp2f.h23
-rw-r--r--libc/src/__support/math/CMakeLists.txt18
-rw-r--r--libc/src/__support/math/exp2f.h (renamed from libc/src/math/generic/exp2f_impl.h)22
-rw-r--r--libc/src/math/generic/CMakeLists.txt22
-rw-r--r--libc/src/math/generic/exp2f.cpp4
-rw-r--r--libc/src/math/generic/powf.cpp5
-rw-r--r--libc/src/sys/resource/linux/CMakeLists.txt2
-rw-r--r--libc/src/sys/resource/linux/getrlimit.cpp5
-rw-r--r--libc/src/sys/resource/linux/setrlimit.cpp5
-rw-r--r--libc/test/shared/CMakeLists.txt1
-rw-r--r--libc/test/shared/shared_math_test.cpp1
-rw-r--r--libc/test/src/sys/mman/linux/CMakeLists.txt6
-rw-r--r--libc/test/src/sys/mman/linux/mincore_test.cpp14
-rw-r--r--libc/test/src/sys/mman/linux/mlock_test.cpp27
-rw-r--r--libc/test/src/sys/mman/linux/msync_test.cpp6
-rw-r--r--libc/test/src/sys/mman/linux/remap_file_pages_test.cpp10
-rw-r--r--libc/test/src/sys/resource/CMakeLists.txt2
-rw-r--r--libc/test/src/sys/resource/getrlimit_setrlimit_test.cpp7
-rw-r--r--libc/test/src/sys/resource/testdata/CMakeLists.txt0
22 files changed, 131 insertions, 85 deletions
diff --git a/libc/hdr/types/CMakeLists.txt b/libc/hdr/types/CMakeLists.txt
index 21971a4..2258439 100644
--- a/libc/hdr/types/CMakeLists.txt
+++ b/libc/hdr/types/CMakeLists.txt
@@ -1,5 +1,5 @@
add_proxy_header_library(
- char8_t
+ char8_t
HDRS
char8_t.h
DEPENDS
@@ -10,7 +10,7 @@ add_proxy_header_library(
)
add_proxy_header_library(
- char32_t
+ char32_t
HDRS
char32_t.h
DEPENDS
@@ -470,3 +470,12 @@ add_proxy_header_library(
libc.include.llvm-libc-types.dl_info
libc.include.dlfcn
)
+
+add_proxy_header_library(
+ struct_rlimit
+ HDRS
+ struct_rlimit.h
+ FULL_BUILD_DEPENDS
+ libc.include.llvm-libc-types.struct_rlimit
+ libc.include.sys_resource
+)
diff --git a/libc/hdr/types/struct_rlimit.h b/libc/hdr/types/struct_rlimit.h
new file mode 100644
index 0000000..a09dd53
--- /dev/null
+++ b/libc/hdr/types/struct_rlimit.h
@@ -0,0 +1,22 @@
+//===-- Proxy for struct rlimit -------------------------------------------===//
+//
+// 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_HDR_TYPES_STRUCT_RLIMIT_H
+#define LLVM_LIBC_HDR_TYPES_STRUCT_RLIMIT_H
+
+#ifdef LIBC_FULL_BUILD
+
+#include "include/llvm-libc-types/struct_rlimit.h"
+
+#else // Overlay mode
+
+#include <sys/resource.h>
+
+#endif // LLVM_LIBC_FULL_BUILD
+
+#endif // LLVM_LIBC_HDR_TYPES_STRUCT_RLIMIT_H
diff --git a/libc/shared/math.h b/libc/shared/math.h
index 924d0cb..1262fa6 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -48,6 +48,7 @@
#include "math/exp10m1f.h"
#include "math/exp10m1f16.h"
#include "math/exp2.h"
+#include "math/exp2f.h"
#include "math/expf.h"
#include "math/expf16.h"
#include "math/frexpf.h"
diff --git a/libc/shared/math/exp2f.h b/libc/shared/math/exp2f.h
new file mode 100644
index 0000000..8c37cbb
--- /dev/null
+++ b/libc/shared/math/exp2f.h
@@ -0,0 +1,23 @@
+//===-- Shared exp2f 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_SHARED_MATH_EXP2F_H
+#define LLVM_LIBC_SHARED_MATH_EXP2F_H
+
+#include "shared/libc_common.h"
+#include "src/__support/math/exp2f.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using math::exp2f;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_MATH_EXP2F_H
diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt
index 4130fdf..203ebb4 100644
--- a/libc/src/__support/math/CMakeLists.txt
+++ b/libc/src/__support/math/CMakeLists.txt
@@ -736,6 +736,24 @@ add_header_library(
)
add_header_library(
+ exp2f
+ HDRS
+ exp2f.h
+ DEPENDS
+ .exp10f_utils
+ libc.src.__support.FPUtil.except_value_utils
+ libc.src.__support.FPUtil.fenv_impl
+ libc.src.__support.FPUtil.fp_bits
+ libc.src.__support.FPUtil.multiply_add
+ libc.src.__support.FPUtil.nearest_integer
+ libc.src.__support.FPUtil.polyeval
+ libc.src.__support.FPUtil.rounding_mode
+ libc.src.__support.macros.optimization
+ libc.src.__support.common
+ libc.src.errno.errno
+)
+
+add_header_library(
exp10
HDRS
exp10.h
diff --git a/libc/src/math/generic/exp2f_impl.h b/libc/src/__support/math/exp2f.h
index b85bb15..ef2aad0 100644
--- a/libc/src/math/generic/exp2f_impl.h
+++ b/libc/src/__support/math/exp2f.h
@@ -1,4 +1,4 @@
-//===-- Single-precision 2^x function -------------------------------------===//
+//===-- Implementation header for exp2f -------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -6,9 +6,10 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_LIBC_SRC_MATH_GENERIC_EXP2F_IMPL_H
-#define LLVM_LIBC_SRC_MATH_GENERIC_EXP2F_IMPL_H
+#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_EXP2F_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_EXP2F_H
+#include "exp10f_utils.h"
#include "src/__support/FPUtil/FEnvImpl.h"
#include "src/__support/FPUtil/FPBits.h"
#include "src/__support/FPUtil/PolyEval.h"
@@ -20,12 +21,12 @@
#include "src/__support/macros/config.h"
#include "src/__support/macros/optimization.h" // LIBC_UNLIKELY
#include "src/__support/macros/properties/cpu_features.h"
-#include "src/__support/math/exp10f_utils.h"
namespace LIBC_NAMESPACE_DECL {
-namespace generic {
-LIBC_INLINE float exp2f(float x) {
+namespace math {
+
+LIBC_INLINE static constexpr float exp2f(float x) {
using FPBits = typename fputil::FPBits<float>;
FPBits xbits(x);
@@ -120,8 +121,8 @@ LIBC_INLINE float exp2f(float x) {
// of 2^mid.
// kf = (hi + mid) * 2^5 = round(x * 2^5)
- float kf;
- int k;
+ float kf = 0;
+ int k = 0;
#ifdef LIBC_TARGET_CPU_HAS_NEAREST_INT
kf = fputil::nearest_integer(x * 32.0f);
k = static_cast<int>(kf);
@@ -161,7 +162,8 @@ LIBC_INLINE float exp2f(float x) {
return static_cast<float>(fputil::multiply_add(p, dx_sq * mh, c1 * mh));
}
-} // namespace generic
+} // namespace math
+
} // namespace LIBC_NAMESPACE_DECL
-#endif // LLVM_LIBC_SRC_MATH_GENERIC_EXP2F_IMPL_H
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_EXP2F_H
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 28ea475..5738fe8 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -1451,24 +1451,6 @@ add_entrypoint_object(
libc.src.__support.math.exp2
)
-add_header_library(
- exp2f_impl
- HDRS
- exp2f_impl.h
- DEPENDS
- libc.src.__support.FPUtil.except_value_utils
- libc.src.__support.FPUtil.fenv_impl
- libc.src.__support.FPUtil.fp_bits
- libc.src.__support.FPUtil.multiply_add
- libc.src.__support.FPUtil.nearest_integer
- libc.src.__support.FPUtil.polyeval
- libc.src.__support.FPUtil.rounding_mode
- libc.src.__support.macros.optimization
- libc.src.__support.math.exp10f_utils
- libc.src.__support.common
- libc.src.errno.errno
-)
-
add_entrypoint_object(
exp2f
SRCS
@@ -1476,7 +1458,7 @@ add_entrypoint_object(
HDRS
../exp2f.h
DEPENDS
- .exp2f_impl
+ libc.src.__support.math.exp2f
)
add_entrypoint_object(
@@ -1659,8 +1641,8 @@ add_entrypoint_object(
HDRS
../powf.h
DEPENDS
- .exp2f_impl
libc.src.__support.math.exp10f
+ libc.src.__support.math.exp2f
libc.src.__support.CPP.bit
libc.src.__support.FPUtil.fenv_impl
libc.src.__support.FPUtil.fp_bits
diff --git a/libc/src/math/generic/exp2f.cpp b/libc/src/math/generic/exp2f.cpp
index 60d6510..3117f73 100644
--- a/libc/src/math/generic/exp2f.cpp
+++ b/libc/src/math/generic/exp2f.cpp
@@ -9,10 +9,10 @@
#include "src/math/exp2f.h"
#include "src/__support/common.h" // for LLVM_LIBC_FUNCTION
#include "src/__support/macros/config.h"
-#include "src/math/generic/exp2f_impl.h"
+#include "src/__support/math/exp2f.h"
namespace LIBC_NAMESPACE_DECL {
-LLVM_LIBC_FUNCTION(float, exp2f, (float x)) { return generic::exp2f(x); }
+LLVM_LIBC_FUNCTION(float, exp2f, (float x)) { return math::exp2f(x); }
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/generic/powf.cpp b/libc/src/math/generic/powf.cpp
index 12246e9..dd2b6aa 100644
--- a/libc/src/math/generic/powf.cpp
+++ b/libc/src/math/generic/powf.cpp
@@ -20,10 +20,9 @@
#include "src/__support/macros/optimization.h" // LIBC_UNLIKELY
#include "src/__support/math/common_constants.h" // Lookup tables EXP_M1 and EXP_M2.
#include "src/__support/math/exp10f.h" // Speedup for powf(10, y) = exp10f(y)
+#include "src/__support/math/exp2f.h" // Speedup for powf(2, y) = exp2f(y)
#include "src/__support/math/exp_constants.h"
-#include "exp2f_impl.h" // Speedup for powf(2, y) = exp2f(y)
-
namespace LIBC_NAMESPACE_DECL {
using fputil::DoubleDouble;
@@ -779,7 +778,7 @@ LLVM_LIBC_FUNCTION(float, powf, (float x, float y)) {
#ifndef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
case 0x4000'0000: // x = 2.0f
// pow(2, y) = exp2(y)
- return generic::exp2f(y);
+ return math::exp2f(y);
case 0x4120'0000: // x = 10.0f
// pow(10, y) = exp10(y)
return math::exp10f(y);
diff --git a/libc/src/sys/resource/linux/CMakeLists.txt b/libc/src/sys/resource/linux/CMakeLists.txt
index 19f3901..9f0fdad 100644
--- a/libc/src/sys/resource/linux/CMakeLists.txt
+++ b/libc/src/sys/resource/linux/CMakeLists.txt
@@ -5,6 +5,7 @@ add_entrypoint_object(
HDRS
../getrlimit.h
DEPENDS
+ libc.hdr.types.struct_rlimit
libc.include.sys_resource
libc.include.sys_syscall
libc.src.__support.OSUtil.osutil
@@ -18,6 +19,7 @@ add_entrypoint_object(
HDRS
../setrlimit.h
DEPENDS
+ libc.hdr.types.struct_rlimit
libc.include.sys_resource
libc.include.sys_syscall
libc.src.__support.OSUtil.osutil
diff --git a/libc/src/sys/resource/linux/getrlimit.cpp b/libc/src/sys/resource/linux/getrlimit.cpp
index d272134..a3234eb 100644
--- a/libc/src/sys/resource/linux/getrlimit.cpp
+++ b/libc/src/sys/resource/linux/getrlimit.cpp
@@ -8,13 +8,12 @@
#include "src/sys/resource/getrlimit.h"
+#include "hdr/types/struct_rlimit.h"
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
#include "src/__support/common.h"
-
#include "src/__support/libc_errno.h"
#include "src/__support/macros/config.h"
-#include <sys/resource.h> // For struct rlimit
-#include <sys/syscall.h> // For syscall numbers.
+#include <sys/syscall.h> // For syscall numbers.
namespace LIBC_NAMESPACE_DECL {
diff --git a/libc/src/sys/resource/linux/setrlimit.cpp b/libc/src/sys/resource/linux/setrlimit.cpp
index 300bad7..e2c2b37 100644
--- a/libc/src/sys/resource/linux/setrlimit.cpp
+++ b/libc/src/sys/resource/linux/setrlimit.cpp
@@ -8,13 +8,12 @@
#include "src/sys/resource/setrlimit.h"
+#include "hdr/types/struct_rlimit.h"
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
#include "src/__support/common.h"
-
#include "src/__support/libc_errno.h"
#include "src/__support/macros/config.h"
-#include <sys/resource.h> // For struct rlimit
-#include <sys/syscall.h> // For syscall numbers.
+#include <sys/syscall.h> // For syscall numbers.
namespace LIBC_NAMESPACE_DECL {
diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index 040f635..dbc3889c 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -41,6 +41,7 @@ add_fp_unittest(
libc.src.__support.math.erff
libc.src.__support.math.exp
libc.src.__support.math.exp2
+ libc.src.__support.math.exp2f
libc.src.__support.math.exp10
libc.src.__support.math.exp10f
libc.src.__support.math.exp10f16
diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp
index ef2e7b8..d118d96 100644
--- a/libc/test/shared/shared_math_test.cpp
+++ b/libc/test/shared/shared_math_test.cpp
@@ -62,6 +62,7 @@ TEST(LlvmLibcSharedMathTest, AllFloat) {
EXPECT_FP_EQ(0x0p+0f, LIBC_NAMESPACE::shared::erff(0.0f));
EXPECT_FP_EQ(0x1p+0f, LIBC_NAMESPACE::shared::exp10f(0.0f));
EXPECT_FP_EQ(0x1p+0f, LIBC_NAMESPACE::shared::expf(0.0f));
+ EXPECT_FP_EQ(0x1p+0f, LIBC_NAMESPACE::shared::exp2f(0.0f));
EXPECT_FP_EQ_ALL_ROUNDING(0.75f,
LIBC_NAMESPACE::shared::frexpf(24.0f, &exponent));
diff --git a/libc/test/src/sys/mman/linux/CMakeLists.txt b/libc/test/src/sys/mman/linux/CMakeLists.txt
index 93fdc62..a362c1c 100644
--- a/libc/test/src/sys/mman/linux/CMakeLists.txt
+++ b/libc/test/src/sys/mman/linux/CMakeLists.txt
@@ -99,7 +99,6 @@ add_libc_unittest(
libc.src.sys.mman.mincore
libc.src.sys.mman.mlock
libc.src.sys.mman.munlock
- libc.src.unistd.sysconf
libc.test.UnitTest.ErrnoCheckingTest
libc.test.UnitTest.ErrnoSetterMatcher
)
@@ -125,7 +124,6 @@ add_libc_unittest(
libc.src.sys.mman.munlockall
libc.src.sys.resource.getrlimit
libc.src.__support.OSUtil.osutil
- libc.src.unistd.sysconf
libc.test.UnitTest.ErrnoCheckingTest
libc.test.UnitTest.ErrnoSetterMatcher
)
@@ -146,7 +144,6 @@ add_libc_unittest(
libc.src.sys.mman.mincore
libc.src.sys.mman.mlock
libc.src.sys.mman.munlock
- libc.src.unistd.sysconf
libc.test.UnitTest.ErrnoCheckingTest
libc.test.UnitTest.ErrnoSetterMatcher
)
@@ -160,13 +157,14 @@ add_libc_unittest(
DEPENDS
libc.include.sys_mman
libc.include.sys_stat
- libc.src.unistd.sysconf
libc.test.UnitTest.ErrnoCheckingTest
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.src.fcntl.open
+ libc.src.unistd.close
)
add_libc_unittest(
diff --git a/libc/test/src/sys/mman/linux/mincore_test.cpp b/libc/test/src/sys/mman/linux/mincore_test.cpp
index 3a15291..fb86252 100644
--- a/libc/test/src/sys/mman/linux/mincore_test.cpp
+++ b/libc/test/src/sys/mman/linux/mincore_test.cpp
@@ -12,7 +12,6 @@
#include "src/sys/mman/mmap.h"
#include "src/sys/mman/munlock.h"
#include "src/sys/mman/munmap.h"
-#include "src/unistd/sysconf.h"
#include "test/UnitTest/ErrnoCheckingTest.h"
#include "test/UnitTest/ErrnoSetterMatcher.h"
#include "test/UnitTest/Test.h"
@@ -21,6 +20,9 @@ using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails;
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
using LlvmLibcMincoreTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;
+// TODO: Replace with sysconf call once the function is properly implemented.
+constexpr size_t PAGE_SIZE = 4096;
+
TEST_F(LlvmLibcMincoreTest, UnMappedMemory) {
unsigned char vec;
int res = LIBC_NAMESPACE::mincore(nullptr, 1, &vec);
@@ -28,7 +30,7 @@ TEST_F(LlvmLibcMincoreTest, UnMappedMemory) {
}
TEST_F(LlvmLibcMincoreTest, UnalignedAddr) {
- unsigned long page_size = LIBC_NAMESPACE::sysconf(_SC_PAGESIZE);
+ unsigned long page_size = PAGE_SIZE;
void *addr = LIBC_NAMESPACE::mmap(nullptr, page_size, PROT_READ,
MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
EXPECT_NE(addr, MAP_FAILED);
@@ -39,7 +41,7 @@ TEST_F(LlvmLibcMincoreTest, UnalignedAddr) {
}
TEST_F(LlvmLibcMincoreTest, InvalidVec) {
- unsigned long page_size = LIBC_NAMESPACE::sysconf(_SC_PAGESIZE);
+ unsigned long page_size = PAGE_SIZE;
void *addr = LIBC_NAMESPACE::mmap(nullptr, 4 * page_size, PROT_READ,
MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
EXPECT_NE(addr, MAP_FAILED);
@@ -49,7 +51,7 @@ TEST_F(LlvmLibcMincoreTest, InvalidVec) {
}
TEST_F(LlvmLibcMincoreTest, NoError) {
- unsigned long page_size = LIBC_NAMESPACE::sysconf(_SC_PAGESIZE);
+ unsigned long page_size = PAGE_SIZE;
void *addr = LIBC_NAMESPACE::mmap(nullptr, page_size, PROT_READ,
MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
EXPECT_NE(addr, MAP_FAILED);
@@ -61,7 +63,7 @@ TEST_F(LlvmLibcMincoreTest, NoError) {
}
TEST_F(LlvmLibcMincoreTest, NegativeLength) {
- unsigned long page_size = LIBC_NAMESPACE::sysconf(_SC_PAGESIZE);
+ unsigned long page_size = PAGE_SIZE;
void *addr = LIBC_NAMESPACE::mmap(nullptr, page_size, PROT_READ,
MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
EXPECT_NE(addr, MAP_FAILED);
@@ -73,7 +75,7 @@ TEST_F(LlvmLibcMincoreTest, NegativeLength) {
}
TEST_F(LlvmLibcMincoreTest, PageOut) {
- unsigned long page_size = LIBC_NAMESPACE::sysconf(_SC_PAGESIZE);
+ unsigned long page_size = PAGE_SIZE;
unsigned char vec;
void *addr = LIBC_NAMESPACE::mmap(nullptr, page_size, PROT_READ | PROT_WRITE,
MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
diff --git a/libc/test/src/sys/mman/linux/mlock_test.cpp b/libc/test/src/sys/mman/linux/mlock_test.cpp
index cd37422..f4a072e 100644
--- a/libc/test/src/sys/mman/linux/mlock_test.cpp
+++ b/libc/test/src/sys/mman/linux/mlock_test.cpp
@@ -22,14 +22,15 @@
#include "src/sys/mman/munlockall.h"
#include "src/sys/mman/munmap.h"
#include "src/sys/resource/getrlimit.h"
-#include "src/unistd/sysconf.h"
#include "test/UnitTest/ErrnoCheckingTest.h"
#include "test/UnitTest/ErrnoSetterMatcher.h"
#include "test/UnitTest/Test.h"
-#include <linux/capability.h>
#include <sys/syscall.h>
+// TODO: Replace with sysconf call once the function is properly implemented.
+constexpr size_t PAGE_SIZE = 4096;
+
using namespace LIBC_NAMESPACE::testing::ErrnoSetterMatcher;
using LlvmLibcMlockTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;
@@ -38,7 +39,7 @@ struct PageHolder {
void *addr;
PageHolder()
- : size(LIBC_NAMESPACE::sysconf(_SC_PAGESIZE)),
+ : size(PAGE_SIZE),
addr(LIBC_NAMESPACE::mmap(nullptr, size, PROT_READ | PROT_WRITE,
MAP_ANONYMOUS | MAP_PRIVATE, -1, 0)) {}
~PageHolder() {
@@ -51,28 +52,10 @@ struct PageHolder {
bool is_valid() { return addr != MAP_FAILED; }
};
-static bool get_capacity(unsigned int cap) {
- __user_cap_header_struct header;
- header.pid = 0;
- header.version = _LINUX_CAPABILITY_VERSION_3;
- __user_cap_data_struct data[_LINUX_CAPABILITY_U32S_3];
- // TODO: use capget wrapper once implemented.
- // https://github.com/llvm/llvm-project/issues/80037
- long res = LIBC_NAMESPACE::syscall_impl(
- SYS_capget, LIBC_NAMESPACE::cpp::bit_cast<long>(&header),
- LIBC_NAMESPACE::cpp::bit_cast<long>(&data));
- if (res < 0)
- return false;
- unsigned idx = CAP_TO_INDEX(cap);
- unsigned shift = CAP_TO_MASK(cap);
- return (data[idx].effective & shift) != 0;
-}
-
static bool is_permitted_size(size_t size) {
rlimit rlimits;
LIBC_NAMESPACE::getrlimit(RLIMIT_MEMLOCK, &rlimits);
- return size <= static_cast<size_t>(rlimits.rlim_cur) ||
- get_capacity(CAP_IPC_LOCK);
+ return size <= static_cast<size_t>(rlimits.rlim_cur);
}
TEST_F(LlvmLibcMlockTest, UnMappedMemory) {
diff --git a/libc/test/src/sys/mman/linux/msync_test.cpp b/libc/test/src/sys/mman/linux/msync_test.cpp
index b4eedb3..764a67d 100644
--- a/libc/test/src/sys/mman/linux/msync_test.cpp
+++ b/libc/test/src/sys/mman/linux/msync_test.cpp
@@ -11,11 +11,13 @@
#include "src/sys/mman/msync.h"
#include "src/sys/mman/munlock.h"
#include "src/sys/mman/munmap.h"
-#include "src/unistd/sysconf.h"
#include "test/UnitTest/ErrnoCheckingTest.h"
#include "test/UnitTest/ErrnoSetterMatcher.h"
#include "test/UnitTest/Test.h"
+// TODO: Replace with sysconf call once the function is properly implemented.
+constexpr size_t PAGE_SIZE = 4096;
+
using namespace LIBC_NAMESPACE::testing::ErrnoSetterMatcher;
using LlvmLibcMsyncTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;
@@ -24,7 +26,7 @@ struct PageHolder {
void *addr;
PageHolder()
- : size(LIBC_NAMESPACE::sysconf(_SC_PAGESIZE)),
+ : size(PAGE_SIZE),
addr(LIBC_NAMESPACE::mmap(nullptr, size, PROT_READ | PROT_WRITE,
MAP_ANONYMOUS | MAP_PRIVATE, -1, 0)) {}
~PageHolder() {
diff --git a/libc/test/src/sys/mman/linux/remap_file_pages_test.cpp b/libc/test/src/sys/mman/linux/remap_file_pages_test.cpp
index 851e4f7d..094bcb2 100644
--- a/libc/test/src/sys/mman/linux/remap_file_pages_test.cpp
+++ b/libc/test/src/sys/mman/linux/remap_file_pages_test.cpp
@@ -11,7 +11,6 @@
#include "src/sys/mman/munmap.h"
#include "src/sys/mman/remap_file_pages.h"
#include "src/unistd/close.h"
-#include "src/unistd/sysconf.h"
#include "test/UnitTest/ErrnoCheckingTest.h"
#include "test/UnitTest/ErrnoSetterMatcher.h"
#include "test/UnitTest/Test.h"
@@ -19,12 +18,15 @@
#include <sys/mman.h>
#include <sys/stat.h> // For S_IRWXU
+// TODO: Replace with sysconf call once the function is properly implemented.
+constexpr size_t PAGE_SIZE = 4096;
+
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails;
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
using LlvmLibcRemapFilePagesTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;
TEST_F(LlvmLibcRemapFilePagesTest, NoError) {
- size_t page_size = LIBC_NAMESPACE::sysconf(_SC_PAGE_SIZE);
+ size_t page_size = PAGE_SIZE;
ASSERT_GT(page_size, size_t(0));
// Create a file-backed mapping
@@ -50,7 +52,7 @@ TEST_F(LlvmLibcRemapFilePagesTest, NoError) {
}
TEST_F(LlvmLibcRemapFilePagesTest, ErrorInvalidFlags) {
- size_t page_size = LIBC_NAMESPACE::sysconf(_SC_PAGE_SIZE);
+ size_t page_size = PAGE_SIZE;
ASSERT_GT(page_size, size_t(0));
// Create a file-backed mapping
@@ -77,7 +79,7 @@ TEST_F(LlvmLibcRemapFilePagesTest, ErrorInvalidFlags) {
}
TEST_F(LlvmLibcRemapFilePagesTest, ErrorInvalidAddress) {
- size_t page_size = LIBC_NAMESPACE::sysconf(_SC_PAGESIZE);
+ size_t page_size = PAGE_SIZE;
ASSERT_GT(page_size, size_t(0));
// Use an address that we haven't mapped
diff --git a/libc/test/src/sys/resource/CMakeLists.txt b/libc/test/src/sys/resource/CMakeLists.txt
index 2870f2c..2097a2c 100644
--- a/libc/test/src/sys/resource/CMakeLists.txt
+++ b/libc/test/src/sys/resource/CMakeLists.txt
@@ -1,7 +1,5 @@
add_custom_target(libc_sys_resource_unittests)
-add_subdirectory(testdata)
-
add_libc_unittest(
getrlimit_setrlimit_test
SUITE
diff --git a/libc/test/src/sys/resource/getrlimit_setrlimit_test.cpp b/libc/test/src/sys/resource/getrlimit_setrlimit_test.cpp
index d6e1490..4e0a3c7 100644
--- a/libc/test/src/sys/resource/getrlimit_setrlimit_test.cpp
+++ b/libc/test/src/sys/resource/getrlimit_setrlimit_test.cpp
@@ -27,8 +27,11 @@ TEST_F(LlvmLibcResourceLimitsTest, SetNoFileLimit) {
// successfully. Next, close the files and set the file descriptor limit
// to 4. This will allow us to open one of those file but not the other.
- constexpr const char *TEST_FILE1 = "testdata/resource_limits1.test";
- constexpr const char *TEST_FILE2 = "testdata/resource_limits2.test";
+ constexpr const char *TEST_FILE1_NAME = "resource_limits1.test";
+ constexpr const char *TEST_FILE2_NAME = "resource_limits2.test";
+
+ auto TEST_FILE1 = libc_make_test_file_path(TEST_FILE1_NAME);
+ auto TEST_FILE2 = libc_make_test_file_path(TEST_FILE2_NAME);
int fd1 = LIBC_NAMESPACE::open(TEST_FILE1, O_CREAT | O_WRONLY, S_IRWXU);
ASSERT_GT(fd1, 0);
diff --git a/libc/test/src/sys/resource/testdata/CMakeLists.txt b/libc/test/src/sys/resource/testdata/CMakeLists.txt
deleted file mode 100644
index e69de29..0000000
--- a/libc/test/src/sys/resource/testdata/CMakeLists.txt
+++ /dev/null