[libc-commits] [libc] [libc] fix sysconf test for rv32 (PR #162685)
via libc-commits
libc-commits at lists.llvm.org
Thu Oct 9 10:47:12 PDT 2025
================
@@ -34,6 +34,20 @@ LIBC_INLINE R syscall_impl(long __number, Ts... ts) {
return cpp::bit_or_static_cast<R>(syscall_impl(__number, (long)ts...));
}
+// Linux-specific function for checking
+namespace linux_utils {
+LIBC_INLINE_VAR constexpr unsigned long MAX_ERRNO = 4095;
+// Ideally, this should be defined using PAGE_OFFSET
+// However, that is a configurable parameter. We mimic kernel's behavior
+// by checking against MAX_ERRNO.
+template <typename PointerLike>
+LIBC_INLINE constexpr bool is_valid_mmap(PointerLike ptr) {
+ long addr = cpp::bit_cast<long>(ptr);
+ return __builtin_expect(addr > 0 || addr < -cpp::bit_cast<long>(MAX_ERRNO),
----------------
lntue wrote:
Use `LIBC_LIKELY` from https://github.com/llvm/llvm-project/blob/main/libc/src/__support/macros/optimization.h#L27
and for casting signed / unsigned integers, `static_cast` should be good enough.
https://github.com/llvm/llvm-project/pull/162685
More information about the libc-commits
mailing list